我正在使用JUnit Categories将集成测试与单元测试分开。 Surefire插件配置有效 - 它会跳过使用我的标记接口IntegrationTest注释的测试。
但是,Failsafe插件不会选择集成测试。我甚至试图指定junit47提供程序,但是在集成测试阶段运行零测试。
这是pom.xml片段:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<groups>com.mycompany.test.IntegrationTest</groups>
<excludedGroups>com.mycompany.test.UnitTest</excludedGroups>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
以下是日志的故障安全部分:
[INFO] --- maven-failsafe-plugin:2.12:integration-test (default) @ MyProject.war ---
[INFO] Failsafe report directory: /home/stoupa/MyProject/war/target/failsafe-reports
[INFO] Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='none', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
提供者org.apache.maven.surefire.junitcore.JUnitCoreProvider可以在日志输出中看到正确的吗?
答案 0 :(得分:13)
默认情况下,failsafe插件会排除各种文件。你必须覆盖它。因此,请将配置部分更改为以下内容:
<configuration>
<includes>
<include>**/*.java</include>
</includes>
<groups>com.mycompany.test.IntegrationTest</groups>
<excludedGroups>com.mycompany.test.UnitTest</excludedGroups>
</configuration>
答案 1 :(得分:2)
解决方法强>
@Categories会给您带来痛苦,因为您必须标记每个集成测试。
尝试创建如下所述的inttests配置文件,并跳过surefire执行。
<profile>
<id>inttests</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<!-- skip the unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/IT*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
使用某些字符串对Integration测试进行前缀或后缀,并在include中给出。 默认情况下,failsafe会将所有以IT为前缀的测试作为集成测试。 参考: Failsafe Inclusions & Exclusions
使用maven profile命令
运行它mvn verify -P inttests
注意:在上述方法中,我们需要在构建过程中运行单元测试,然后单独进行单元测试。
更新:使用故障安全插件的JUnit4类别