Jacoco Filtering options

531 views
Skip to first unread message

peter_...@web.de

unread,
Jan 11, 2018, 9:05:10 AM1/11/18
to JaCoCo and EclEmma Users
Hi,

1) We have a problem with the following construct:

public final int getId() {
int retValue = -1;
switch (getDevice()) {
case MIREL1:
retValue = 1;
break;
case MIREL2:
retValue = 2;
break;
default:
getMyTestScript().error("Invalid device!");
break;
}
return retValue;
}

All 3 branches are covered, but "switch getDevice()" is marked yellow. On internet i found the info, that getId() can return null and then a Exception is thrown.
I generated a 4.th test case via mocking getId() to null. Then a nullptrexception is thrown, i tested this in the unit-test, but Jacoco always marks the row "switch getDevice()" yellow and the static coverage is not 100%.
How can we solve this problem?

2) On the page https://github.com/jacoco/jacoco/wiki/FilteringOptions Jacoco filtering options are described.

I want to use JAVAC.ENUM to suppress coverage of values() and valueOf().
On the side above there is the following statement: "This page discusses a not yet available feature!", but behind the option JAVAC.ENUM there is the remark "Done".

Is this feature already implemented in Jacoco? If it is available, in which version is it implemented and how can i set the filtering option in the following ANT-script:

<target name="instrument" depends="test-compile">
<!-- Step 2: Instrument class files -->
<jacoco:instrument destdir="${result.classes.instr.dir}">
<fileset dir="${result.classes.dir}" />
</jacoco:instrument>
</target>

<target name="unittestall" depends="instrument">
<junit printsummary="yes" haltonfailure="no" fork="true">
<sysproperty key="jacoco-agent.destfile" file="${result.exec.file}"/>
<classpath refid="Plug-in Dependencies.libraryclasspath"/>
<classpath refid="classpath.tools"/>
<classpath refid="classpath.instr"/>
<classpath refid="classpath.test"/>
<batchtest fork="yes">
<fileset dir="${test.dir}" includes="**/*Test.java" />
<formatter type="plain"/>
<formatter type="xml"/>
</batchtest>
</junit>
</target>

<target name="unittestreport" depends="unittestall">
<mkdir dir="${report.dir}/html"/>
<junitreport todir="${report.dir}">
<fileset dir="${xml.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${report.dir}/html"/>
</junitreport>
</target>

<target name="report" depends="unittestreport">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>

<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>

<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>

<target name="rebuild" depends="clean, compile, test-compile, instrument, unittest, unittestreport, report" />

</project>

Evgeny Mandrikov

unread,
Jan 11, 2018, 3:43:57 PM1/11/18
to JaCoCo and EclEmma Users
Hi Peter,

On Thursday, January 11, 2018 at 3:05:10 PM UTC+1, peter_...@web.de wrote:
 
2) On the page https://github.com/jacoco/jacoco/wiki/FilteringOptions Jacoco filtering options are described.
I want to use JAVAC.ENUM to suppress coverage of values() and valueOf().
On the side above there is the following statement: "This page discusses a not yet available feature!", but behind the option JAVAC.ENUM there is the remark "Done".
Is this feature already implemented in Jacoco? If it is available, in which version is it implemented and how can i set the filtering option in the following ANT-script:

As of today latest released JaCoCo version 0.8.0 includes all filters that are marked on mentioned page as "done".
No special activation/configuration is required - just use version 0.8.0.

wiki is primarly used by JaCoCo developers to analyze and design new features, user documentation as always located at http://www.jacoco.org/jacoco/ , and includes full change log - http://www.jacoco.org/jacoco/trunk/doc/changes.html

 

1) We have a problem with the following construct:

 public final int getId() {
        int retValue = -1;
        switch (getDevice()) {
            case MIREL1:
                retValue = 1;
                break;
            case MIREL2:
                retValue = 2;
                break;
            default:
                getMyTestScript().error("Invalid device!");
                break;
        }
        return retValue;
    }

All 3 branches are covered, but "switch getDevice()" is marked yellow. On internet i found the info, that getId() can return null and then a Exception is thrown.

 

I generated a 4.th test case via mocking getId() to null.


"int getId()" can't return null ;)
 

Then a nullptrexception is thrown, i tested this in the unit-test, but Jacoco always marks the row "switch getDevice()" yellow and the static coverage is not 100%.
How can we solve this problem?


Not even counting the above about int and null, in absence of complete executable example hard to understand what you're trying to describe - no explanation of "getDevice" / "MIREL1" / "getMyTestScript().error" / etc, tests not shown, no even screenshot of report.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages