在自定义测试任务定义中使用Gradle test-retry插件

时间:2020-02-27 10:45:52

标签: java gradle junit

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

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插件?

2 个答案:

答案 0 :(得分:1)

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

0x16fa53000 +[MICodeSigningVerifier _validateSignatureAndCopyInfoForURL:withOptions:error:]: 77: Failed to verify code signature of /var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.dABVKh/extracted/Your.app/Frameworks/xxx.framework : 0xe8008001 (An unknown error has occurred.)
0x16fa53000 -[MIInstaller performInstallationWithError:]: Verification stage failed

答案 1 :(得分:0)

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

  retry {
    maxRetries = 3
  }
}