我在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.orgjacocotrunkdocreport-mojo.html
还有很多其他的代码覆盖工具,选择你想包含的测试是一个常见的选项。 这里提供了样本列表。