【发布时间】:2018-04-06 18:43:51
【问题描述】:
我正在尝试为我的 csv 文件中的每一行测试数据从一个类运行多个测试(@Test)。我正在使用 testNG facory 和 dataprovider。例如,假设我的班级中有 test1、test2 和 Test3 测试方法,我的 CSV 文件中有 3 组(行)测试数据。现在当我运行它时,运行 secquence 如下所示: 测试1 测试1 测试1 测试2 测试2 测试2 测试3 测试3 测试3
但这就是我要找的,我希望我的测试按以下顺序运行: 测试1 测试2 测试3 测试1 测试2 测试3 测试1 测试2 测试3
以下是我的示例代码(将我的 csv 数据替换为数据提供者自己的测试数据)
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
public class TestWithDataProviderAndFactory {
private String firstName;
private String lastName;
@Factory(dataProvider = "dp")
public TestWithDataProviderAndFactory(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@DataProvider(name = "dp")
public static Object[][] getData() {
return new Object[][]{
{"Rajeev", "Kumar"},
{"Sanjeev", "Kumar"},
{"Jony", "Dip"}
};
}
@Test
public void test1() {
System.out.println("This is test 1");
System.out.println("First Name: "+ firstName);
}
@Test
public void test2() {
System.out.println("This is test 2");
System.out.println("Last Name: "+ lastName);
}
}
输出:(这是我得到的)
This is test 1
First Name: Rajeev
This is test 1
First Name: Jony
This is test 1
First Name: Sanjeev
This is test 2
Last Name: Kumar
This is test 2
Last Name: Dip
This is test 2
Last Name: Kumar
但是,我想执行如下测试:
This is test 1
First Name: Rajeev
This is test 2
Last Name: Kumar
This is test 1
First Name: Sanjeev
This is test 2
Last Name: Kumar
This is test 1
First Name: Jony
This is test 2
Last Name: Dip
提前感谢您的帮助!
【问题讨论】:
-
在 testng.xml 中的套件或测试标签上使用 group-by-instances="true" ....testng.org/doc/…
-
感谢@Grasshopper - group-by-instances="true" 为我工作。
-
@Grasshopper - 也许您可以将其添加为答案,以便可以接受并关闭问题?
-
@KrishnanMahadevan 接受了您的建议并添加为答案。谢谢
-
@Sandip 您能否继续接受
@Grasshopper的回答,因为他的建议可以帮助您解决问题?