Reputation: 57
Is there a quicker way to order the execution of test classes in maven without creating suits?
Upvotes: 1
Views: 4998
Reputation: 997
The Maven Surfire plugin allows you to specify some order by setting the runOrder element: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#runOrder
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<groups>${testcase.groups}</groups>
<runOrder>reversealphabetical</runOrder>
</configuration>
</plugin>
Upvotes: 1
Reputation: 14661
To order the methods within a class Junit comes with a FixMethodOrder annotation. However I had to warn against doing such things. Unit tests should be independent and not require state from the previous test to work.
The class order however requires a suite, however this is also annotation based and so very small.
@RunWith(Suite.class)
@Suite.SuiteClasses({TestA.class, TestB.class})
public class TestSuite {
}
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestA {
@Test
public void testA1() {
System.out.println("testA1");
}
@Test
public void testA2() {
System.out.println("testA2");
}
}
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestB {
@Test
public void testB1() {
System.out.println("testB1");
}
@Test
public void testB2() {
System.out.println("testB2");
}
}
Upvotes: 6