简体   繁体   中英

Maven failsafe: followed guide, but does not run on “verify”

I am trying to make the Maven failsafe plugin run my integration tests, but even though I have followed the guide at https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html it doesn't work.

My maven project (MvnTest) looks like this (source files are below):

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

mvn test correctly runs only the tests in SomeTest.java using the sunfire plugin. Output:

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

However, the mvn verify command outputs exactly the same thing as mvn test which is wrong in two ways: 1) it calls sunfire, and 2) it runs the tests in SomeTest.java but should only run those in SomeIT.java ( https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html )

I believe I have followed the guide on using failsafe correctly, but obviously I must have missed something. What did I do wrong?

SOURCE FILES

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);
    }
}

Add includes section in your pom.xml for maven-failsafe-plugin

Looks like:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM