我希望在testng中以这样的方式循环测试,即在测试结果中记录每个循环的执行时间。我使用Do-While循环了测试,但testng记录了循环完成测试用例所用的整个时间。这里是我的代码的一个简单视图。
class BackEndController{
@Test
public void fwdProcess(){
do{
//pick a pending request from a list
//perform some actions on it
//forward the request
}while(items are in the list)
}
}尽管循环完成一个周期几乎需要一秒钟。但Testng记录了fwdProcess所用的全部时间(结果中显示3-4分钟)。那么,有没有什么注释或方法可以通过循环测试来实现类似的条件(直到列表中有项为止),这样我就可以获得测试的每次执行时间?
发布于 2015-11-10 21:13:01
您需要的是data provider
class BackEndController {
@DataProvider
public Object[][] requests() {
// construct the array (or iterable) from a list
}
@Test(dataProvider = "requests")
public void fwdProcess(request) {
// perform some actions on the request
// forward the request
}
}发布于 2015-11-10 22:35:50
如果循环要使用相同的数据,我认为您需要使用invocationcount
@Test(invocationCount = 10)
public void testServer() {
}这将调用相同的测试10次,在报告中,您将获得不同的时间。您还可以使用这些参数设置其他参数,如超时、successPercentage等。有关这些参数及其工作原理的更多信息,请阅读this
https://stackoverflow.com/questions/33624126
复制相似问题