Gradle Jacoco-找不到方法jacocoTestReport() [英] Gradle Jacoco - Could not find method jacocoTestReport()

查看:568
本文介绍了Gradle Jacoco-找不到方法jacocoTestReport()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Gradle中生成Jacoco测试报告.当我尝试同步我的代码时,我将收到以下错误:

I'm trying to generate a Jacoco test report in Gradle. When I try to sync my code, I will receive the following error:

错误:(56,0)在类型为org.gradle.api.Project的项目':app'上找不到参数[build_38ehqsoyd54r3n3g1ropzso $ _run_closure4 @ 10012308]的方法jacocoTestReport().

Error:(56, 0) Could not find method jacocoTestReport() for arguments [build_38ehqsoyd54r3n1gzrop303so$_run_closure4@10012308] on project ':app' of type org.gradle.api.Project.

我的build.gradle文件包含以下项目:

My build.gradle file contains the following items:

apply plugin: 'jacoco'

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

jacocoTestReport {
    group = "Reporting"
    reports {
        xml.enabled true
        csv.enabled false
        html.destination "${buildDir}/reports/coverage"
    }
}

当我查看文档时,看不到任何我做错了.

When I look at the documentation , I don't see anything which I'm doing wrong.

版本版本:3.3

为什么会收到此错误,我该如何解决?

Why am I receiving this error and how can I fix it?

推荐答案

基本上,我知道两种方法可以实现此目的.

Basically I know two ways to achieve this.

第一种方法是内置的Android gradle插件功能:

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

这将定义可以执行的gradle任务.据我所知,这在仪器测试中效果很好.详细信息: Android上的代码覆盖率

This one will define gradle tasks, which can be executed. As far as I know this works fine with instrumentation tests. More information: Code Coverage on Android

第二种方法是使用此插件:

https://github.com/vanniktech/gradle-android-junit- jacoco插件

设置简单:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
         classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.6.0'
    }
}

apply plugin: 'com.vanniktech.android.junit.jacoco'

项目同步后,您将执行诸如jacocoTestReport<Flavor><BuildType>

And after project sync, you will have tasks like jacocoTestReport<Flavor><BuildType>

我们用它来衡量在本地计算机上运行的单元测试的代码覆盖率.

We use this to measure the code coverage of our unit tests running on the local machine.

这篇关于Gradle Jacoco-找不到方法jacocoTestReport()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆