如何让我的 Maven 集成测试运行 [英] How do I get my Maven Integration tests to run
问题描述
我有一个 maven2 多模块项目,在我的每个子模块中,我都有名为 Test.java
和 Integration.java
的 JUnit 测试,用于单元测试和分别进行集成测试.当我执行:
I have a maven2 multi-module project and in each of my child modules I have JUnit tests that are named Test.java
and Integration.java
for unit tests and integration tests respectively. When I execute:
mvn 测试
执行子模块中的所有 JUnit 测试 *Test.java
.当我执行
all of the JUnit tests *Test.java
within the child modules are executed. When I execute
mvn test -Dtest=**/*集成
Integration.java
测试都不会在子模块中执行.
none of the Integration.java
tests get execute within the child modules.
这些对我来说似乎是完全相同的命令,但是带有 -Dtest=/*Integration** 的命令不起作用,它显示在父级别运行的 0 个测试,而没有任何测试
These seem like the exact same command to me but the one with the -Dtest=/*Integration** does not work it displays 0 tests being run at the parent level, which there are not any tests
推荐答案
您可以设置 Maven 的 Surefire 来分别运行单元测试和集成测试.在标准单元测试阶段,您运行与集成测试模式不匹配的所有内容.然后您创建第二个测试阶段,只运行集成测试.
You can set up Maven's Surefire to run unit tests and integration tests separately. In the standard unit test phase you run everything that does not pattern match an integration test. You then create a second test phase that runs just the integration tests.
这是一个例子:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
这篇关于如何让我的 Maven 集成测试运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!