如何运行Maven Integration测试 [英] How do I get my Maven Integration tests to run

查看:611
本文介绍了如何运行Maven Integration测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven2多模块项目,在我的每个子模块中,我都有JUnit测试,名为 Test.java Integration。 java 分别用于单元测试和集成测试。执行时:

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 test

全部执行子模块中的JUnit测试 * Test.java 当我执行

all of the JUnit tests *Test.java within the child modules are executed. When I execute

mvn test -Dtest = ** / * Integration

没有 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 Integration测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆