将JUnit类与Maven Failsafe插件一起使用

pra*_*pes 11 java junit unit-testing maven maven-failsafe-plugin

我正在使用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>
Run Code Online (Sandbox Code Playgroud)

这是日志的故障安全部分:

[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
Run Code Online (Sandbox Code Playgroud)

提供者org.apache.maven.surefire.junitcore.JUnitCoreProvider是否可以在日志输出中看到正确的一个?

tun*_*ith 14

默认情况下,failsafe插件会排除各种文件.你必须覆盖它.因此,请将配置部分更改为以下内容:

<configuration>
    <includes>
        <include>**/*.java</include>
    </includes>
    <groups>com.mycompany.test.IntegrationTest</groups>
    <excludedGroups>com.mycompany.test.UnitTest</excludedGroups>
</configuration>
Run Code Online (Sandbox Code Playgroud)