简体   繁体   English

如何在Android中自定义Jacoco for Espresso测试

[英]How to customize Jacoco for Espresso tests in Android

I have a library project with some weird configuration between modules. 我有一个库项目,模块之间有一些奇怪的配置。 Due to some specific restrictions, I have now 3 module: core (main module), core-test (where my unit tests are) and a core-app (where my Espresso tests are). 由于一些特定的限制,我现在有3个模块: 核心 (主模块), 核心测试 (我的单元测试)和核心应用程序 (我的Espresso测试)。

At this time, I need to generate a coverage report to make it available on out CI server. 此时,我需要生成一个覆盖率报告,以使其在CI服务器上可用。 Using properties such additionalSourceDirs and additionalClassDirs , I created a custom task for enabling the core classes to be shown in the resulting jacoco.exec file. 使用additionalSourceDirsadditionalClassDirs等属性,我创建了一个自定义任务,用于使核心类显示在生成的jacoco.exec文件中。 But for the Espresso tests, I am not able to find a way to customize this, as the jacoco configuration node on Android Gradle plugin seems to have no options for anything . 但是对于Espresso测试,我无法找到一种方法来定制它,因为Android Gradle插件上的jacoco配置节点似乎没有任何选项 Enabling testCoverageEnabled for a specific build configuration works, it generates the coverage, but only for the classes in core-app (I know, in a regular project, this is the expected behavior), so the coverage.ec file doesn't have the execution data for my other classes. 为特定的构建配置启用testCoverageEnabled有效,它会生成覆盖范围,但仅适用于core-app中的类(我知道,在常规项目中,这是预期的行为),因此coverage.ec文件没有我的其他课程的执行数据。

Anyone knows a way to add more classes / sources to the coverage task for integration tests? 任何人都知道为集成测试添加更多类/源到coverage任务的方法吗? (maybe extending AndroidJUnitRunner in some way or changing the task itself through Groovy?) (可能以某种方式扩展AndroidJUnitRunner或通过Groovy更改任务本身?)

You need to add the following in your build.gradle: 您需要在build.gradle中添加以下内容:

apply plugin: 'jacoco'
jacoco {
    toolVersion "0.7.5.201505241946"
}

Also in buildTypes: 同样在buildTypes中:

debug {
    testCoverageEnabled = true

Run

gradle tasks 

and you will see a task called (If you are using debug build for coverage) 并且您将看到一个名为的任务(如果您正在使用调试版本进行覆盖)

createDebugCoverageReport

Run

gradle createDebugCoverageReport

You will see coverage.ec in the following folder 您将在以下文件夹中看到coverage.ec

$build_dir/outputs/code-coverage/connected/flavors/debug/coverage.ec

Which device you are using and which OS ? 您使用的是哪种设备以及哪种操作系统? Some device with a particular OS produces empty coverage.ec Please share more information about OS and device you are using? 某些具有特定操作系统的设备会产生空白覆盖。请分享有关您正在使用的操作系统和设备的更多信息?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM