kotlinx-kover
kotlinx-kover copied to clipboard
Support for CoverageUnit METHOD
It would be nice to be able to verify the method % coverage shown in the report.
We currently verify on 90% instructions per class, but we always want to cover 100% of the methods, which is currently not possible as far as i understand the documentation regarding verification rules.
Hi! Are there any known workarounds on how to extract the method-level coverage info from the reports?
@egor-bogomolov, hi You can generate an XML report, parse it and count the methods that are not covered.
the XML path to the method report/package/class/method
e.g.
<report name="debug">
<package name="com/example">
<class name="com/example/Foo">
<method name="<init>" desc="()V" line="8">
<counter type="INSTRUCTION" missed="3" covered="0"/>
<counter type="LINE" missed="1" covered="0"/>
<counter type="COMPLEXITY" missed="1" covered="0"/>
<counter type="METHOD" missed="1" covered="0"/>
</method>
<method name="exists" desc="()Ljava/lang/Boolean;" line="11">
<counter type="INSTRUCTION" missed="1" covered="10"/>
<counter type="BRANCH" missed="1" covered="1"/>
<counter type="LINE" missed="1" covered="3"/>
<counter type="COMPLEXITY" missed="1" covered="1"/>
<counter type="METHOD" missed="0" covered="1"/>
</method>
<method name="delete" desc="()V" line="11">
<counter type="INSTRUCTION" missed="0" covered="15"/>
<counter type="BRANCH" missed="0" covered="1"/>
<counter type="LINE" missed="0" covered="3"/>
<counter type="COMPLEXITY" missed="1" covered="1"/>
<counter type="METHOD" missed="0" covered="1"/>
</method>
</class>
</package>
Depending on which coverage metric you choose, you can count in different ways: for example, if all rows in the method are not covered ( covered="0" for type="LINE" ), then consider this method uncovered, otherwise consider it covered