如何添加注释以从jacoco代码覆盖率报告中排除方法? [英] How would I add an annotation to exclude a method from a jacoco code coverage report?

查看:1517
本文介绍了如何添加注释以从jacoco代码覆盖率报告中排除方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Java代码,我想从代码覆盖中排除。我该怎么办?我希望能够添加注释。有没有办法配置或扩展jacoco(在gradle中使用)来使用它?

I have some code in Java that I want to exclude from code coverage. How would I do this? I want to be able to add an annotation. Is there a way to configure or extend jacoco (as used in gradle) to use this?

示例:

public class Something
{
    @ExcludeFromCodeCoverage
    public void someMethod() {}
}


推荐答案


我有一些Java代码,我想从代码覆盖中排除。我该怎么办?我希望能够添加注释。有没有办法配置或扩展jacoco(在gradle中使用)来使用它?

I have some code in Java that I want to exclude from code coverage. How would I do this? I want to be able to add an annotation. Is there a way to configure or extend jacoco (as used in gradle) to use this?

截至今天还没有这样的功能在最新发布的JaCoCo版本中( 0.7.9 )。只能排除整个班级。

As of today there is no such feature in latest released version of JaCoCo (0.7.9). Only whole classes can be excluded.

页面 https://github.com/jacoco/jacoco/wiki/FilteringOptions#annotation-based-filtering (专用于开发人员)这被记录为未来版本的想法。

On page https://github.com/jacoco/jacoco/wiki/FilteringOptions#annotation-based-filtering (which is dedicated for developers) this is recorded as an idea for future versions.

JaCoCo官方文档包含有关如何获取最新未发布版本以及下一版本未发布更改列表的信息 - http://www.jacoco.org/jacoco/trunk/doc/changes.html ,其中包括各种过滤器,其中过滤由Lombok和Groovy生成并由注释标记的方法 lombok.Generated groovy.transform.Generated 分别。可能你可以滥用这个,但我不建议这样做有很多种原因。

Official JaCoCo documentation contains information about how to obtain latest unreleased build as well as list of unreleased changes for next version - http://www.jacoco.org/jacoco/trunk/doc/changes.html , which includes various filters, among which filtering of methods that are generated by Lombok and Groovy and marked by annotations lombok.Generated and groovy.transform.Generated respectively. Potentially you can abuse this, but I wouldn't recommend to do so for many various reasons.

这篇关于如何添加注释以从jacoco代码覆盖率报告中排除方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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