[英]Maven Surefire Test Rerun Parameter Does Not Re-Run Failing Tests
[英]Surefire rerun failing tests not working
我想重新運行一個我知道會失敗的測試,因為我正在嘗試測試 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.
只是添加到 Wim Rutgeerts 的答案 - rerunFailingTestsCount
必須在configuration
部分,而不是在properties
,如下所示:
<configuration>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
在我使用maven-surefire-plugin
2.19.1 的情況下,它是這樣工作的。 當它在properties
它不起作用。
盡管文檔中缺少該參數,但在 Maven Surefire 插件的 2.18 版中引入了參數rerunFailingTestsCount
,如SUREFIRE-1087 中所述。 由於您使用的是默認版本 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)。
除了使用命令行屬性 -Dsurefire.rerunFailingTestsCount=2,您還可以在屬性部分的 pom 中定義它
<properties>
<surefire.rerunFailingTestsCount>2</surefire.rerunFailingTestsCount>
</properties>
JUnit 5更新:Maven Surefire 3.0.0-M4
或更高版本現在允許您在執行 JUnit 5 測試時使用rerunFailingTestsCount
系統屬性。
確保在運行mvn clean
階段時傳遞以下屬性:
-Dsurefire.rerunFailingTestsCount=3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.