TestNG的组测试和组中组测试

发表于:2015-2-09 11:21

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:桐桐-Dragon    来源:51Testing软件测试网采编

  在编写测试的过程中,我们经常遇到只想执行个别或者某一部分/某一类型的测试用例,这时我们可以使用TestNG的分组测试方法
  分组测试在配置时,TestNG执行的原则是:只保留最小集合进行执行
  看代码:
/**
*
* <p>
* Title: TestngGroups
* </p>
*
* <p>
* 对应配置文件testng-groups.xml
* Description:使用groups进行分组测试,include和exclude的原则是保留最小集合,
* </p>
*
* <p>
* Company:
* </p>
*
* @author : Dragon
*
* @date : 2014年10月13日
*/
public class TestngGroups {
@Test(groups = { "functest", "checkintest" })
public void testMethod1() {
System.err.println("groups = { functest, checkintest }");
}
@Test(groups = { "functest", "checkintest" })
public void testMethod2() {
System.err.println("groups = { functest, checkintest }");
}
@Test(groups = { "functest" })
public void testMethod3() {
System.err.println("groups = { functest }");
}
@Test(groups = { "checkintest" })
public void testMethod4() {
System.err.println("groups = { checkintest }");
}
}
  配置文件:testng-groups.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="framework_testng">
<test verbose="2" name="TestGroups">
<groups>
<run>
<include name="functest" />
<exclude name="checkintest" />
</run>
</groups>
<classes>
<class name="com.dragon.testng.annotation.TestngGroups" />
</classes>
</test>
</suite>
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号