Why does <excludeGroups> work but <groups> doesnt?

允我心安 提交于 2019-12-12 00:47:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!