指定方法名称序列TestNG

时间:2011-10-27 10:54:00

标签: testng

我正在以编程方式使用TestNG运行selenium测试。我想按顺序运行测试方法。

如果我们使用preserve-order="true",它就像属性TestNG.XML一样。 类似的功能如何在不使用TestNG.XMl的情况下实现它。

setTestNames无效

TestNG tng= new TestNG();

tng.setTestClasses(new Class[] { A.class});

//tng.setTestNames

tng.run();

A.class指定了班级@Test。因此该类中的所有方法都是测试用例。 所以Testng执行A中的所有方法。我想按顺序运行它们出现在类中。

2 个答案:

答案 0 :(得分:4)

在testNg中你可以使用

@Test(priority = 1)

他们将此更改为所有方法以保持您想要的顺序

@Test(priority = 2)
@Test(priority = 3)

另一种解决方案是使用

@Test(dependsOnMethods = { "serverStartedOk" }) as stated in TestNG docs.

我搜索了TestNG文档,但是我看不到使用annotatios做你想要的简单方法......

答案 1 :(得分:1)

如果没有testng.xml,最简单的方法就是实现自己的IMethodInterceptor

相关问题