我想多次运行一个测试用例。这可以在testng.xml
中配置吗?如果我在测试方法中添加一个循环,那么每次运行的结果都不会在testng
报告中受到影响。
发布于 2014-10-01 13:44:19
你不能在xml中做到这一点,但是在@Test注解中--你可以添加一个带有你想要运行的次数的invocationCount属性。它会像报告中运行的那些测试那样出来。
例如:
@Test(invocationCount = 10)
public void testCount() {..}
你遗漏了末尾的右花括号,所以稍微修正一下。
发布于 2017-01-31 21:34:30
TestNg有一种方法。您可以使用此方法并多次运行测试用例:
@Test(invocationCount = 100)
public void testCount() {
}
发布于 2017-06-28 01:20:46
到目前为止,没有一个答案真正让用户能够从testng文件中增加调用计数,这就是我们所要求的。该解决方案借鉴了gaurav25的DataProvider解决方案。
class TestClass() {
int invocations;
@Parameters({ "invocationCount" })
@BeginClass
void BeginClass( @Optional("1") String invocationCount) {
this.invocations = Ingeter.parse(invocationCount)
}
// It will return a 2D array of size 3x1
@DataProvider(name="URLprovider")
private Object[][] getURLs() {
ArrayList<Object []> obj = new ArrayList<>(3 * this.invocations);
for(int iCount = 0; iCount < this.invocations; ++iCount) {
list.add( new Object[] {"https://www.google.co.in/"} );
list.add( new Object[] {"http://www.gmail.com/"} );
list.add( new Object[] {"http://stackoverflow.com/"} );
}
return list.toArray();
}
/* Since Data provider for this test method returns 2D array of size
(3*invocations)x1, this test method will run 3*invocations
times **automatically** with 1 parameter every time. */
@Test(dataProvider="URLprovider")
private void notePrice(String url) {
driver.get(url);
System.out.println(driver.getTitle());
}
}
现在,您可以使用以下testng.xml文件更改通过测试函数运行的测试集的数量:
<suite name="ESFService" verbose="1" parallel="methods" thread-count="1" data-provider-thread-count="10" >
<test name="Basic">
<classes>
<class name="TestClass">
<parameter name="invocationCount" value="5"/>
</class>
</classes>
</test>
</suite>
https://stackoverflow.com/questions/26128289
复制相似问题