I am running these TestNG
tests, through a java main
method (thanks to another post - how to call testng.xml from java main method?)
public class MainTest { //main
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("c:/AbcTests/xyztest.xml");
testng.setTestSuites(suites);
testng.run();
}
}
public class Test001 { //test
@Test(priority=1)
public void a1() {
System.out.println("In a1 run");
}
@Test(priority=2)
public void a2() {
System.out.println("In a2 run");
}
@Test(priority=3)
public void b1() {
System.out.println("In b1 run");
}
}
But when I run it, the tests are randomly picked.
Output:
In a2 run
In a1 run
In b1 run
When running from TestNG, it is fine.
Is there a way to prioritize tests in TestNG when running from a Java main?
------- EDIT ----------
Thank you tim-slifer. I had a look at the xml. It was :-
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Just Test" verbose="3" parallel="methods">
<test name="Smoke">
<classes>
<class name="test2.Test001" />
</classes>
</test>
</suite>
I removed the parallel="methods". And changed it to
<suite name="Just Test" verbose="3">
And it works fine now. I think this was the mistake? Is it correct?