生成其他模块的覆盖率 [英] Generate coverage for other modules

查看:130
本文介绍了生成其他模块的覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构如下::app:core. :app是Android应用程序项目,它取决于具有所有业务逻辑的:core.

My project structure is as follows: :app, :core. :app is the Android application project, and it depends on :core which has all the business logic.

我对:appEspresso个测试,由于存在所有问题和指导,我能够运行并获得覆盖率报告.但是覆盖范围仅适用于:app中的代码.

I have Espresso tests for :app, and I am able to run and get coverage report thanks to all the questions and guides out there. But the coverage is only for code in :app.

我如何获得我的Espresso工具测试产生的所有项目(:app:core)的覆盖率?这有可能吗?

How do I get coverage for all projects (:app and :core) resulting from my Espresso instrumentation tests? Is this even possible?

非常感谢您的帮助.

推荐答案

即使您未在问题中提及Jacoco,它也会在标签中列出,因此我假设您想使用它来创建覆盖率报告. Gradle Jacoco插件(apply plugin: 'jacoco')允许您创建JacocoReport类型的自定义任务.

Even if you did not mention Jacoco in your question, it is listed in the tags, so I assume you want to create coverage reports by using it. The Gradle Jacoco plugin (apply plugin: 'jacoco') allows you to create custom tasks of the type JacocoReport.

定义此类任务后,您可以指定源目录和类目录以及执行数据:

Defining such a task, you can specify source and class directories as well as the execution data:

task jacocoTestReport(type: JacocoReport) {
    dependsOn // all your test tasks
    reports {
        xml.enabled = true
        html.enabled = true
    }
    sourceDirectories = // files() or fileTree() to your source files
    classDirectories = // files() or fileTree() to your class files
    executionData = // files() or fileTree() including all your test results
}

对于Espresso测试,执行数据应包括所有生成的.ec文件.您可以在Gradle根项目中定义此任务,并链接到子项目的文件和任务.

For Espresso tests, the execution data should include all generated .ec files. You could define this task in the Gradle root project and link to both the files and the tasks of your subprojects.

存在一个自定义Jacoco报告任务的示例,即使该报告旨在针对多种测试类型创建统一报告,也可以针对该多项目问题进行转移.

There is an example for a custom Jacoco report task, even if it aims on creating an unified report for multiple test types, it can be transfered for this multi-project problem.

这篇关于生成其他模块的覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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