首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有找到Jacoco

没有找到Jacoco
EN

Stack Overflow用户
提问于 2015-10-09 11:49:39
回答 1查看 10.6K关注 0票数 23

我想在Android应用程序中运行我的测试并创建覆盖报告,所以我在我的build.gradle文件中添加了Jacoco配置,但是它不起作用。

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {

    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    defaultConfig {
        applicationId "mm"
        minSdkVersion 12
        targetSdkVersion 18
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile 'com.google.code.gson:gson:2.1'
    compile files('libs/android-async-http-1.4.4.jar')
    compile files('libs/freemarker.jar')
    compile files('libs/greendao-1.3.1.jar')
    compile files('libs/raygun4android-1.1.0.jar')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    testCompile 'org.mockito:mockito-core:1.10.19'
    testCompile 'org.hamcrest:hamcrest-library:1.3'
    compile 'junit:junit:4.11'

    androidTestCompile('junit:junit:4.11') {
        exclude module: 'hamcrest-core'
    }

}

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
        classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'jacoco'

jacoco {
    version "0.7.1.201405082137"
}


jacoco {
    toolVersion "0.7.1.201405082137"
}

def coverageSourceDirs = [
        'src/main/java',
]

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R*.class',
                       '**/*$InjectAdapter.class',
                       '**/*$ModuleAdapter.class',
                       '**/*$ViewInjector*.class'
            ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files("$buildDir/jacoco/testDebug.exec")
    doFirst {
        new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }
}

我知道,gradle版本1.3.0和1.3.1应该正常工作是有问题的,但是使用1.3.1我得到了Task 'createDebugCoverageReport' not found in root project

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-20 16:20:00

您必须启用testCoverageEnabled

代码语言:javascript
复制
buildTypes {
    debug{
        debuggable true
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        isTestCoverageEnabled true
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        isTestCoverageEnabled true
    }
}
票数 36
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33037537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档