TestNg依赖详解(三)------灵活的文件配置依赖

配置型的依赖测试,让依赖测试不局限于测试代码中,在XML文件中进行灵活的依赖配置

 代码实例:

复制代码
/**
 * 
 * <p>
 * Title: TestngDependencyOnXML
 * </p>
 * 
 * <p>
 * Description: 不使用注解的情况下,通过对testng-xml来进行依赖配置
 * 
 * 执行原则:
 * 被依赖的group最先执行,如果某个group没有被配置成被依赖,那么它将在被依赖的group之后执行,最后执行的是需要依赖其它group的方法
 * ,如果都没有配置依赖,则按顺序执行.一个方法有多个依赖时用空格隔开
 * </p>
 * 
 * <p>
 * Company:
 * </p>
 * 
 * @author : Dragon
 * 
 * @date : 2014年10月21日
 */
public class TestngDependencyOnXML {
    @Test(groups = { "ss" })
    public void a() {
        System.out.println("this is method a, Groups ss");
    }
 
    @Test(groups = { "ss" })
    public void b() {
        System.out.println("this is method b,     Groups ss");
    }
 
    @Test(groups = { "xx" })
    public void c() {
        System.out.println("this is method c ,Groups xx");
    }
 
    @Test(groups = { "xx" })
    public void d() {
        System.out.println("this is method d, Groups xx");
    }
 
    @Test(groups = { "yy" })
    public void e() {
        System.out.println("this is method e , Groups yy");
    }
}
复制代码

配置文件:

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="framework_testng">
    <test name="testng-dependOnXML" >
        <groups >
            <dependencies >
                <group name="ss" depends-on="xx yy" />
            </dependencies>
        </groups>
        <classes>
            <class name="com.dragon.testng.annotation.TestngDependencyOnXML" />
        </classes>
    </test>
</suite>
复制代码

运行结果:

复制代码
this is method c ,Groups xx
this is method d, Groups xx
this is method e , Groups yy
this is method a, Groups ss
this is method b,     Groups ss
 
===============================================
framework_testng
Total tests run: 5, Failures: 0, Skips: 0
===============================================
复制代码

总结: 被依赖的group最先执行,如果某个group没有被配置成被依赖,那么它将在被依赖的group之后执行,最后执行的是需要依赖其它group的方法,如果都没有配置依赖,则按顺序执行.一个方法有多个依赖时用空格隔开

posted @   久曲健  阅读(1009)  评论(0编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示