您可以将 IT 放入不同的文件夹,如下所示:
.
|-- 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
需要以下内容才能使编译器等知道文件夹。
<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 需要以下内容:
<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。