[英]How to include integration tests via maven-surefire-plugin using path
My Java Maven project separates unit tests from integration tests in the directory structure:我的 Java Maven 项目在目录结构中将单元测试与集成测试分开:
src/test/java
; src/test/java
下的单元测试;src/integration-test/java
.src/integration-test/java
。 src/integration-test/java
is a non-default test source directory, so I added it manually to the project using build-helper-maven-plugin
, as you can see: 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>
I also used maven-failsafe-plugin
to include the test integration classes in the test execution flow, as shown below.我还使用
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>
This approach works, but obliges me to use a naming convention in the test classes.这种方法有效,但迫使我在测试类中使用命名约定。 Precisely, only the ones ending with "IntegrationTest" will be executed.
准确地说,只会执行以“IntegrationTest”结尾的那些。
I would like to configure the plugin based on a naming convention in the path and not in the file name.我想根据路径中的命名约定而不是文件名来配置插件。 Precisely, I intend to allow all classes under
src/integration-test/java
regardless the file names.准确地说,我打算允许
src/integration-test/java
下的所有类,而不管文件名。 I did not succeed so far and every tutorial in the web only shows the approach I implemented and showed you above.到目前为止,我没有成功,网络上的每个教程都只展示了我在上面实现和展示的方法。
Does anyone have any suggestion on how to do that?有没有人对如何做到这一点有任何建议?
Thanks谢谢
AFAIK, both plugins (surefire and failsafe) simply use the classpath. AFAIK,两个插件(surefire 和 failsafe)都只使用类路径。 So, to achieve what you want, you either have to use a naming convention (eg Test vs IT as is standard) or use two different modules.
因此,要实现您想要的目标,您要么必须使用命名约定(例如标准测试与 IT),要么使用两个不同的模块。
The only other (really ugly) solution I could find would be:我能找到的唯一其他(非常丑陋的)解决方案是:
This might work, but is hell to maintain and code ;)这可能有效,但维护和编码是地狱;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.