TestNG分组测试
测试用例分组
TestNG中可以把测试用例分组,这样可以按组来执行测试用例,比如:
package me.yezhou;
import org.testng.Assert;
import org.testng.annotations.Test;
public class GroupTest {
@Test(groups = { "group1" })
public void testCase1() {
System.out.println("groups = { group1 }");
}
@Test(groups = { "group2" })
public void testCase2() {
System.out.println("groups = { group2 }");
}
@Test(groups = { "group3" })
public void testCase3() {
System.out.println("groups = { group3 }");
}
@Test(groups = { "group1", "group2" })
public void testCase12() {
System.out.println("groups = { group1, group2 }");
}
@Test(groups = { "group1", "group3" })
public void testCase13() {
System.out.println("groups = { group1, group3 }");
}
@Test(groups = { "group2", "group3" })
public void testCase23() {
System.out.println("groups = { group2, group3 }");
}
@Test(groups = { "group1", "group2", "group3" })
public void testCase123() {
System.out.println("groups = { group1, group2, group3 }");
}
}
分组测试
只测试group1组:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
<test name="test">
<groups>
<run>
<include name="group1" />
</run>
</groups>
<classes>
<class name="me.yezhou.AppBlogTest"/>
</classes>
</test>
</suite>
测试结果:
groups = { group1 }
groups = { group1, group2 }
groups = { group1, group2, group3 }
groups = { group1, group3 }
===============================================
Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
并组测试
同时测试group1和group2组:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
<test name="test">
<groups>
<define name="group_i12">
<include name="group1"/>
<include name="group2"/>
</define>
<run>
<include name="group_i12" />
</run>
<!--run>
<include name="group1"/>
<include name="group2"/>
</run-->
</groups>
<classes>
<class name="me.yezhou.AppBlogTest"/>
</classes>
</test>
</suite>
测试结果:
groups = { group1 }
groups = { group1, group2 }
groups = { group1, group2, group3 }
groups = { group1, group3 }
groups = { group2 }
groups = { group2, group3 }
===============================================
Suite
Total tests run: 6, Failures: 0, Skips: 0
===============================================
斥组测试
同时测试group1和group2组,但不测试group3组:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
<test name="test">
<groups>
<define name="group_i12">
<include name="group1"/>
<include name="group2"/>
</define>
<run>
<include name="group_i12" />
<exclude name="group3" />
</run>
</groups>
<classes>
<class name="me.yezhou.AppBlogTest"/>
</classes>
</test>
</suite>
测试结果:
groups = { group1 }
groups = { group1, group2 }
groups = { group2 }
===============================================
Suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/01/testng-group-test/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
TestNG分组测试
测试用例分组
TestNG中可以把测试用例分组,这样可以按组来执行测试用例,比如:
package me.yezhou;
import org.testng.Assert;
import org.testng.annotat……
文章目录
关闭
共有 0 条评论