从pom排除测试文件夹不起作用

时间:2019-06-26 00:30:17

标签: maven maven-3 pom.xml

我有2套测试。一个用于junit测试,另一个用于db-unit测试。我只想在一个单独的阶段执行db-unit测试用例,例如说“ mvn integration-test”。

junit test cases folder: bso
db-unit test cases folder: dao

但是当我运行“ mvn integration-test”时,它也会自动运行junit测试用例。因此,我排除了junit测试用例文件夹,即“ bso”。但是它仍然会在bso文件夹中运行测试用例。 在这里查看我的pom文件。如何仅在“ dao”文件夹中运行测试用例?

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
            <trimStackTrace>false</trimStackTrace>
        </configuration>
        <executions>
            <execution>
              <id>unit-tests</id>
              <phase>test</phase>
              <goals>
                 <goal>test</goal>
              </goals>
              <configuration>
                  <skip>true</skip>
              </configuration>
           </execution>
           <execution>
              <id>integration-tests</id>
              <phase>integration-test</phase>
              <goals>
                 <goal>test</goal>
              </goals>
              <configuration>
                 <skip>false</skip>
                 <includes>
                   <include>**/dao/**</include>
                 </includes>
                 <excludes>
                    <exclude>**/bso/**</exclude>
                 </excludes>
              </configuration>
           </execution>
        </executions>
    </plugin>

2 个答案:

答案 0 :(得分:0)

exclude中的execution标签从id中删除为集成测试,将导致在dao包下执行测试。

以下是相同的代码段:


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <trimStackTrace>false</trimStackTrace>
                </configuration>
                <executions>
                    <execution>
                        <id>unit-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                            <includes>
                                <include>**/dao/**</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

答案 1 :(得分:0)

通常,您需要使用不同的插件执行单元和集成测试 单元测试通常由Maven Surefire插件处理,而集成测试则由Maven Failsafe插件处理。

为什么? 出于我的考虑,有两个原因:

  • 如果集成测试失败,则您可能不想使构建失败(并非总是如此,但仍然如此)。
  • 测试报告不同(在不同的文件夹下生成)

默认情况下,Surefire将识别为以*Test结尾的测试类,Failsafe插件与*IT一起使用(集成测试) 因此,请将它们放在不同的文件夹下以免混淆,您可以使用。

完成后,检查报告(在目标文件夹中,您会找到surefire-reportsfailsafe-reports文件夹),并发现插件确实选择了正确的测试用例

相关问题