hoc*_*kto 7 java testing surefire maven maven-surefire-plugin
我想重新运行一个我知道会失败的测试,因为我正在尝试测试 Surefire 参数以重新运行失败的测试。我尝试使用这两个命令运行 Maven 它们都没有按预期工作
-Dsurefire.rerunFailingTestsCount=2 -Dtest=TestThatFails test
Run Code Online (Sandbox Code Playgroud)
和
-Dsurefire.rerunFailingTestsCount=2 -Dtest=TestThatFails surefire:test
Run Code Online (Sandbox Code Playgroud)
这是其中的一部分 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>
Run Code Online (Sandbox Code Playgroud)
我原以为 Surefire 会在失败后重新启动测试,但 Maven 只是抛出此错误,我知道如何解决,但我希望重新运行测试。
<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>
Run Code Online (Sandbox Code Playgroud)
小智 13
只是添加到 Wim Rutgeerts 的答案 -rerunFailingTestsCount必须在该configuration部分中,而不是在 中properties,如下所示:
<configuration>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在我maven-surefire-plugin2.19.1 的情况下,它是这样工作的。当它在properties它不工作。
尽管文档中缺少该参数,但该参数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>
Run Code Online (Sandbox Code Playgroud)
请注意,此参数仅适用于 JUnit 4+(这是您的情况,因为您有 JUnit 4.12)。
JUnit 5更新:Maven Surefire 版本3.0.0-M4或更高版本现在允许您使用rerunFailingTestsCount在执行 JUnit 5 测试时使用系统属性。
确保在运行mvn clean阶段时传递以下属性:
-Dsurefire.rerunFailingTestsCount=3
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8433 次 |
| 最近记录: |