问题
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.
回答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>
来源:https://stackoverflow.com/questions/16768732/why-does-excludegroups-work-but-groups-doesnt