TestNG依赖测试
有时候,我们需要按顺序来调用测试用例,那么测试用例之间就存在依赖关系。
TestNG支持测试用例之间的依赖:
- 测试案例依赖:@Test(dependsOnMethods = {"dependedMethods"})
- 测试组依赖:@Test(dependsOnGroups = {"dependedGroups"})
测试案例依赖
package me.yezhou;
import org.testng.annotations.Test;
public class DependsOnTest {
@Test
public void onLoad() {
System.out.println("onLoad");
}
@Test(dependsOnMethods = { "onLoad" })
public void onReady() {
System.out.println("onReady");
}
@Test(dependsOnMethods = { "onReady" })
public void onShow() {
System.out.println("onShow");
}
}
测试结果:
onLoad
onReady
onShow
===============================================
Suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
测试组依赖
package me.yezhou;
import org.testng.annotations.Test;
public class DependsOnTest {
@Test(groups = { "group1" })
public void testCase1() {
System.out.println("testCase1");
}
@Test(groups = { "group2" })
public void testCase2() {
System.out.println("testCase2");
}
@Test(dependsOnGroups = { "group1" })
public void testCase3() {
System.out.println("testCase3");
}
@Test(dependsOnGroups = { "group.*" })
public void testCase4() {
System.out.println("testCase4");
}
}
测试结果:
testCase1
testCase2
testCase3
testCase4
===============================================
Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
注:group.* 是通配符
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/01/testng-dependency-test/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
TestNG依赖测试
有时候,我们需要按顺序来调用测试用例,那么测试用例之间就存在依赖关系。
TestNG支持测试用例之间的依赖:
测试案例依赖:@Test(dependsOnMethods = {&quo……
文章目录
关闭
共有 0 条评论