Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Maven Surefire plug-in with different groups for test and integration-test?

I want to use testng with the Surefire plug-in of Maven. The idea is to tag some tests with a group integrationTest and run the plug-in twice: for goal test excluding the group integrationTest and for goal integration-test including the group integrationTest only.

I found some material for running the plug-in for both goals and that works, but the group for the second run does not work (no test is executed).

Here is the plug-in configuration in the build element of my pom.xml:

  <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <excludedGroups>integrationTest</excludedGroups>
      <reportFormat>brief</reportFormat>
      <trimStackTrace>true</trimStackTrace>
      <useFile>false</useFile>
    </configuration>
    <executions>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
        <configuration>
          <groups>integrationTest</groups>
          <excludedGroups/>
          <reportsDirectory>${project.build.directory}/surefire-reports/integration</reportsDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

Any idea? mvn integration-test runs all unit tests as expected (excluding the group integrationTest) but the second test run just writes:

Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.562 sec

The Result of mvn test is as expected, tests run and group integrationTest is ignored.

like image 382
Arne Burmeister Avatar asked Jan 05 '09 10:01

Arne Burmeister


People also ask

How do I run a specific integration-test in Maven?

The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.

Does surefire run tests in parallel?

The surefire offers a variety of options to execute tests in parallel, allowing you to make best use of the hardware at your disposal. But forking in particular can also help keeping the memory requirements low.

What is the difference between Maven surefire and failsafe plugin?

maven-surefire-plugin is designed for running unit tests and if any of the tests fail then it will fail the build immediately. maven-failsafe-plugin is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests.

How does Maven surefire plugin work?

Maven sure fire plugin is used to follow the sequence of tests in testng. xml file. If we don't include the Mavwen surefire plugin then it will execute all the testcases under src/test/java which has prefix or suffix as 'test' and these tests will get executed without any sequence.


2 Answers

I got it - irritating configuration implementation!

<excludedGroups/> does not override <excludedGroups>integrationTest</excludedGroups>. You need to specify any (unknown) group instead, <excludedGroups>none</excludedGroups> for example.

like image 163
Arne Burmeister Avatar answered Oct 04 '22 07:10

Arne Burmeister


The Failsafe plugin is the best way to do this (it may not have been available when you posted this question). It adds an integration-test phase to the build lifecycle. It allows you to have setup and teardown activities run before and after the tests, which is useful for managing an embedded container, for example.

like image 36
Kief Avatar answered Oct 04 '22 07:10

Kief