簡體   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