在testng中按顺序执行测试
Executing Tests in sequencial in testng
我正在执行 testng 测试套件。我在测试套件中进行了一项测试。该测试有一个 returns 2 条记录的数据提供者。所以同一个测试必须 运行 两次。我希望这些测试按顺序 运行 但我看到的是 运行 并行。我尝试将 singleThread = true 提供给数据提供者,但没有成功。我看到以下输出
- BeforeMethod-1
- BeforeMothod-2
- 测试 1
- 测试 2
- AfterMethod-1
- AfterMethod-2
但我想要的是
- BeforeMethod-1
- 测试 1
- AfterMethod-1
- BeforeMothod-2
- 测试 2
- AfterMethod-2
从 DataProvider
方法 (getData) 中删除 parallel = true
如果指定。
@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
===============================================
我正在执行 testng 测试套件。我在测试套件中进行了一项测试。该测试有一个 returns 2 条记录的数据提供者。所以同一个测试必须 运行 两次。我希望这些测试按顺序 运行 但我看到的是 运行 并行。我尝试将 singleThread = true 提供给数据提供者,但没有成功。我看到以下输出
- BeforeMethod-1
- BeforeMothod-2
- 测试 1
- 测试 2
- AfterMethod-1
- AfterMethod-2
但我想要的是
- BeforeMethod-1
- 测试 1
- AfterMethod-1
- BeforeMothod-2
- 测试 2
- AfterMethod-2
从 DataProvider
方法 (getData) 中删除 parallel = true
如果指定。
@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
===============================================