安卓+ JaCoCo:jacocoTestCoverageVerification 永远不会失败
我正在尝试配置一个新的 Android 项目以使用 JaCoCo 进行测试覆盖率,但当覆盖率低于某个阈值时会失败。我使用过 此文档,并查看了许多 SO 帖子。我预计任务会失败,因为我没有测试覆盖率,但它成功了,没有任何警告。
我的 :app build.gradle 文件包含以下内容:
plugins {
...
id 'jacoco'
}
jacoco {
toolVersion = "0.8.7"
reportsDirectory = layout.buildDirectory.dir('app/build/reports')
}
task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: ['jacocoTestReport']) {
onlyIf = { true }
violationRules {
failOnViolation = true
rule {
limit {
minimum = 1.0
}
}
}
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
finalizedBy jacocoTestCoverageVerification
onlyIf = {true}
reports {
xml.enabled true
html.enabled true
html.outputLocation = layout.buildDirectory.dir('app/build/reports')
}
}
tasks.withType(Test) {
finalizedBy jacocoTestReport
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
android {
...
jacoco{
version = "0.8.7"
}
}
当我尝试运行测试时,使用以下任何一项:
./gradlew test
./gradlew jacocoTestReport
./gradlew jacocoTestCoverageVerification
结果始终相同:
...
> Task :app:connectedDebugAndroidTest
Starting 2 tests on Nexus 5X - 8.1.0
> Task :app:createDebugAndroidTestCoverageReport
> Task :app:createDebugCoverageReport
> Task :app:jacocoTestReport
> Task :app:jacocoTestCoverageVerification
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 31s
93 actionable tasks: 93 executed
Build Analyzer results available
1:10:48 PM: Task execution finished 'test'.
我预计任务会失败,因为我没有测试覆盖率。我添加了一个实用程序类和方法,并部分实现了一个测试,以便 JaCoCo 报告显示一个类的覆盖率为 60%,但这并没有改变任何东西。
I am trying to configure a new Android project to use JaCoCo for test coverage and fail when coverage is below a certain threshold. I have used this documentation, as well as looking at many SO posts. I expect the task to fail, since I don't have test coverage, but it succeeds without any warnings.
My :app build.gradle file includes the following:
plugins {
...
id 'jacoco'
}
jacoco {
toolVersion = "0.8.7"
reportsDirectory = layout.buildDirectory.dir('app/build/reports')
}
task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: ['jacocoTestReport']) {
onlyIf = { true }
violationRules {
failOnViolation = true
rule {
limit {
minimum = 1.0
}
}
}
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
finalizedBy jacocoTestCoverageVerification
onlyIf = {true}
reports {
xml.enabled true
html.enabled true
html.outputLocation = layout.buildDirectory.dir('app/build/reports')
}
}
tasks.withType(Test) {
finalizedBy jacocoTestReport
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
android {
...
jacoco{
version = "0.8.7"
}
}
When I try to run tests, using any of the following:
./gradlew test
./gradlew jacocoTestReport
./gradlew jacocoTestCoverageVerification
The results are always the same:
...
> Task :app:connectedDebugAndroidTest
Starting 2 tests on Nexus 5X - 8.1.0
> Task :app:createDebugAndroidTestCoverageReport
> Task :app:createDebugCoverageReport
> Task :app:jacocoTestReport
> Task :app:jacocoTestCoverageVerification
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 31s
93 actionable tasks: 93 executed
Build Analyzer results available
1:10:48 PM: Task execution finished 'test'.
I expect the task to fail, since I have no test coverage. I have added a utility class and method, and partially implemented a test so that the JaCoCo report shows 60% coverage for one class, but this has not changed anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论