我创建了一个maven UI测试项目。现在,我通过命令运行mvn test。但我想重新运行失败的测试用例。我应该在pom文件中还是通过命令执行某些操作?有什么帮助吗?
答案 0 :(得分: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] ------------------------------------------------------------------------