0
我創建了一個Maven UI測試項目。現在,我作爲mvn測試通過命令運行。但我想重新運行失敗的測試用例。我是否應該在pom文件或命令中做一些事情?請幫忙嗎?我如何運行maven失敗的UI測試用例?
我創建了一個Maven UI測試項目。現在,我作爲mvn測試通過命令運行。但我想重新運行失敗的測試用例。我是否應該在pom文件或命令中做一些事情?請幫忙嗎?我如何運行maven失敗的UI測試用例?
您可以使用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] ------------------------------------------------------------------------