I have several test cases that depend on each other. The order of execution can be defined in TestNG using groups and dependsOnGroups in the @Test
annotation:
public class MyTest {
@Test(groups = { "group1" })
public void testCase1() {
}
@Test(groups = {"group2"}, dependsOnGroups = { "group1" })
public void testCase2() {
}
@Test(groups = {"group2"}, dependsOnGroups = { "group1" })
public void testCase() {
}
@Test(groups = { "group3" }, dependsOnGroups = { "group2" })
public void testCase4() {
}
}
But I want it dynamically with only one @Test
method and a @DataProvider
that gives me the group and the dependencies.
public class MyTest {
@Test(dataProvider = "test-cases", groups = {testCase[1]}, dependsOnGroups = {testCase[2]})
public void executeTest(TestCase testCase) throws Exception {
}
@DataProvider(name = "test-cases", parallel = true)
public Object[][] getTestCases() {
Object[][] testdata = new Object[...][...];
// Fields: test name, group, depends on, test data
testdata[0] = {"TC#1", "group1", "", "foo data"};
testdata[1] = {"TC#2", "group2", "group1", "bar data"};
testdata[2] = {"TC#3", "group2", "group1", "bzz data"};
testdata[3] = {"TC#4", "group3", "group2", "frr data"};
return testdata;
}
}
Unfortunately this approach does not work, as testCase[1] cannot be accessed from the @Test(..., groups = {testCase[1]}, ...)
annotation.
Is there another approach to get data-provider driven tests into a fixed order?