如何防止jacoco仪器仪表生产代码? [英] how to prevent jacoco instrumenting production code?

查看:147
本文介绍了如何防止jacoco仪器仪表生产代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将jacoco插件用于gradle:

i use jacoco plugin for gradle:

apply plugin: 'kotlin'

jacoco {
    toolVersion = "0.7.9"
}
jacocoTestReport {
    reports {
        xml.enabled true
        html.enabled false
        csv.enabled false
    }
}

,然后我要为生产

./gradlew build jacocoTestReport

问题是:jacoco将检测生成的软件包吗?如果是,如何构建未检测到的包装=准备投入生产?并运行代码覆盖率?我必须运行两次构建吗?

the question is: will the generated package be instrumented by jacoco? if yes, how can build package NOT instrumented = ready for production? and having code coverage run? do i have to run build twice? is it impossible to build code once (sign it) and then test it, measure coverage etc and if all checks passes, deploy it?

推荐答案

是不可能一次构建代码(对其进行签名)然后对其进行测试,测量覆盖率等,如果所有检查都通过,则将其部署?

JaCoCo提供了两种执行检测的方式:

JaCoCo provides two ways of performing instrumentation:

  • so-called "on-the-fly" using Java Agent - http://www.jacoco.org/jacoco/trunk/doc/agent.html
  • and so-called "offline" - http://www.jacoco.org/jacoco/trunk/doc/offline.html

区别在于,在第一种情况下,检测会在执行期间在内存中发生,因此不会在磁盘上更改类或jar文件-引用第二个链接

The difference is that in first case instrumentation happens in memory during execution and so no class or jar files will be changed on disk - quoting the second link:


JaCoCo的主要好处之一是Java代理, w即时学习乐器。

One of the main benefits of JaCoCo is the Java agent, which instruments classes on-the-fly. This simplifies code coverage analysis a lot as no pre-instrumentation and classpath tweaking is required.

因此,Java代理带来的简化之一是,大大简化了代码覆盖率分析,因为不需要进行预仪表化和类路径调整。 -正是您不必担心打包或多重构建。与其他Java覆盖工具(例如Cobertura和Clover)相比,这是IMO JaCoCo的优势之一

So one of the simplifications that Java agent brings - is exactly that you don't need to worry about packaging or multiple builds. This is IMO one of the advantages of JaCoCo over other coverage tools for Java such as Cobertura and Clover.

这是强烈建议使用即时检测工具的原因之一-引用 http://www.jacoco.org/jacoco/trunk/doc/cli.html

And this is one of the reasons why it is highly recommended to use on-the-fly instrumentation - quoting http://www.jacoco.org/jacoco/trunk/doc/cli.html :


使用JaCoCo进行代码覆盖率分析的首选方法是使用JaCoCo代理实时进行检测。脱机检测存在一些缺陷,仅在特定情况明确要求使用此模式时才应使用。

the preferred way for code coverage analysis with JaCoCo is on-the-fly instrumentation with the JaCoCo agent. Offline instrumentation has several drawbacks and should only be used if a specific scenario explicitly requires this mode.

此类特定情况之一-是执行在Android上进行测试,因为无法在其上使用Java代理。因此,当被指示使用JaCoCo测量覆盖率时,AFAIK Android Gradle插件 ,使用离线工具,因此需要两种类型的构建-有覆盖且无发布。

One of such specific scenarios - is execution of tests on Android, because there is no way to use Java agent on it. So AFAIK Android Plugin for Gradle, when instructed to measure coverage using JaCoCo, uses offline instrumentation and therefore requires two types of build - with coverage and without for release.

另一方面, JaCoCo Gradle插件,它将JaCoCo集成到Java项目的Gradle中,截止到今天,AFAIK 提供了仅执行即时检测而不能离线执行的功能。

On the other hand JaCoCo Gradle Plugin, which integrates JaCoCo into Gradle for Java projects, AFAIK as of today provides ability to perform only on-the-fly instrumentation and not offline.

这篇关于如何防止jacoco仪器仪表生产代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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