kotlinx-kover icon indicating copy to clipboard operation
kotlinx-kover copied to clipboard

Support for CoverageUnit METHOD

Open sLite opened this issue 1 year ago • 2 comments

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.

sLite avatar Oct 31 '24 01:10 sLite

Hi! Are there any known workarounds on how to extract the method-level coverage info from the reports?

egor-bogomolov avatar Nov 26 '24 16:11 egor-bogomolov

@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="&lt;init&gt;" 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

shanshin avatar Nov 26 '24 21:11 shanshin