【发布时间】:2015-12-28 21:02:47
【问题描述】:
有一个配置值rerunFailingTestsCount,但我想以可配置的次数运行测试方法,即使它成功了。有什么选择吗?
【问题讨论】:
标签: java maven-3 junit4 maven-plugin surefire
有一个配置值rerunFailingTestsCount,但我想以可配置的次数运行测试方法,即使它成功了。有什么选择吗?
【问题讨论】:
标签: java maven-3 junit4 maven-plugin surefire
我认为不可能配置maven-surefire-plugin 重新运行通过的测试。
但是,您可以使用 TestNG(不是 JUnit)@Test 注释来配置单个测试的调用计数:
@Test(invocationCount = 5)
public void testSomething() {
}
这将导致 testSomething 方法被测试 5 次。
如果不想走TestNG路线,可以参考this answerJUnit的解决方案。
【讨论】:
如果你想通过实现 IInvokedMethodListener beforeInvocation 方法来配置它,那么大意是:
method.getTestMethod().setInvocationCount(Integer.parseInt(System.getProperty("configurablecount")));
System.getProperty 可以替换为您想要配置的任何内容。您还可以通过传递测试名称来控制哪些测试来设置调用计数来更改。
【讨论】:
是的
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>phase-1</id>
<phase>test</phase>
<configuration>
<skip>false</skip>
<!-- Phase 1 configuration -->
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
<execution>
<id>phase-2</id>
<phase>test</phase>
<configuration>
<skip>false</skip>
<!-- Phase 2 configuration -->
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
【讨论】: