Why doesn't “mvn verify” run my integration tests?

守給你的承諾、 提交于 2020-01-13 08:12:00

问题


I have a multi-module project and I have failsafe defined in the root pom like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <includes>
            <include>**/*IntegrationTest.java</include>
            <include>**/*JourneyTest.java</include>
            <include>**/*CucumberFeatureTest.java</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <excludes>
            <exclude>**/*IntegrationTest.java</exclude>
            <exclude>**/*JourneyTest.java</exclude>
            <exclude>**/*CucumberFeatureTest.java</exclude>
        </excludes>
    </configuration>
</plugin>

Failsafe is not defined anywhere else in my other poms. If I run mvn verify, it skips integration tests (it runs unit tests). But if I run mvn test-compile failsafe:integration-test, it runs integration tests.

I'm under the assumption that failsafe is supposed to run in both of these situations. So why doesn't it run when I type mvn verify?

UPDATE: Just noticed that this was wrapped around these tags:

<build>
    <pluginManagement> <!-- oops -->
        <plugins>
            <plugin>

I feel like this explains the cause, but I'm not sure why unit tests still run like you'd expect with mvn verify and mvn test. Why does surefire work differently from failsafe in this respect?


回答1:


You need to bind failsafe's integration test goal to maven's integration-test and verify phases. By default the failsafe-plugin isn't included in a vanilla maven project. You need to add it. So even though there is an integration-test lifecycle, by default it is not included (well, at least doesn't run the maven-failsafe-plugin). You add it to the integration-test and verify phases (it needs both, it will fail the build at the verify phase only [if the preceding integration-tests failed], so that the post-integration lifecycle phase still has a chance to run and cleanup resources, hence the name "fail safe").

   <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-failsafe-plugin</artifactId>
       <version>2.19</version>
       <configuration>
           <includes>
               <include>**/*IntegrationTest.java</include>
               <include>**/*JourneyTest.java</include>
               <include>**/*CucumberFeatureTest.java</include>
           </includes>
       </configuration>
       <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
   </plugin>



回答2:


I encountered a similar issue when running mvn verify as the integration tests were not executed, but only the unit tests. It worked after marking skipTests to false:

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <skipTests>false</skipTests>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>           
</plugin>


来源:https://stackoverflow.com/questions/33923601/why-doesnt-mvn-verify-run-my-integration-tests

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