java - mvn failsafe:使用dependencyToScan验证是否损坏?

我具有以下故障安全设置,并且在我“正常”运行事物时可以按预期运行(=使用mvn verify,并且不使用dependenciesToScan):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.18.1</version>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <failIfNoTests>true</failIfNoTests>
    <suiteXmlFiles>
      <suiteXmlFile>src/test/resources/mySuite.xml</suiteXmlFile>
    </suiteXmlFiles>
  </configuration>
</plugin>



集成测试按预期运行,
如果未指定测试,则验证会按预期爆炸,并且
当集成测试失败时,构建会在验证阶段中断


但是,当我采用完全相同的故障安全设置,并在仅从jar文件运行测试的“ test-runner” pom /项目中使用“ dependenciesToScan”对其进行扩展(因此,我不会每次重新编译/重建整个项目我想运行集成测试的时间):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.18.1</version>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <failIfNoTests>true</failIfNoTests>
    <suiteXmlFiles>
      <suiteXmlFile>src/test/resources/mySuite.xml</suiteXmlFile>
    </suiteXmlFiles>
    <dependenciesToScan>
      <dependency>${test.library.groupId}:${test.library.artifactId}</dependency>
    </dependenciesToScan>
  </configuration>
</plugin>


这是发生了什么:


集成测试按预期运行,
构建失败,因为它找不到要运行的任何测试(在验证阶段!?-见下文),并且
当我删除failIfNoTests时,即使有测试失败,也报告构建成功


我检查了所有内容,并尝试了一些方法,所以我不确定此处可能缺少的内容。如果我不使用dependenciesToScan,插件配置显然可以正常工作。

当您使用dependenciesToScan时,故障保护插件中是否有可能破坏验证业务逻辑的错误?

Tests run: 79, Failures: 6, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:verify (default) @ test-runner ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:2.18.1, parent: sun.misc.Launcher$AppClassLoader@42a57993]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify' with basic configurator -->
[DEBUG]   (s) basedir = /xyz/test-runner
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (s) failIfNoTests = true
[DEBUG]   (s) reportsDirectory = /xyz/test-runner/target/failsafe-reports
[DEBUG]   (s) skip = false
[DEBUG]   (f) summaryFile = /xyz/test-runner/target/failsafe-reports/failsafe-summary.xml
[DEBUG]   (s) testClassesDirectory = /xyz/test-runner/target/test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG] -- end configuration --
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:27 min
[INFO] Finished at: 2015-03-13T22:44:46-04:00
[INFO] Final Memory: 13M/250M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify (default) on project test-runner: No tests to run! -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify (default) on project test-runner: No tests to run!

最佳答案

嗯...首先,从您发布的内容来看,您的配置错误:

您已经这样配置它:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.18.1</version>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <failIfNoTests>true</failIfNoTests>
    <suiteXmlFiles>
      <suiteXmlFile>src/test/resources/mySuite.xml</suiteXmlFile>
    </suiteXmlFiles>
  </configuration>
  <dependenciesToScan>
    <dependency>${test.library.groupId}:${test.library.artifactId}  </dependency>
  </dependenciesToScan>
</plugin>


我很惊讶您没有从Maven获得失败...

但是它应该看起来像这样。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.18.1</version>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <failIfNoTests>true</failIfNoTests>
    <suiteXmlFiles>
      <suiteXmlFile>src/test/resources/mySuite.xml</suiteXmlFile>
    </suiteXmlFiles>
    <dependenciesToScan>
      <dependency>${test.library.groupId}:${test.library.artifactId}  </dependency>
    </dependenciesToScan>
  </configuration>
</plugin>


因为调试输出未显示任何形式的配置,这些配置代表您在配置中编写的内容(dependenciesToScan)。

本文翻译自 https://stackoverflow.com/questions/29050477/

网站遵循 CC BY-SA 4.0 协议,转载或引用请注明出处。

标签 java maven maven-failsafe-plugin


相关文章:

java - Maven Surefire插件:runOrder中的文件系统是什么意思?

java - 如何创建自定义Android单选按钮?

java - Spring MVC:应用程序上下文运行两次

google-app-engine - Maven + App Engine + Google Eclipse插件

java - 如何确定实际安装的maven-gpg-plugin的版本?

java - 在surefire和failsafe中运行已启用预览功能的测试时出现问题

java - 如何从父Maven模块运行测试?

java - 将单个csv对象存储到数组中

java - Applet似乎找不到资源

maven - 尝试执行“bin / mkdistro.sh -DskipTests”时出现Oozie错误