In Maven is it possible to keep integration tests in a separate folder from unit tests?

末鹿安然 提交于 2019-11-29 16:25:40

问题


On the Maven and Integration Testing page it says:

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.

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

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)?

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


回答1:


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>

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>

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.



来源:https://stackoverflow.com/questions/17865088/in-maven-is-it-possible-to-keep-integration-tests-in-a-separate-folder-from-unit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!