我正在使用OpenCover来计算代码覆盖率,我得到以下xml响应。
<CoverageSession xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Modules>
<Module hash="FD-FE-41-D9-AB-19-E3-F2-D4-3A-E6-27-3D-30-A5-CC-E1-13-AC-C1">
<FullName>D:DEMOTestProjectbinDebugTestProject.dll</FullName>
<ModuleName>TestProject</ModuleName>
<Files>
<File uid="1" fullPath="D:DemoTestProjectMathFunctionsTest.cs" />
</Files>
<Classes>
<Class>
<FullName><Module></FullName>
<Methods />
</Class>
<Class>
<FullName>TestProject.MathFunctionsTest</FullName>
<Methods>
<Method visited="false" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="false" isStatic="false" isGetter="true" isSetter="false">
<MetadataToken>100663297</MetadataToken>
<Name>Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestProject.MathFunctionsTest::get_TestContext()</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="0" uspid="1" ordinal="0" offset="0" sl="27" sc="13" el="27" ec="14" />
<SequencePoint vc="0" uspid="2" ordinal="1" offset="1" sl="28" sc="17" el="28" ec="44" />
<SequencePoint vc="0" uspid="3" ordinal="2" offset="10" sl="29" sc="13" el="29" ec="14" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="0" uspid="1" ordinal="0" offset="0" sl="27" sc="13" el="27" ec="14" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="true">
<MetadataToken>100663298</MetadataToken>
<Name>System.Void TestProject.MathFunctionsTest::set_TestContext(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext)</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="5" uspid="4" ordinal="0" offset="0" sl="31" sc="13" el="31" ec="14" />
<SequencePoint vc="5" uspid="5" ordinal="1" offset="1" sl="32" sc="17" el="32" ec="45" />
<SequencePoint vc="5" uspid="6" ordinal="2" offset="8" sl="33" sc="13" el="33" ec="14" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="5" uspid="4" ordinal="0" offset="0" sl="31" sc="13" el="31" ec="14" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663299</MetadataToken>
<Name>System.Void TestProject.MathFunctionsTest::MathFunctionsConstructorTest()</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="1" uspid="7" ordinal="0" offset="0" sl="72" sc="9" el="72" ec="10" />
<SequencePoint vc="1" uspid="8" ordinal="1" offset="1" sl="73" sc="13" el="73" ec="56" />
<SequencePoint vc="1" uspid="9" ordinal="2" offset="7" sl="75" sc="9" el="75" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="7" ordinal="0" offset="0" sl="72" sc="9" el="72" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663300</MetadataToken>
<Name>System.Void TestProject.MathFunctionsTest::AddTest()</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="1" uspid="10" ordinal="0" offset="0" sl="82" sc="9" el="82" ec="10" />
<SequencePoint vc="1" uspid="11" ordinal="1" offset="1" sl="83" sc="13" el="83" ec="56" />
<SequencePoint vc="1" uspid="12" ordinal="2" offset="7" sl="84" sc="13" el="84" ec="27" />
<SequencePoint vc="1" uspid="13" ordinal="3" offset="17" sl="85" sc="13" el="85" ec="27" />
<SequencePoint vc="1" uspid="14" ordinal="4" offset="27" sl="86" sc="13" el="86" ec="34" />
<SequencePoint vc="1" uspid="15" ordinal="5" offset="37" sl="88" sc="13" el="88" ec="39" />
<SequencePoint vc="1" uspid="16" ordinal="6" offset="47" sl="89" sc="13" el="89" ec="47" />
<SequencePoint vc="1" uspid="17" ordinal="7" offset="56" sl="91" sc="9" el="91" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="10" ordinal="0" offset="0" sl="82" sc="9" el="82" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663301</MetadataToken>
<Name>System.Void TestProject.MathFunctionsTest::DivideTest()</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="1" uspid="18" ordinal="0" offset="0" sl="98" sc="9" el="98" ec="10" />
<SequencePoint vc="1" uspid="19" ordinal="1" offset="1" sl="99" sc="13" el="99" ec="56" />
<SequencePoint vc="1" uspid="20" ordinal="2" offset="7" sl="100" sc="13" el="100" ec="28" />
<SequencePoint vc="1" uspid="21" ordinal="3" offset="17" sl="101" sc="13" el="101" ec="28" />
<SequencePoint vc="1" uspid="22" ordinal="4" offset="27" sl="102" sc="13" el="102" ec="34" />
<SequencePoint vc="1" uspid="23" ordinal="5" offset="37" sl="104" sc="13" el="104" ec="42" />
<SequencePoint vc="1" uspid="24" ordinal="6" offset="47" sl="105" sc="13" el="105" ec="47" />
<SequencePoint vc="1" uspid="25" ordinal="7" offset="56" sl="107" sc="9" el="107" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="18" ordinal="0" offset="0" sl="98" sc="9" el="98" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663302</MetadataToken>
<Name>System.Void TestProject.MathFunctionsTest::MultiplyTest()</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="1" uspid="26" ordinal="0" offset="0" sl="114" sc="9" el="114" ec="10" />
<SequencePoint vc="1" uspid="27" ordinal="1" offset="1" sl="115" sc="13" el="115" ec="56" />
<SequencePoint vc="1" uspid="28" ordinal="2" offset="7" sl="116" sc="13" el="116" ec="27" />
<SequencePoint vc="1" uspid="29" ordinal="3" offset="17" sl="117" sc="13" el="117" ec="27" />
<SequencePoint vc="1" uspid="30" ordinal="4" offset="27" sl="118" sc="13" el="118" ec="34" />
<SequencePoint vc="1" uspid="31" ordinal="5" offset="37" sl="120" sc="13" el="120" ec="44" />
<SequencePoint vc="1" uspid="32" ordinal="6" offset="47" sl="121" sc="13" el="121" ec="47" />
<SequencePoint vc="1" uspid="33" ordinal="7" offset="56" sl="123" sc="9" el="123" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="26" ordinal="0" offset="0" sl="114" sc="9" el="114" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663303</MetadataToken>
<Name>System.Void TestProject.MathFunctionsTest::SubtractTest()</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="1" uspid="34" ordinal="0" offset="0" sl="130" sc="9" el="130" ec="10" />
<SequencePoint vc="1" uspid="35" ordinal="1" offset="1" sl="131" sc="13" el="131" ec="56" />
<SequencePoint vc="1" uspid="36" ordinal="2" offset="7" sl="132" sc="13" el="132" ec="27" />
<SequencePoint vc="1" uspid="37" ordinal="3" offset="17" sl="133" sc="13" el="133" ec="27" />
<SequencePoint vc="1" uspid="38" ordinal="4" offset="27" sl="134" sc="13" el="134" ec="34" />
<SequencePoint vc="1" uspid="39" ordinal="5" offset="37" sl="136" sc="13" el="136" ec="44" />
<SequencePoint vc="1" uspid="40" ordinal="6" offset="47" sl="137" sc="13" el="137" ec="47" />
<SequencePoint vc="1" uspid="41" ordinal="7" offset="56" sl="139" sc="9" el="139" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="34" ordinal="0" offset="0" sl="130" sc="9" el="130" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="true" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663304</MetadataToken>
<Name>System.Void TestProject.MathFunctionsTest::.ctor()</Name>
<SequencePoints />
<BranchPoints />
<MethodPoint vc="5" uspid="42" ordinal="0" offset="0" />
</Method>
</Methods>
</Class>
</Classes>
</Module>
<Module hash="CE-A4-EA-1B-A3-A3-41-FC-95-6A-47-ED-DB-FB-8A-39-10-3B-39-6D">
<FullName>d:demotestprojectbindebugPOC.exe</FullName>
<ModuleName>POC</ModuleName>
<Files>
<File uid="3" fullPath="D:DemoPOCProgram.cs" />
</Files>
<Classes>
<Class>
<FullName><Module></FullName>
<Methods />
</Class>
<Class>
<FullName>POC.Program</FullName>
<Methods>
<Method visited="false" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="false" isStatic="true" isGetter="false" isSetter="false">
<MetadataToken>100663297</MetadataToken>
<Name>System.Void POC.Program::Main(System.String[])</Name>
<FileRef uid="3" />
<SequencePoints>
<SequencePoint vc="0" uspid="43" ordinal="0" offset="0" sl="11" sc="9" el="11" ec="10" />
<SequencePoint vc="0" uspid="44" ordinal="1" offset="1" sl="13" sc="13" el="13" ec="67" />
<SequencePoint vc="0" uspid="45" ordinal="2" offset="12" sl="14" sc="13" el="14" ec="55" />
<SequencePoint vc="0" uspid="46" ordinal="3" offset="24" sl="15" sc="13" el="15" ec="55" />
<SequencePoint vc="0" uspid="47" ordinal="4" offset="36" sl="16" sc="13" el="16" ec="53" />
<SequencePoint vc="0" uspid="48" ordinal="5" offset="42" sl="17" sc="13" el="17" ec="59" />
<SequencePoint vc="0" uspid="49" ordinal="6" offset="71" sl="18" sc="13" el="18" ec="64" />
<SequencePoint vc="0" uspid="50" ordinal="7" offset="100" sl="19" sc="13" el="19" ec="64" />
<SequencePoint vc="0" uspid="51" ordinal="8" offset="129" sl="20" sc="13" el="20" ec="62" />
<SequencePoint vc="0" uspid="52" ordinal="9" offset="158" sl="21" sc="13" el="21" ec="66" />
<SequencePoint vc="0" uspid="53" ordinal="10" offset="180" sl="22" sc="13" el="22" ec="42" />
<SequencePoint vc="0" uspid="54" ordinal="11" offset="191" sl="23" sc="13" el="23" ec="32" />
<SequencePoint vc="0" uspid="55" ordinal="12" offset="197" sl="24" sc="9" el="24" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="0" uspid="43" ordinal="0" offset="0" sl="11" sc="9" el="11" ec="10" />
</Method>
<Method visited="false" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="true" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663298</MetadataToken>
<Name>System.Void POC.Program::.ctor()</Name>
<SequencePoints />
<BranchPoints />
<MethodPoint vc="0" uspid="56" ordinal="0" offset="0" />
</Method>
</Methods>
</Class>
<Class>
<FullName>POC.MathFunctions</FullName>
<Methods>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663299</MetadataToken>
<Name>System.Double POC.MathFunctions::Add(System.Double,System.Double)</Name>
<FileRef uid="3" />
<SequencePoints>
<SequencePoint vc="1" uspid="57" ordinal="0" offset="0" sl="32" sc="9" el="32" ec="10" />
<SequencePoint vc="1" uspid="58" ordinal="1" offset="1" sl="33" sc="13" el="33" ec="26" />
<SequencePoint vc="1" uspid="59" ordinal="2" offset="7" sl="34" sc="9" el="34" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="57" ordinal="0" offset="0" sl="32" sc="9" el="32" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663300</MetadataToken>
<Name>System.Double POC.MathFunctions::Subtract(System.Double,System.Double)</Name>
<FileRef uid="3" />
<SequencePoints>
<SequencePoint vc="1" uspid="60" ordinal="0" offset="0" sl="37" sc="9" el="37" ec="10" />
<SequencePoint vc="1" uspid="61" ordinal="1" offset="1" sl="38" sc="13" el="38" ec="26" />
<SequencePoint vc="1" uspid="62" ordinal="2" offset="7" sl="39" sc="9" el="39" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="60" ordinal="0" offset="0" sl="37" sc="9" el="37" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663301</MetadataToken>
<Name>System.Double POC.MathFunctions::Multiply(System.Double,System.Double)</Name>
<FileRef uid="3" />
<SequencePoints>
<SequencePoint vc="1" uspid="63" ordinal="0" offset="0" sl="42" sc="9" el="42" ec="10" />
<SequencePoint vc="1" uspid="64" ordinal="1" offset="1" sl="43" sc="13" el="43" ec="26" />
<SequencePoint vc="1" uspid="65" ordinal="2" offset="7" sl="44" sc="9" el="44" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="63" ordinal="0" offset="0" sl="42" sc="9" el="42" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="100" branchCoverage="100" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663302</MetadataToken>
<Name>System.Double POC.MathFunctions::Divide(System.Double,System.Double)</Name>
<FileRef uid="3" />
<SequencePoints>
<SequencePoint vc="1" uspid="66" ordinal="0" offset="0" sl="47" sc="9" el="47" ec="10" />
<SequencePoint vc="1" uspid="67" ordinal="1" offset="1" sl="48" sc="13" el="48" ec="26" />
<SequencePoint vc="1" uspid="68" ordinal="2" offset="7" sl="49" sc="9" el="49" ec="10" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="66" ordinal="0" offset="0" sl="47" sc="9" el="47" ec="10" />
</Method>
<Method visited="true" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="true" isStatic="false" isGetter="false" isSetter="false">
<MetadataToken>100663303</MetadataToken>
<Name>System.Void POC.MathFunctions::.ctor()</Name>
<SequencePoints />
<BranchPoints />
<MethodPoint vc="5" uspid="69" ordinal="0" offset="0" />
</Method>
</Methods>
</Class>
</Classes>
</Module>
谁能解释一下我如何通过 xml 计算代码覆盖率百分比、覆盖的行数和其他有用信息。
我正在使用 Xslt 将其转换为 html,我不能为此目的使用报告生成器工具。
提前谢谢。
行代码由SequencePoint
覆盖。
访问过的SequencePoint
的 vc> 0
因此,覆盖运行的总覆盖范围为
计数( SequencePoint
其中 VC> 0) * 100/计数( SequencePoint
)
然后,您可以通过限制每个模块/类型/方法的搜索来微调结果
BranchPoint
和MethodPoint
结果可以用类似的方式计算
看看 ReportGenerator: https://github.com/danielpalme/ReportGenerator使用此工具,您可以将OpenCover报告转换为HTML,XML和Latex。
也许这会有所帮助:使 OpenCover 报告以 CruiseControl.NET 提供