Launch Junit Suite with the Maven Team

I have several Junit test suites (SlowTestSuite, FastTestSuite, etc.). I would like to run only a specific set using the maven command. eg.

mvn clean install test -Dtest=FastTestSuite -DfailIfNoTests=false 

but does not work. Just don't run any tests. Any suggestions please.

+24
source share
2 answers

I achieved this by adding a property to pom like:

 <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> 

therefore it by default runs FastTestSuite, but you can run another test, for example. SlowTestSuite using the maven command as:

 mvn install -DrunSuite=**/SlowTestSuite.class -DfailIfNoTests=false 
+35
source

The keyword you missed is maven-surefire-plugin: http://maven.apache.org/plugins/maven-surefire-plugin/ .

Using:

 <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 do a little search when the stack overflows, you can find the information:

Launching a JUnit4 Test Suite in Maven Using the maven Failover Plugin Using JUnit Categories with the Maven Failsafe Plugin

In addition, you can define a profile, for example fastTest, that will be launched by adding a parameter to the cmd line:

 mvn package -PfastTests 

This profile also includes some inclusions.

+5
source

Source: https://habr.com/ru/post/914586/


All Articles