Can the maven surefire plugin run multiple test runs in a direct call? (Sonar + Jenkins does not perform all unit tests)

I have a maven project that uses the surefire plugin for unit testing. Currently, testing is split into two default tests and unitTests, both related to the purpose of testing, as follows:

<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <executions> <!-- Test one set of files --> <execution> <id>default-test</id> <goals> <goal>test</goal> </goals> <configuration> <includes> ... </includes> </configuration> </execution> <!-- Test a different set of files --> <execution> <id>unitTests</id> <goals> <goal>test</goal> </goals> <configuration> <includes> ... </includes> </configuration> <execution> </executions> </plugin> </plugins> 

This works fine when running mvn test :

 $ mvn test ... [INFO] maven-surefire-plugin:2.13:test (default-test) ... [INFO] maven-surefire-plugin:2.13:test (unitTests) 

I am using the Jenkins Sonar plugin to generate code metrics, and Jenkins is configured as follows:

  • run the build action mvn clean install -DskipTests
  • run Sonar plugin as post build action

This means that the Sonar plugin runs unit tests, and unit tests run only once. And I see the following output when the Sonar plugin starts:

 [INFO] maven-surefire-plugin:213:test (default-cli) 

Note that only default cli is called, not test + unitTests by default, because (I suppose) the surefire plugin is called directly through mvn surefire:test instead of the mvn test life cycle.

I can add the default-cli execution to the POM file and copy the configuration from the default execution, but this will only perform one set of unit tests. Unit tests configured to run unitTests are not executed at all, although this execution has the same goal.

How can I guarantee that the default cli and unitTests calls when the Sonar plugin calls mvn surefire:test ?

I think that perhaps my Jenkins setup will change, so that unit tests will be performed in the normal assembly action, which generates code coverage reports, and then the Sonar plugin runs as the post-assembly action and loads these reports into analysis. Not sure if this is possible, or what changes are needed for my POM files to support this (hoping to make minimal changes to the POM files is another goal).

+6
source share

All Articles