2016-11-24 353 views
1

我想重新運行一個測試,我知道會失敗,因爲我試圖測試Surefire參數以重新運行失敗的測試。 我試圖與這兩個命令如預期Surefire重新運行失敗的測試不起作用

-Dsurefire.rerunFailingTestsCount=2 -Dtest=TestThatFails test 

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

這裏都沒有工作運行Maven是的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 ju st拋出這個錯誤,我知道如何解決,但我想重新運行測試。

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. 

回答

1

雖然是從文檔丟失,參數rerunFailingTestsCount在Maven Surefire插件的版本2.18中引入,爲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)。

+0

oooooh現在我明白了! 我認爲將它作爲依賴添加將會完成這項工作,但它必須添加爲插件。我正要問,如果你沒有注意到它已經在pom.xml中定義好了,哈哈。 謝謝! –

1

而不是使用命令行屬性-Dsurefire.rerunFailingTestsCount = 2,你也可以在屬性部分的POM定義它

<properties> 
    <surefire.rerunFailingTestsCount>2</surefire.rerunFailingTestsCount> 
</properties> 
0

只需添加到維姆Rutgeerts的答案 - rerunFailingTestsCount必須在configuration部分,而不是在properties,像這樣:

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

在我的情況與maven-surefire-plugin 2.19.1它的工作這種方式。當它在properties它不起作用。

相關問題