我正在执行一个testng测试套件。我在测试套件中有一个测试。该测试有一个dataprovider,返回2条记录。所以相同的测试必须运行两次。我希望这些测试按顺序运行,但我看到它是平行运行的。我尝试将singleThread = true提供给数据提供者,但没有用。我看到以下输出
但我想要的是
答案 0 :(得分:2)
从parallel = true
方法中删除DataProvider
(getData)如果已指定。
@DataProvider()
或者
将其设为 false 。
@DataProvider(parallel = false)
我使用TestNG 6.8.5
default settings from Eclipse:
尝试了以下示例
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;
public class TestExample {
@BeforeMethod
public void beforeMethod(){
System.out.println("before method ");
}
@Test(dataProvider="getData")
public void test1(String username, String password) {
System.out.println("test");
System.out.println("you have provided username as::"+username);
System.out.println("you have provided password as::"+password);
}
@AfterMethod
public void afterMethod() {
System.out.println("after method");
}
@DataProvider
public Object[][] getData()
{
//Rows - Number of times your test has to be repeated.
//Columns - Number of parameters in test data.
Object[][] data = new Object[2][2];
// 1st row
data[0][0] ="sampleuser1";
data[0][1] = "abcdef";
// 2nd row
data[1][0] ="testuser2";
data[1][1] = "zxcvb";
return data;
}
}
给出了以下输出:
before method
test
you have provided username as::sampleuser1
you have provided password as::abcdef
after method
before method
test
you have provided username as::testuser2
you have provided password as::zxcvb
after method
PASSED: test1("sampleuser1", "abcdef")
PASSED: test1("testuser2", "zxcvb")
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================