How to exclude a line from jacoco code coverage?

nommer :

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) {}
        }
    }
}
GoodDok :

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

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.

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.

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=465680&siteId=1