51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2050|回复: 1

[原创] TestNg配置依赖的高级用法

[复制链接]

该用户从未签到

发表于 2017-10-12 16:24:56 | 显示全部楼层 |阅读模式
配置型的依赖测试,让依赖测试不局限于测试代码中,在XML文件中进行灵活的依赖配置。
java code:
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>  
运行结果:
[html] view plain copy
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  
===============================================  

评分

参与人数 1测试积点 +10 收起 理由
lsekfe + 10 赞一个!

查看全部评分

回复

使用道具 举报

该用户从未签到

发表于 2017-10-13 10:39:36 | 显示全部楼层
可不可以通过注解来实现依赖测试呢?通过配置文件来实现有点麻烦吧。

评分

参与人数 1测试积点 +10 收起 理由
lsekfe + 10 积极回复获得测试积点10 赶快去商城换取奖.

查看全部评分

回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-3-29 16:14 , Processed in 0.068287 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表