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

2

17

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.

Merited answered 5/1, 2009 at 10:11 Comment(0)
M
14

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.

Merited answered 6/1, 2009 at 8:55 Comment(2)
excludedGroups does not work with TestNG 5.14.1 - use 5.14.2 instead!Merited
With Surefire 2.18.1 and JUnit 4.10, I get the error [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (integration-test) on project example-project: Execution integration-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: There was an error in the forked process [ERROR] java.lang.RuntimeException: Unable to load category: none. It seems the group you override with must at least exist, even if it's not used anywhere. I do this with a public interface SystemTest extends IntegrationTest and exclude that category.Mauer
B
9

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.

Batholith answered 12/3, 2011 at 9:45 Comment(1)
You might be right: Maven Central search dates the oldest maven-failsafe-plugin artifact to January 12, 2010. Since then, I think, it's become the preferred solution to the problem.Imena

© 2022 - 2024 — McMap. All rights reserved.