当测试覆盖率验证失败时显示测试报告

时间:2020-01-23 12:29:45

标签: java gradle

我的Gradle版本执行以下操作

  1. 运行测试
  2. 在浏览器中打开测试报告
  3. 在浏览器中打开测试报道
  4. 验证测试覆盖率至少为80%

build.gradle中的相关任务是:

task testWithReports {
  description "Runs all tests, open the coverage and test reports in a browser, and verify the test coverage rules"

  dependsOn 'clean'
  dependsOn 'test'
  dependsOn 'jacocoTestReport'
  dependsOn 'showCoverage'
  dependsOn 'showTestResults'
  dependsOn 'jacocoTestCoverageVerification'
}

jacocoTestReport {
  reports {
    xml.enabled false
    csv.enabled false
    html.destination file("${buildDir}/jacocoHtml")
  }
}

task showCoverage {
  doLast {
    desktop.browse "file:///${buildDir}/jacocoHtml/index.html".toURI()
  }
}

task showTestResults {
  doLast {
    desktop.browse "file:///${buildDir}/junitHtml/index.html".toURI()
  }
}

jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        minimum = 0.8
      }
    }
  }
}

如果我运行testWithReports并且jacocoTestCoverageVerification子任务失败,则不会打开测试报告。有没有一种方法可以定义这些任务,以确保始终打开这些报告?

0 个答案:

没有答案