Reputation: 629
I am working on a project to prioritize Junit tests based on their statement coverage for any Maven project (I am picking random projects from Git). So far I am able to get a list of the prioritized tests.
I am not sure how to make the Maven project run the tests in the sequence that I have come up with.
I did some search and found that Maven surefire plugin supports order using the runOrder tag. But the order is fixed - alphabetical/ reverse etc. I also came across TestNG which supports order specified on an XML file.
I cannot modify the source code in the target project( Since the source code is not written by me). I can only add new config files if needed or edit the POM.xml.
How can I achieve this? I would really appreciate if you could please direct me any resource useful to achieve this.
TIA
Upvotes: 0
Views: 1306
Reputation: 666
You can create and use JUnitTestSuite for this.
@RunWith(Suite.class)
@SuiteClasses({Test1.class,
Test2.class
})
public class YourTestSuite {
}
Test suite runs test cases in order in which they are mentioned in @SuiteClasses annotation.
And if you want to run test cases in order through maven goal like maven test goal, you can use this test suite. Just exclude test cases and include test case through plugin configuration given below.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
<includes>
<include>**/*TestSuite.java</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
<additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
</additionalClasspathElements>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
</configuration>
</plugin>
Upvotes: 1