即使在排除它们之后,单元测试也会在集成测试阶段执行

时间:2016-08-15 15:56:11

标签: java maven unit-testing integration-testing

我的maven应用程序中有一个单元测试(ProductDaoTest.java)和一个集成测试(ProductDaoIT.java)。

我想在mvn verify命令调用期间仅执行集成测试,但即使在使用<exclude>配置中的maven-failsafe-plugin标记将其排除后,单元测试也会执行。 / p>

如何解决此问题?

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
            <excludes>
                <exclude>**/*Test.java</exclude>
            </excludes>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

更新了POM(带解决方案):

 <!-- For skipping unit tests execution during execution of IT's -->
    <profiles>
        <profile>
            <id>integration-test</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.19.1</version>
                        <!-- Skips UTs -->
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                    <!-- Binding the verify goal with IT -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.19.1</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <port>5000</port>
                            <path>${project.artifactId}</path>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-tomcat</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <fork>true</fork>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-tomcat</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>shutdown</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>    
                </plugins>
            </build>
        </profile>
    </profiles>

mvn clean install - 默认情况下仅运行单元测试

mvn clean install -Pintegration-test - 默认情况下仅运行集成测试

0 个答案:

没有答案