Reputation: 1
I'm creating TestNG.xml programatically and running tests in parallel.
The issue is: - I need to run Test2 after Test1
I tried Using 'dependsOnGroup' by assigning Test1 to a group and then asking Test2 to dependOn Test1's group. But when I run the test suite, only Test1 will get Executed, Test2 will be skipped. No errors reported.
@Test(groups = {"FirstTest"})
public class Test1 {
public void hello(){
syso("Test1");
}
}
@Test(groups = {"SecondTest"}, dependsOnGroups= {"FirstTest"}, alwaysRun=true)
public class Test2 {
public void hi(){
syso("Test2");
}
}
I'm using TestNG.6.9.6.jar
Upvotes: 0
Views: 987
Reputation: 95
You can also use the dependsOnMethods()
method instead of dependsOnGroup()
.
Upvotes: 0
Reputation: 1145
Adding priority would do what you need. @Test(priority=1)
. The lower priority would execute first.
@Test(priority=1)
public class Test1 {
public void hello(){
syso("Test1");
}
}
@Test(priority=2)
public class Test2 {
public void hi(){
syso("Test2");
}
}
It will first run Test1 and then Test2. So whichever classes you put in your test suite, it would consider the priorities of all the test functions in all it's classes.
Should do the needful for you in a lesser complicated way.
I hope it helps. :)
Upvotes: 1