3

我正在做一个基于 Maven 的项目。项目有多个模块。这是项目结构

- 项目

--Module1  
   -- pom.xml  
--Module2  
   -- pom.xml    
--Module3-war   
   -- pom.xml 
--parent module   
   --pom.xml

父模块封装类型为“pom”,所有模块都在此定义。
我在父模块 pom 中添加了故障安全插件,如下所示

 <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 后被执行,但它找不到测试类。见下文

[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 项目中编写集成测试的最佳实践是什么?
4

1 回答 1

0

我认为您必须在故障安全插件配置中添加 dependenciesToScan 。IE:

 <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

于 2014-03-18T17:26:36.677 回答