【问题标题】:mvn failsafe:verify broken when using dependenciesToScan?mvn failsafe:使用dependenciesToScan时验证损坏?
【发布时间】:2015-03-14 15:14:46
【问题描述】:

我有以下故障安全设置,当我“正常”运行时它按预期工作(= 使用 mvn 验证,并且不使用 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>
  • 集成测试按预期运行,
  • 如果没有指定测试,验证会按预期爆炸,并且
  • 当集成测试失败时,构建会在验证阶段中断

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

<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!

【问题讨论】:

    标签: java maven maven-failsafe-plugin


    【解决方案1】:

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

    你已经这样配置了:

    <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)。

    【讨论】:

    • 是的,你是对的。这是错误的,现在解决了这个问题......当我发布问题时,将带有 dependenciesToScan 的代码粘贴到错误的位置。然而,这确实与/解决我的问题有关。 :(
    • 您是否有显示错误行为的示例项目? Create on 可能在 Gihib 上?
    • 不,抱歉。这一切都在我们的企业 github 上。 :( 我可能会清理一些东西并发布在 github 上,但这需要我一点时间......
    • 清理一下就好了。没问题,慢慢来。
    【解决方案2】:

    我遇到了同样的问题。尝试使用 dependenciesToScan 功能从 jar 中运行测试。我配置的mavenpom.xml,也有&lt;packaging&gt;pom&lt;/packaging&gt;

    在运行 mvn verify -x 时,我得到了这个堆栈跟踪:

    Caused by: org.apache.maven.plugin.MojoFailureException: No tests to run!
        at org.apache.maven.plugin.failsafe.VerifyMojo.verifyParameters (VerifyMojo.java:225)
    

    查看源代码 org.apache.maven.plugin.failsafe.VerifyMojo:

    if ( !getTestClassesDirectory().exists() )
    {
        if ( getFailIfNoTests() != null && getFailIfNoTests() )
        {
            throw new MojoFailureException( "No tests to run!" );
        }
    }
    

    测试源目录应该存在。

    我首先创建了一个空文件夹target/empty-test-classes,然后将其添加到插件配置中来解决它:

    <testClassesDirectory>${project.build.directory}/empty-test-classes</testClassesDirectory>
    

    2013 年提出了一个问题,并提供了有关如何解决此问题的其他建议: https://issues.apache.org/jira/browse/SUREFIRE-1024

    【讨论】:

    • 在 Maven Surefire 2.19 中修复了 SUREFIRE-1024 问题。
    【解决方案3】:

    避免在验证阶段启用failIfNoTests,在集成测试阶段启用它就足够了:

            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <failIfNoTests>true</failIfNoTests>
                        </configuration>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <dependenciesToScan>
                        <dependency>${project.groupId}:cms-it</dependency>
                    </dependenciesToScan>
                </configuration>
            </plugin>
    

    【讨论】:

      猜你喜欢
      • 2017-06-29
      • 1970-01-01
      • 2014-07-04
      • 2011-08-23
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多