目录
如果test1()失败了怎么办?test2()测试会发生什么,因为它依赖于test1?
如果我们在test1()方法上不使用@Test注释,但在test 2()测试用例上仍然使用@Test(dependsOnMethod =“test1”),会怎么样?
如果我们在dependsOnMethods属性中传递一个方法列表会怎么样?他们的处决有命令吗?
如何在属于不同类的测试用例上使用dependsOnMethods?
本文将详细讨论@Test注释的dependsOnMethods属性。
这个属性有什么作用?dependsOnMethods属性的用途是什么?dependsOnMethods用于依赖于另一个测试用例执行的测试用例。因此,后一个测试用例将首先执行,因为它的执行对于运行依赖于它的用例是必要的。
语法
dependsOnMethod属性将接受一个字符串数组,如{“test1”,“test 2”},如果一个测试只依赖于另一个测试,你也可以传递“test1”。所以,它会像下面这样-
@Test(dependsOnMethod = {"test1","test2"}) // if depends on one or more tests
@Test(dependsOnMethod = "test1") // if your test depends on only one other test
现在,让我们看一些关于如何在测试中使用dependsOnMethods的代码-
import org.testng.Assert;
import org.testng.annotations.Test;
public class CodekruTest {
@Test // this test will run first
public void