Maven故障保险:遵循指南,但没有运行“验证”

时间:2014-01-15 13:03:30

标签: java maven maven-failsafe-plugin

我正在努力让Maven故障安全插件运行我的集成测试,但即使我已经按照https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html上的指南操作它也无效。

我的maven项目(MvnTest)看起来像这样(源文件在下面):

pom.xml
-src
  -main
    -java
    -resources
 -test
  -java
    SomeIT.java
    SomeTest.java

mvn test 使用sunfire插件正确运行 SomeTest.java 中的测试。输出:

...
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MvnTest ---
[INFO] Surefire report directory: ...
...
Running SomeTest
Tests run: 1, Failures: 1

然而, mvn verify 命令输出与 mvn test 完全相同的东西,这在两个方面是错误的:1)它调用sunfire,2)它运行SomeTest.java中的测试,但只应在SomeIT.java(https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html

中运行

我相信我已按照指南正确使用故障保护,但显然我一定错过了什么。我做错了什么?

消息来源

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>MvnTest</groupId>
    <artifactId>MvnTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.16</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
    </dependencies>
</project>

SomeIT.java:

import org.junit.Test;
import static org.junit.Assert.assertTrue;

public class SomeIT {
    @Test
    public void test2() {
        assertTrue(4 == 3);
    }
}

SomeTest.java:

import org.junit.Test;
import static org.junit.Assert.assertTrue;

public class SomeTest {
    @Test
    public void test1() {
        assertTrue(2 == 3);
    }
}

1 个答案:

答案 0 :(得分:0)

在pom.xml中为maven-failsafe-plugin添加包含部分

看起来像:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.16</version>
            <configuration>
                <includes>
                    <include>**/*IT.java</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
相关问题