0

I am trying to split up integration-tests and smoke-tests using the @Category - Annotation of JUnit and profiles. So that if I run mvn clean install -P smoke-tests only the Smoke-Tests get executed and if I run mvn clean install every test runs.

The thing is:

When I exclude the groups in Maven with <excludeGroups> it excludes the groups as expected. But when I try to include them with <groups> it still runs every test. The Maven code is nothing fancy:

<profile>
    <id>smoke-tests</id>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.12</version>
                <configuration>
                    <parallel>classes</parallel>
                    <threadCount>4</threadCount>
                    <perCoreThreadCount>false</perCoreThreadCount>
                    <!-- <excludeGroups>de.package.SmokeTest</excludeGroups> -->
                    <groups>de.package.SmokeTest</groups>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

Of course I could solve this problem by using <include> and <exclude> but I would really like to use the @Category Annotation.

Any help is appreciated.

tk2000
  • 631
  • 2
  • 6
  • 10

1 Answers1

1

This is a bug which is fixed in 2.12.1: JUnit categories only work when junit47 provider is explicitly set. If you can't upgrade, explicitly specify a junit provider, and it should work:

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.12</version>
  <configuration>
    <groups>uk.co.farwell.test.SlowTests</groups>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-junit47</artifactId>
      <version>2.12</version>
    </dependency>
  </dependencies>
</plugin>
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
  • Thank you for your answer. I tried your solution with `mvn test` and Maven doesn't run any tests. It just shows `Tests run: 0, Failures: 0, Errors: 0, Skipped: 0` – tk2000 May 27 '13 at 08:46
  • 1
    Which solution did you try? Upgrading to 2.12.1 or adding the dependency? – Matthew Farwell May 27 '13 at 09:24
  • Sorry, I've just noticed that you've got parallel running enabled. Looking at https://jira.codehaus.org/browse/SUREFIRE-817, this may have an effect. Try 2.12.3 instead. – Matthew Farwell May 27 '13 at 12:55