【发布时间】:2014-04-03 02:05:59
【问题描述】:
我正在开发一个基于 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.
所以,我的问题是
- 当故障安全插件在 main pom.xml 中定义时,为什么它没有被执行?
- 为什么找不到在另一个模块中定义的测试用例?
- 在多模块 maven 项目中编写集成测试的最佳实践是什么?
【问题讨论】:
-
您找到解决方案了吗?
-
在多模块项目中,故障安全插件对我不起作用。 Failsafe 插件总是在该项目下和子模块中寻找测试。
-
我的解决方案是创建新模块“integration-test”并在该模块中添加所有测试。在父 pom 中添加这个模块,以便它在最后运行并验证您的集成测试。
org.apache.maven.plugins maven-failsafe-plugin 2.19.1 *.IT/*.java
标签: maven-2 maven-plugin maven-failsafe-plugin integration-testing