2017-10-17 177 views

回答

0

您可以使用maven-surefire-plugin + rerunFailingTestsCount參數。它適用於JUnit4 +。見下面的例子。 和平的pom.xml的:

<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.19.1</version> 
     <configuration> 
      <reportsDirectory> ${project.basedir}/test-output</reportsDirectory> 
      <rerunFailingTestsCount>1</rerunFailingTestsCount> 
     </configuration> 
    </plugin> 
</plugins> 

簡單的Java測試:

import org.junit.Assert; 
import org.junit.Test; 

import java.util.Random; 

public class SimpleTest { 
    @Test 
    public void test(){ 
     if(new Random().nextBoolean()) { 
      Assert.fail(); 
     } 
    } 
} 

控制檯輸出:

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running SimpleTest 
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.025 sec <<< FAILURE! - in SimpleTest 
test(SimpleTest) Time elapsed: 0.008 sec <<< FAILURE! 
java.lang.AssertionError 
     at SimpleTest.test(SimpleTest.java:10) 


Results : 

Flaked tests: 
SimpleTest.test(SimpleTest) 
    Run 1: SimpleTest.test:10 
    Run 2: PASS 


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

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
相關問題