我的Java项目将单元测试与目录结构中的集成测试分离开来:
src/test/java;
src/integration-test/java.下的
src/integration-test/java是一个非默认的测试源目录,所以我使用build-helper-maven-plugin手动将它添加到项目中,如您所见:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
...
</executions>
</plugin>我还使用maven-failsafe-plugin在测试执行流程中包含测试集成类,如下所示。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>这种方法可以工作,但要求我在测试类中使用命名约定。准确地说,只有那些以"IntegrationTest“结尾的才会被执行。
我想根据路径中的命名约定而不是文件名来配置插件。确切地说,我打算允许src/integration-test/java下的所有类,而不管文件名如何。到目前为止,我还没有成功,网络上的每个教程都只展示了我实现的方法,并向您展示了上面的内容。
有人对怎么做有什么建议吗?
谢谢
发布于 2020-01-02 15:27:17
AFAIK,这两个插件(确保火和故障安全)只需使用类路径。因此,要实现您想要的,您要么使用命名约定(如测试与IT是标准的),要么使用两个不同的模块。
我唯一能找到的(非常丑陋的)解决方案是:
directory
中使用相应的源目录进行故障安全。
在每个配置文件中,通过它的configuration
这可能是可行的,但是维护和编码都很困难;)
https://stackoverflow.com/questions/59565652
复制相似问题