【问题标题】:Maven not recognizing integration tests in multi-module projectMaven 无法识别多模块项目中的集成测试
【发布时间】:2019-06-03 09:54:25
【问题描述】:

我正在尝试使用故障安全插件为我的多模块 Maven 项目设置集成测试。 在一个较小的虚拟项目中,我有以下结构:

pom.xml
src 
-main
--java
---com
----App.java
-test
--java 
---com 
----AppIT.java

这是对 pom.xml 的相关补充:

<profiles>
  <profile>
    <id>failsafe</id>
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>2.22.0</version>
          <executions>
             <execution>
               <goals>
                 <goal>integration-test</goal>
                 <goal>verify</goal>
               </goals>
             </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>         

一切正常,当我运行 mvn verify -Pfailsafe 时检测到测试。

对于新项目,我有以下内容 结构:

pom.xml
module-1
module-2
module-testing
-src
--test
---java    
----com
-----Test1.java
-----Test2.java
-----...
-----RestIT.java

Test1.java 到 TestN.java 都是单元测试。 RestIT.java 是我只想成为的空集成测试的名称 验证命令检测到的方式与在旧虚拟项目中检测到 AppIT.java 的方式相同。

这是我为整个项目添加到 pom.xml 的内容(与虚拟 Maven 项目的 pom.xml 中的内容相同):

<profiles>
  <profile>
    <id>failsafe</id>
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>2.22.0</version>
          <executions>
            <execution>
              <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
 </profiles>

在mvn verify -Pfailsafe 的输出中检测到现有的单元测试,但RestIT.java 测试没有。我也有 以前看到过“未找到故障安全配置文件”的错误,当我运行该命令时它不存在 将上面的 sn-p 添加到父 pom.xml 中。

如果您有兴趣查看整个 maven 命令输出或整个 pom.xml,请告诉我,我会添加 Dropbox 链接。

【问题讨论】:

    标签: java maven pom.xml maven-plugin maven-failsafe-plugin


    【解决方案1】:

    尝试将其添加到带有集成测试的模块中:

    <profiles>
      <profile>
        <id>failsafe</id> 
      </profile>
    </profiles>
    

    注意,ID 是一样的。我怀疑这将允许模块获取配置文件内容。默认情况下不继承配置文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-10
      • 2021-07-22
      • 2010-12-16
      • 2014-10-13
      • 2017-01-29
      • 2018-04-19
      • 1970-01-01
      相关资源
      最近更新 更多