繁体   English   中英

在自定义测试任务定义中使用 Gradle 测试重试插件

[英]Use Gradle test-retry plugin in custom test task definition

我有一个自定义任务定义来运行具有每个测试特殊设置的特定测试文件。 我的任务定义如下所示:

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 中描述的自定义规则成功运行测试

有什么方法可以将测试重试插件与自定义任务定义一起使用吗?

您的任务配置错误。 它应该是:

task retryTest(type: Test) {
    description = 'Dummy Retry Test'
    group = 'verification'
    maxHeapSize = '2048m'
    include '**/*SpecificIntegrationTest.class'
    retry {
        maxRetries = 2
    }
}
task retryTest(type: Test) {
  description = 'Dummy Retry Test'
  group = 'verification'
  maxHeapSize = '2048m'
  include '**/*SpecificIntegrationTest.class'
  reports {
    junitXml {
      mergeReruns = true
    }
  }

  retry {
    maxRetries = 3
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM