在Maven中,是否可以将集成测试与单元测试保存在单独的文件夹中? [英] In Maven is it possible to keep integration tests in a separate folder from unit tests?

查看:98
本文介绍了在Maven中,是否可以将集成测试与单元测试保存在单独的文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven和集成测试页面上,该页面上显示:

On the Maven and Integration Testing page it says:

未来谣言说Maven的未来版本将支持 此外,在集成测试阶段还类似于src/it/java 在测试阶段转到src/test/java.

The Future Rumor has it that a future version of Maven will support something like src/it/java in the integration-test phase, in addition to src/test/java in the test phase.

但是那是2011-12-11了.这发生了吗?

but that was back in 2011-12-11. Has this happened yet?

提到设置<testSourceDirectory>,这是他们的一些方法这样做只是为了进行集成测试(即integration-test阶段)?

In this answer to "Run maven test not in default src/test/java folder" it mentions setting the <testSourceDirectory>, is their some way of doing this just for integration test (ie. the integration-test phase)?

我希望使用 Maven FailSafe插件,并避免重命名一堆集成测试或使用仍在试验中的JUnit @Categories.

I'm looking to use the Maven FailSafe plugin and avoid renaming a bunch of integration tests or using the still experimental JUnit @Categories.

推荐答案

您可以将IT放置在不同的文件夹中,如下所示:

You can put the IT'ss into different folder like this:

.
|-- pom.xml
`-- src
    |-- it
    |   `-- java
    |       `-- com
    |           `-- soebes
    |               `-- maui
    |                   `-- it
    |                       `-- BitMaskIT.java
    |-- main
    |   `-- java
    |       `-- com
    |           `-- soebes
    |               `-- maui
    |                   `-- it
    |                       `-- BitMask.java
    `-- test
        `-- java
            `-- com
                `-- soebes
                    `-- maui
                        `-- it
                            `-- BitMaskTest.java

需要以下内容来使编译器等知道文件夹.

The following is needed to make then folders known to the compiler etc.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.5</version>
  <executions>
    <execution>
      <id>add-test-source</id>
      <phase>process-resources</phase>
      <goals>
        <goal>add-test-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>src/it/java</source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>

以下是真正运行IT的必要条件:

The following is needed to really run the IT's:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.15</version>
  <executions>
    <execution>
      <id>integration-test</id>
      <goals>
        <goal>integration-test</goal>
      </goals>
    </execution>
    <execution>
      <id>verify</id>
      <goals>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
</plugin>

这意味着您可以在同一模块中进行集成,但缺点是运行集成测试所用的资源与单元测试所用的资源相同.更好的解决方案是创建一个单独的maven模块,您可以在其中将集成测试放入通常的文件夹src/test/java等中,并且仅配置maven-failsafe-plugin.

This means you can have the integration within the same module which has the disadvantage that running the integration tests use the same resources as the unit tests. A better solution would be to create a separate maven module where you can put the integration tests into the usual folder src/test/java etc. and only configure the maven-failsafe-plugin.

这篇关于在Maven中,是否可以将集成测试与单元测试保存在单独的文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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