没有“ androidTest”文件夹的Android Jacoco

时间:2019-03-12 12:03:19

标签: android robolectric jacoco gradlew

目前,我仅在RoboElectric 4.2和Android X和Android SDK 28中使用“测试”文件夹

然后我触发

之类的任务
.\gradlew :app:createDevDebugCoverageReport

然后我看到正确创建的文件夹像app\build\reports\coverage\dev\debug

但是,当我打开index.html时,所有承保范围仅为0

我正在使用dagger butterknife mockito powermock,覆盖范围肯定是80%+

我想念任何人的建议。

下面是我的项目级别gradle的简化版本

    ......
    ......

    dependencies {
    classpath 'com.android.tools.build:gradle:3.3.2'
    classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
    classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.0.1622'
    classpath 'com.google.gms:google-services:4.2.0'
    classpath 'org.jacoco:org.jacoco.core:0.8.2'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files

    ......
    ......

下面是我的应用级别gradle的简化版本

apply plugin: 'com.android.application'
apply plugin: 'org.sonarqube'
apply plugin: 'jacoco'
apply plugin: 'spoon'
apply plugin: 'com.google.gms.google-services'
.....
.....
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
flavorDimensions "default"
testOptions.unitTests.includeAndroidResources = true
.....
.....
buildTypes {
    debug{
        debuggable true
        minifyEnabled false
        testCoverageEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
....
....
productFlavors {
   dev {
   ......
   ......
   uat {
   ......
   .....
   prod {
   .....
   .....
testOptions {
    animationsDisabled true
    unitTests {
        returnDefaultValues true
        includeAndroidResources = true
    }
......
......
task testJacoco(type: JacocoReport, dependsOn: ["testDevDebugUnitTest", "createDevDebugCoverageReport"]) {
    executionData(file("build/jacoco/testDevDebugUnitTest.exec"))
    sourceDirectories = files("src/main/java")
    classDirectories = files("build/intermediates/javac/debug/compileDebugJavaWithJavac/classes")
}

......
......

0 个答案:

没有答案