【问题标题】:Maven failsafe plugin in multi module project多模块项目中的 Maven 故障安全插件
【发布时间】: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.

所以,我的问题是

  1. 当故障安全插件在 main pom.xml 中定义时,为什么它没有被执行?
  2. 为什么找不到在另一个模块中定义的测试用例?
  3. 在多模块 maven 项目中编写集成测试的最佳实践是什么?

【问题讨论】:

  • 您找到解决方案了吗?
  • 在多模块项目中,故障安全插件对我不起作用。 Failsafe 插件总是在该项目下和子模块中寻找测试。
  • 我的解决方案是创建新模块“integration-test”并在该模块中添加所有测试。在父 pom 中添加这个模块,以便它在最后运行并验证您的集成测试。org.apache.maven.pluginsmaven-failsafe-plugin2.19.1*.IT/*.java

标签: maven-2 maven-plugin maven-failsafe-plugin integration-testing


【解决方案1】:

我认为您必须在故障安全插件配置中添加 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,我无法对其进行测试

【讨论】:

    猜你喜欢
    • 2010-11-24
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 2016-01-30
    相关资源
    最近更新 更多