如何从jacoco代码覆盖率中排除一行? [英] How to exclude a line from jacoco code coverage?

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

问题描述

我如何在pom.xml或Java代码中的jacoco代码覆盖范围内排除 inputStream.close()?

How would i exclude inputStream.close() from jacoco code coverage, in pom.xml or in the java code?

public void run() {
    InputStream inputStream = null;
    try {
        inputStream = fileSystem.newFileInputStream(file);
    }
    finally {
        if(inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {}
        }
    }
}

推荐答案

到目前为止,尚不能排除特定行(请参见

As for now, there's no ability to exclude a specific line (see the link):

到目前为止,JaCoCo Core仅适用于类文件,没有源处理.这将需要对体系结构进行重大修改,并增加其他配置麻烦.

As of today JaCoCo core only works on class files, there is no source processing. This would require a major rework of the architecture and adds additional configuration hassles.

这意味着,Jacoco分析了程序的字节代码,而不是源代码,其结果是

It means, Jacoco analyzes byte code of your program, not your sources, as the result it cannot use hints like comments.

按照相应的问题来跟踪此类功能实现的状态.

Follow the corresponding issue to track the status of such feature implementation.

作为一种解决方法,您可以将其放入单独的方法中,但是请注意,当您更改代码以使其达到100%覆盖级别时,这是一种难闻的气味.

As a workaround you can put it into a separate method, but see, it's a bad smell when you change your code just to reach 100% coverage level.

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

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