Android+JaCoCo:jacocoTestCoverageVerificationneverfails
创始人
2024-08-19 15:30:16
0

在build.gradle文件中添加以下代码:

android {
    ...
    buildTypes {
        debug {
            testCoverageEnabled true
        }
    }
}

dependencies {
    ...
    androidTestImplementation('org.jacoco:org.jacoco.agent:0.8.7') {
        // JaCoCo version might need to be changed to match the version
        // used in other places (e.g. SonarQube)
        exclude group: 'org.slf4j', module: 'slf4j-android'
    }
}

jacoco {
    toolVersion "0.8.7"
    reportsDir file("$buildDir/reports")
}

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
}

task jacocoTestCoverageVerification(type: JacocoCoverageVerification) {
    dependsOn 'testDebugUnitTest'
    sourceDirectories.setFrom(files(android.sourceSets.debug.java.srcDirs))
    classDirectories.setFrom(files("${buildDir}/intermediates/classes/debug"))
    // Change minimum coverage percentage as desired
    violationRules {
        rule {
            limit {
                minimum = 0.8
            }
        }
    }
}

注意:这个解决方法假设你使用的是JUnit和Robolectric进行单元测试,而不是Espresso进行UI测试。如果你使用Espresso,则应调整jacocoTestCoverageVerification任务中的依赖项。

最后,运行以下命令来运行Jacoco测试覆盖率验证任务:

./gradlew jacocoTestCoverageVerification

相关内容

热门资讯

透视游戏!aapoker透视怎... 透视游戏!aapoker透视怎么用(透视)脚本(原来是真的有挂)1)aapoker透视怎么用辅助挂:...
透视脚本!aa poker辅助... 透视脚本!aa poker辅助(透视)透视脚本下载(真是真的是有挂);1、首先打开aa poker辅...
透视计算!aapoker能控制... 透视计算!aapoker能控制牌吗(透视)辅助(真是是有挂);1、下载好aapoker能控制牌吗辅助...
透视玄学!aapoker脚本怎... 透视玄学!aapoker脚本怎么用(透视)ai插件(一贯真的是有挂);该软件可以轻松地帮助玩家将aa...
透视新版!aapoker辅助插... 透视新版!aapoker辅助插件工具(透视)透视脚本(总是是有挂)1、每一步都需要思考,不同水平的挑...
透视游戏!aa poker辅助... 透视游戏!aa poker辅助(透视)透视软件(真是是真的有挂)1、进入到aa poker辅助黑科技...
透视科技!aapoker真的假... 透视科技!aapoker真的假的(透视)ai插件(本来真的有挂)1、完成aapoker真的假的透视辅...
透视辅助!aapoker如何设... 透视辅助!aapoker如何设置胜率(透视)透视插件(本来是真的有挂);1、进入游戏-大厅左侧-新手...
透视中牌率!aapoker透视... 透视中牌率!aapoker透视方法(透视)透视脚本(切实是有挂);1、完成aapoker透视方法透视...
透视系统!aapoker脚本怎... 透视系统!aapoker脚本怎么用(透视)透视脚本下载(确实存在有挂)1、进入游戏-大厅左侧-新手福...