I have multiple Junit test suites (SlowTestSuite, FastTestSuite etc). I would like to run only specific suite using maven command. e.g.
mvn clean install test -Dtest=FastTestSuite -DfailIfNoTests=false
but its not working. Just not running any test at all. Any suggestions please.
We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.
The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.
I have achieved this by adding property into pom as:
<properties> <runSuite>**/FastTestSuite.class</runSuite> </properties>
and maven-surefire-plugin should be:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>${runSuite}</include> </includes> </configuration> </plugin>
so it means by default it will run FastTestSuite but you can run other test e.g. SlowTestSuite using maven command as:
mvn install -DrunSuite=**/SlowTestSuite.class -DfailIfNoTests=false
The keyword you missed is maven-surefire-plugin :http://maven.apache.org/plugins/maven-surefire-plugin/.
Usage is :
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.1</version> <configuration> <includes> <include>**/com.your.packaged.Sample.java</include> </includes> </configuration> </plugin> </plugins> </build> [...] </project>
If you make a little search on stack overflow, you may find information :
Running a JUnit4 Test Suite in Maven using maven-failsafe-plugin Using JUnit Categories with Maven Failsafe plugin
In addition, you may define profile, like fastTest, that will be triggered by adding parameter to cmd line :
mvn package -PfastTests
This profile would include some inclusions too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With