[英]How to execute tests sequentially using TestNG and DataProvider
[英]How to run/execute methods sequentially by Selenium RC and TestNG using Java
我有一个包含3个方法的Java类:
public class Test{
public void orange(){
}
public void apple(){
}
public void mango(){
}
}
我要按顺序/有序执行上述3种方法,就像我由Selenium RC和TestNG编写的那样。 我怎样才能做到这一点?
简单的方法是将@Test
更改为@Test(singleThreaded=true)
。 如果这样做,您的类中的所有测试将在单个线程中按顺序运行。
要么
如果要明确说明测试的运行顺序,可以使用批注@dependsOnMethods
public void orange(){}
@Test(dependsOnMethods = { "orange" })
public void apple(){}
@Test(dependsOnMethods = { "apple" })
public void mango(){}
如果您希望类中的某些(但不是全部)方法按顺序运行,这也很好。
http://testng.org/doc/documentation-main.html#dependent-methods
只需将@Test
更改为@Test(singleThreaded=true)
,就可以了。
http://testng.org/javadoc/org/testng/annotations/Test.html#singleThreaded%28%29
除了在类上使用sequential=true
,还可以在方法本身上设置优先级。
@Test(priority=1)
public void orange(){}
@Test(priority=2)
public void apple(){}
@Test(priority=3)
public void mango(){}
在测试类中,您可以在类级别尝试使用此注释。
@Test(sequential = true)
我建议使用dependsOnGroups。 因此,您将测试方法归为一组,并提供对该组的依赖性。 所以明天如果您重构方法名称,则依赖结构将不会被破坏。 更多关于dependsOnGroups的信息,请点击这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.