当前位置: 首页 > 软件库 > 手机/移动开发 > >

jacoco-android-gradle-plugin

授权协议 Apache-2.0 License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 吴弘壮
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

jacoco-android-gradle-plugin

A Gradle plugin that adds fully configured JacocoReport tasks for unit tests of each Android application and library project variant.

Why

In order to generate JaCoCo unit test coverage reports for Android projects you need to create JacocoReport tasks and configure them by providing paths to source code, execution data and compiled classes. It can be troublesome since Android projects can have different flavors and build types thus requiring additional paths to be set. This plugin provides those tasks already configured for you.

Usage

buildscript {
  repositories {
    ...
    mavenCentral()
  }
  dependencies {
    ...
    classpath 'com.dicedmelon.gradle:jacoco-android:0.1.5'
  }
}

apply plugin: 'com.android.application'
apply plugin: 'com.dicedmelon.gradle.jacoco-android'

jacoco {
  toolVersion = "0.8.4"
}

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

android {
  ...
  productFlavors {
    free {}
    paid {}
  }
}

The above configuration creates a JacocoReport task for each variant and an additional jacocoTestReport task that runs all of them.

jacocoTestPaidDebugUnitTestReport
jacocoTestFreeDebugUnitTestReport
jacocoTestPaidReleaseUnitTestReport
jacocoTestFreeReleaseUnitTestReport
jacocoTestReport

The plugin excludes Android generated classes from report generation by default. You can use jacocoAndroidUnitTestReport extension to add other exclusion patterns if needed.

jacocoAndroidUnitTestReport {
  excludes += ['**/AutoValue_*.*',
              '**/*JavascriptBridge.class']
}

You can also toggle report generation by type using the extension.

jacocoAndroidUnitTestReport {
  csv.enabled false
  html.enabled true
  xml.enabled true
}

By default your report will be in [root_project]/[project_name]/build/jacoco/But you can change the local reporting directory :

jacocoAndroidUnitTestReport {
  destination "/path/to/the/new/local/directory/"
}

To generate all reports run:

$ ./gradlew jacocoTestReport

Reports for each variant are available at $buildDir/reports/jacoco in separate subdirectories, e.g. build/reports/jacoco/jacocoTestPaidDebugUnitTestReport.

Examples

Snapshot usage

Snapshots of the development version are available in Sonatype Nexus snapshots repository.

buildscript {
  repositories {
    ...
    maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
  }
  dependencies {
    ...
    classpath 'com.dicedmelon.gradle:jacoco-android:x.y.z-SNAPSHOT'
  }
}

License

Copyright 2015-2021 Artur Stępniewski

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
  • 经过多次测试,参考国内外诸多资料。现整理配置如下。 环境: classpath “com.android.tools.build:gradle:7.0.2” ext.kotlin_version = ‘1.6.0’ //jacoco.gradle import org.gradle.api.internal.project.ProjectInternal apply plugin: 'jacoc

  • Gradle 7.4.2 发布 Gradle团队很兴奋地宣布Gradle 7.4.2。 这个版本使得创建单一测试报告或者JaCoCo代码覆盖率报告跨越几个项目。此版本还包括几项可用性改进,例如在IDEA中将附加测试源目录标记为测试和更好地支持子项目中的插件版本声明. Java工具链支持已更新以反映将AdoptOpenJDK迁移到Adoptium. 采用时需要进行一些更改实验配置缓存更容易,随着几个

  • 有谁知道如何为Java Jacoco报告配置一个gradle文件,其中包含多个gradle子模块的代码覆盖率? 我当前的方法仅显示当前子模块的代码覆盖率,而不显示兄弟子模块的代码覆盖率。 我有这个项目结构 - build.gradle (1) - corelib/ - build.gradle (2) - src/main/java/package/Core.java - extlib/ - bu

  • 使用Gradle过滤JaCoCo覆盖报告 问题: 我有一个与jacoco项目,我想能够过滤某些类和/或包。 相关文件: 我已阅读以下文件: 官方的jacoco网站: http : //www.eclemma.org/jacoco/index.html 官方jacoco文档gradle : https : //gradle.org/docs/current/userguide/jacoco_plug

  • 本文的书写已经是很早之前的事情了,只是把从新排版发了出来,有部分内网资源以及找不到了,有兴趣的同学可以根据原理补充上部分缺失的脚本。 覆盖率统计说明 由于这段很重要,特此在最前面的章节说明。 在多项目工程中(dolphin和topnews都是多项目工程),按照本文的方法仅能统计主工程的代码覆盖率,无法统计库工程的代码覆盖率,如需统计库工程的覆盖率请参考在多项目工程中统计子工程的覆盖率 Gradle

 相关资料
  • 其他地方,如这个其他问题,将有一个依赖于testDebug的JacocoTestReport任务。这很有效。 然而,在我的例子中,除了testDebug之外,我还需要依赖android任务compiledbugsources和compiledbugtestsources。所以我希望下面的方法能奏效 但是,当我使用DepsOn属性或方法时,这些依赖项的顺序不能保证Gradle所述的顺序。所以我想在任

  • 我们有一个Android项目,我们使用Powermock进行一些测试用例,使用Jacoco进行覆盖率报告。我们注意到,我们的一些类返回0%覆盖率,尽管它们确实被覆盖。我们还观察了下面关于受影响类的消息。 一些在线搜索显示Powermock和Jacoco玩得不好,离线仪器是一种可能的解决方法。 之前有人使用过android项目的gradle离线插装脚本吗?

  • 我想从JaCoCo中排除一些类别,但排除似乎不起作用。 例如,我想排除所有以Dao结尾的Java类(例如com.company.emplyedao)。 我已经尝试了以下代码,但当我将其推送到sonar/use JacoTestReport时,它仍然显示出来。 我将它与Android结合使用。发生了什么事?

  • 在java项目中,这是非常容易的,在Gradle的示例文件夹中有两个实例。但是当我尝试在android项目中实现时,有很多问题。 当前问题是“找不到方法jacocoTestReport()...Balabala” 任何建议都将得到极大的支持!

  • 我正在尝试在 Gradle 中生成 Jacoco 测试报告。当我尝试同步我的代码时,我将收到以下错误: 错误:(56,0)找不到参数[build_38ehqsoyd54r3n1gzrop303so]的方法jacoTestReport()$_run_closure4@10012308]在项目上:org.gradle.api.project类型的“app”。 我的build.gradle文件包含以下项

  • 我尝试寻找Jacoco离线检测gradle脚本片段,但找不到一个。是否可以通过gradle脚本进行Jacoco离线检测?如果是的话…一个很好的例子。谢谢。