我正在从事一个基于 maven 的项目。项目有多个模块。 这是项目结构
-- 项目
--Module1 -- pom.xml --Module2 -- pom.xml --Module3-war -- pom.xml --parent module --pom.xml
父模块封装类型为“pom”,所有模块均定义于此。
我在父模块 pom 中添加了 failsafe-pligin,如下所示
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
现在当我运行“mvn verify”命令时,故障保护插件没有被执行。 我的集成测试名称“TestServiceIT.java”在结构的 module1 中。
当我在我的 war 模块中添加相同的“故障安全”插件时,我看到故障安全插件在创建 WAR 后被执行,但它找不到测试类。见下文
[INFO] Started Jetty Server
[INFO]
[INFO] --- maven-failsafe-plugin:2.15:integration-test (integration-test) @ service-integration-test
---
[INFO] No tests to run.
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform d
endent!
[INFO]
[INFO] --- jetty-maven-plugin:8.1.11.v20130520:stop (stop-jetty) @ service-integration-test ---
[INFO]
[INFO] --- maven-failsafe-plugin:2.15:verify (verify) @ service-integration-test ---
[INFO] No tests to run.
所以,我的问题是
- 当在主 pom.xml 中定义故障安全插件时,为什么它没有被执行?
- 为什么找不到另一个模块中定义的测试用例?
- 在多模块 Maven 项目中编写集成测试的最佳实践是什么?
最佳答案
我认为您必须在故障安全插件配置中添加 dependenciesToScan。 即:
<dependencies>
<dependency>
<groupId>org.arquillian.tck.container</groupId>
<artifactId>arquillian-tck-container</artifactId>
<version>1.0.0.Final-SNAPSHOT</version>
<classifier>tests</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14-SNAPSHOT</version>
<configuration>
<dependenciesToScan>
<dependency>org.arquillian.tck.container:arquillian-tck-container</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
但是因为这个错误我无法测试它https://issues.apache.org/jira/browse/SUREFIRE-1024
关于maven-2 - 多模块项目中的 Maven 故障保护插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22122814/