Surefire重新运行失败的测试无法正常工作

问题描述 投票:4回答:3

我想重新运行一个我知道会失败的测试,因为我正在尝试测试Surefire参数以重新运行失败的测试。我尝试使用这两个命令运行Maven,它们都没有按预期工作

-Dsurefire.rerunFailingTestsCount=2 -Dtest=TestThatFails test

-Dsurefire.rerunFailingTestsCount=2 -Dtest=TestThatFails surefire:test

这是pom.xml的一部分

<dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-api</artifactId>
    <version>2.19.1</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.1</version>
</dependency>

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>

我原以为Surefire会在失败后重新启动测试,但是Maven只是抛出了这个错误,我知道如何解决,但我想重新运行测试。

Results :

Tests in error: 
  testA(selenium.services.TestThatWillFail): Element is not currently visible and so may not be interacted with(..)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.060 s
[INFO] Finished at: 2016-11-24T12:58:02+01:00
[INFO] Final Memory: 18M/173M

[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project eskn_selenium: There are test failures.
java maven testing maven-surefire-plugin surefire
3个回答
3
投票

尽管文档中缺少这一点,但在rerunFailingTestsCount中提到的参数SUREFIRE-1087是在Maven Surefire插件的2.18版本中引入的。由于您使用的是默认版本2.12.4(来自Super POM),因此该选项不可用。

因此,修复只是将Surefire版本更新为至少2.18的版本;例如,最新的,目前是2.19.1:

<pluginManagement>
  <plugins>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.19.1</version>
    </plugin>
  </plugins>
</pluginManagement>

请注意,此参数仅适用于JUnit 4+(这是您的情况,因为您有JUnit 4.12)。


4
投票

只是添加到Wim Rutgeerts的答案 - rerunFailingTestsCount必须在configuration部分,而不是在properties,如下:

<configuration>
    <rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>

在我的情况下,maven-surefire-plugin 2.19.1就是这样的。当它在properties它没有奏效。


3
投票

您可以在属性部分的pom中定义它,而不是使用命令行属性-Dsurefire.rerunFailingTestsCount = 2

 <properties>
    <surefire.rerunFailingTestsCount>2</surefire.rerunFailingTestsCount>
 </properties>
© www.soinside.com 2019 - 2024. All rights reserved.