因此,我在Eclipse中使用EclEmma来生成XML覆盖率报告。看起来像这样:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

<!DOCTYPE report SYSTEM "report.dtd" PUBLIC "-//JACOCO//DTD Report 1.1//EN">

-<report name="mainTest (1) (Apr 23, 2020 3:48:01 PM)">


-<group name="covTest2">


-<group name="src">


-<package name="covTest2">


-<class name="covTest2/main" sourcefilename="main.java">


-<method name="<init>" line="3" desc="()V">

<counter covered="0" missed="3" type="INSTRUCTION"/>

<counter covered="0" missed="1" type="LINE"/>

<counter covered="0" missed="1" type="COMPLEXITY"/>

<counter covered="0" missed="1" type="METHOD"/>

</method>


-<method name="main" line="5" desc="([Ljava/lang/String;)V">

<counter covered="0" missed="11" type="INSTRUCTION"/>

<counter covered="0" missed="3" type="LINE"/>

<counter covered="0" missed="1" type="COMPLEXITY"/>

<counter covered="0" missed="1" type="METHOD"/>

</method>

<counter covered="0" missed="14" type="INSTRUCTION"/>

<counter covered="0" missed="4" type="LINE"/>

<counter covered="0" missed="2" type="COMPLEXITY"/>

<counter covered="0" missed="2" type="METHOD"/>

<counter covered="0" missed="1" type="CLASS"/>

</class>


-<class name="covTest2/calc" sourcefilename="calc.java">


-<method name="<init>" line="3" desc="()V">

<counter covered="3" missed="0" type="INSTRUCTION"/>

<counter covered="1" missed="0" type="LINE"/>

<counter covered="1" missed="0" type="COMPLEXITY"/>

<counter covered="1" missed="0" type="METHOD"/>

</method>


-<method name="sum" line="5" desc="(II)I">

<counter covered="4" missed="0" type="INSTRUCTION"/>

<counter covered="1" missed="0" type="LINE"/>

<counter covered="1" missed="0" type="COMPLEXITY"/>

<counter covered="1" missed="0" type="METHOD"/>

</method>

<counter covered="7" missed="0" type="INSTRUCTION"/>

<counter covered="2" missed="0" type="LINE"/>

<counter covered="2" missed="0" type="COMPLEXITY"/>

<counter covered="2" missed="0" type="METHOD"/>

<counter covered="1" missed="0" type="CLASS"/>

</class>


-<sourcefile name="main.java">

<line cb="0" mb="0" ci="0" mi="3" nr="3"/>

<line cb="0" mb="0" ci="0" mi="4" nr="5"/>

<line cb="0" mb="0" ci="0" mi="6" nr="6"/>

<line cb="0" mb="0" ci="0" mi="1" nr="7"/>

<counter covered="0" missed="14" type="INSTRUCTION"/>

<counter covered="0" missed="4" type="LINE"/>

<counter covered="0" missed="2" type="COMPLEXITY"/>

<counter covered="0" missed="2" type="METHOD"/>

<counter covered="0" missed="1" type="CLASS"/>

</sourcefile>


-<sourcefile name="calc.java">

<line cb="0" mb="0" ci="3" mi="0" nr="3"/>

<line cb="0" mb="0" ci="4" mi="0" nr="5"/>

<counter covered="7" missed="0" type="INSTRUCTION"/>

<counter covered="2" missed="0" type="LINE"/>

<counter covered="2" missed="0" type="COMPLEXITY"/>

<counter covered="2" missed="0" type="METHOD"/>

<counter covered="1" missed="0" type="CLASS"/>

</sourcefile>

<counter covered="7" missed="14" type="INSTRUCTION"/>

<counter covered="2" missed="4" type="LINE"/>

<counter covered="2" missed="2" type="COMPLEXITY"/>

<counter covered="2" missed="2" type="METHOD"/>

<counter covered="1" missed="1" type="CLASS"/>

</package>


-<package name="TestCase">


-<class name="TestCase/mainTest" sourcefilename="mainTest.java">


-<method name="<init>" line="9" desc="()V">

<counter covered="0" missed="3" type="INSTRUCTION"/>

<counter covered="0" missed="1" type="LINE"/>

<counter covered="0" missed="1" type="COMPLEXITY"/>

<counter covered="0" missed="1" type="METHOD"/>

</method>


-<method name="test" line="13" desc="()V">

<counter covered="0" missed="11" type="INSTRUCTION"/>

<counter covered="0" missed="3" type="LINE"/>

<counter covered="0" missed="1" type="COMPLEXITY"/>

<counter covered="0" missed="1" type="METHOD"/>

</method>

<counter covered="0" missed="14" type="INSTRUCTION"/>

<counter covered="0" missed="4" type="LINE"/>

<counter covered="0" missed="2" type="COMPLEXITY"/>

<counter covered="0" missed="2" type="METHOD"/>

<counter covered="0" missed="1" type="CLASS"/>

</class>


-<sourcefile name="mainTest.java">

<line cb="0" mb="0" ci="0" mi="3" nr="9"/>

<line cb="0" mb="0" ci="0" mi="4" nr="13"/>

<line cb="0" mb="0" ci="0" mi="6" nr="14"/>

<line cb="0" mb="0" ci="0" mi="1" nr="16"/>

<counter covered="0" missed="14" type="INSTRUCTION"/>

<counter covered="0" missed="4" type="LINE"/>

<counter covered="0" missed="2" type="COMPLEXITY"/>

<counter covered="0" missed="2" type="METHOD"/>

<counter covered="0" missed="1" type="CLASS"/>

</sourcefile>

<counter covered="0" missed="14" type="INSTRUCTION"/>

<counter covered="0" missed="4" type="LINE"/>

<counter covered="0" missed="2" type="COMPLEXITY"/>

<counter covered="0" missed="2" type="METHOD"/>

<counter covered="0" missed="1" type="CLASS"/>

</package>

<counter covered="7" missed="28" type="INSTRUCTION"/>

<counter covered="2" missed="8" type="LINE"/>

<counter covered="2" missed="4" type="COMPLEXITY"/>

<counter covered="2" missed="4" type="METHOD"/>

<counter covered="1" missed="2" type="CLASS"/>

</group>

<counter covered="7" missed="28" type="INSTRUCTION"/>

<counter covered="2" missed="8" type="LINE"/>

<counter covered="2" missed="4" type="COMPLEXITY"/>

<counter covered="2" missed="4" type="METHOD"/>

<counter covered="1" missed="2" type="CLASS"/>

</group>

<counter covered="7" missed="28" type="INSTRUCTION"/>

<counter covered="2" missed="8" type="LINE"/>

<counter covered="2" missed="4" type="COMPLEXITY"/>

<counter covered="2" missed="4" type="METHOD"/>

<counter covered="1" missed="2" type="CLASS"/>

</report>


在此文件中,它显示了一个测试“ mainTest”,我想知道的是“ mainTest”文件涵盖了哪些文件,以及“ mainTest”测试所覆盖的文件中有多少%。如果ECLEmma不起作用,欢迎提供其他可以达到此目的的工具的提示:)

最佳答案

您可以使用“ includes”参数来指定要在报告中使用的类。请参阅此处的文档:

https://www.eclemma.org/jacoco/trunk/doc/report-mojo.html

还有许多其他代码覆盖工具可用,选择要包含的测试将是一个常见的选择。此处提供示例列表:

https://en.wikipedia.org/wiki/Java_code_coverage_tools

10-06 02:18