【发布时间】:2019-11-07 20:35:31
【问题描述】:
我有 2 组测试。一个用于 junit 测试,另一个用于 db-unit 测试。我只想在单独的阶段执行 db-unit 测试用例,比如说“mvn integration-test”。
junit test cases folder: bso
db-unit test cases folder: dao
但是当我运行“mvn integration-test”时,它也会自动运行 junit 测试用例。所以我排除了那个名为“bso”的junit测试用例文件夹。但它仍然会在 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>
【问题讨论】:
-
是的,这可能是一个解决方案。但是为什么这不起作用?
-
数据库测试应该命名为
*IT.java,而其他的应该命名为*Test.java。您必须配置 maven-failsafe-plugin 并根据命名约定,单元测试将由 maven-surefire 执行,无需任何补充配置,集成测试*IT.java将由 maven-failsafe-plugin (maven.apache.org/surefire/maven-failsafe-plugin/usage.html ) 不需要以这种方式排除/包含。