Surefire 重新运行失败的测试不起作用 [英] Surefire rerun failing tests not working

查看:172
本文介绍了Surefire 重新运行失败的测试不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to rerun a test that I know will fail cause I am trying to test the Surefire parameter for re-running the failing tests. I tried running Maven with these two commands neither of them works as expected

-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 只是抛出此错误,我知道如何解决,但我希望重新运行测试.

I was expecting that Surefire would restart the test after failure but Maven just throws this error, which I know how to solve but I want the test to be rerun.

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.

推荐答案

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

Although that is missing from the documentation, the parameter rerunFailingTestsCount was introduced in version 2.18 of the Maven Surefire Plugin, as mentioned in SUREFIRE-1087. Since you're using the default version of 2.12.4 (that comes from the Super POM), that option is not available.

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

Therefore, the fix is simply to update the Surefire version to a version that is at least 2.18; for example, the latest, which is currently 2.19.1:

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

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

Note that this parameter only works with JUnit 4+ (which is your case, since you have JUnit 4.12).

这篇关于Surefire 重新运行失败的测试不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆