java - 在自定义测试任务定义中使用 Gradle 测试重试插件
问题描述
我有一个自定义任务定义来运行每个测试具有特殊设置的特定测试文件。我的任务定义如下所示:
task retryTest(type: Test) {
description = 'Dummy Retry Test'
group = 'verification'
maxHeapSize = '2048m'
include '**/*SpecificIntegrationTest.class'
}
现在,此设置中的一些测试很不稳定,我尝试像这样再次重新运行它们:
plugins {
id "org.gradle.test-retry" version "1.1.1"
}
task retryTest(type: Test) {
description = 'Dummy Retry Test'
group = 'verification'
maxHeapSize = '2048m'
include '**/*SpecificIntegrationTest.class'
test {
retry {
maxRetries = 2
}
}
}
我写了一个测试类,第一次总是失败,第二次成功:
public class RetryTest {
private int execCount = 0;
@Test
public void throwException() {
if (execCount == 0) {
execCount++;
throw new NotImplementedException();
}
}
}
不幸的是,测试只执行一次,整个测试套件都失败了。我可以使用https://stackoverflow.com/a/55178053/6059889中描述的自定义规则成功运行测试
有什么方法可以将 test-retry 插件与自定义任务定义一起使用?
解决方案
您的任务配置错误。它应该是:
task retryTest(type: Test) {
description = 'Dummy Retry Test'
group = 'verification'
maxHeapSize = '2048m'
include '**/*SpecificIntegrationTest.class'
retry {
maxRetries = 2
}
}
推荐阅读
- android - 找不到@Bindable 属性
- reactjs - 如何在 registerBlockType 上的编辑和保存函数中获取块唯一 ID
- php - 允许用户传递方法名称和参数时, call_user_func_array 是否存在安全风险?
- c++ - 奇怪的解析行为 _Atomic 与模板
- flutter - 解码图像并添加到小部件列表 [flutter]
- php - Laravel - 碳 addDays()
- php - 返回所需文件中的对象并引用它
- reactjs - 无法用浅层和酶测试 onChange 模拟方法
- sql - PLSQL Oracle 触发器,按 id 对行中的金额求和
- php - 如何将存储中的文件附加到邮件 - laravel 6