【发布时间】:2021-06-08 20:24:24
【问题描述】:
Visual Studio 2019 社区版 项目框架 4.5 我的环境:Windows Server 2016 预期行为:预期将代码覆盖率显示为覆盖百分比。 实际行为:代码覆盖率始终显示为 0
使用的命令:
OpenCover.Console.exe -target:"<PATH>\xunit.runner.console.2.4.1\tools\net472\xunit.console.x86.exe" -targetargs:"<PATH>\bin\Debug\PROJECT_Tests.dll" -register:user -output:"<PATH>\bin\Debug\TestResults\OpenCover\coverage.xml"
我也尝试过使用 vstest runner。
在cmd中,输出显示为:
=== 测试执行摘要 === PROJECT_Tests Total: 11, Errors: 0, Failed: 0, Skipped: 0, Time: 118.717s 提交... 访问了 1338 的 235 班 (17.56) 17022 的访问方法 942 (5.53) 访问点 2632 of 58653 (4.49) 36315 (4.43) 中访问的分支 1607
==== 替代结果(包括所有方法,包括那些没有相应来源的方法)==== 1570 年的替代访问类 235 (14.97) 18541 的替代访问方法 942 (5.08)
但是,当检查 coverage.xml 文件或使用报告生成器 (v4.5.0) 我们生成报告时,所有文件都显示为 0% 覆盖率。
<Method visited="false" cyclomaticComplexity="4" nPathComplexity="2" sequenceCoverage="0" branchCoverage="0" crapScore="20" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<Summary numSequencePoints="8" visitedSequencePoints="0" numBranchPoints="3" visitedBranchPoints="0" sequenceCoverage="0" branchCoverage="0" maxCyclomaticComplexity="4" minCyclomaticComplexity="4" maxCrapScore="20" minCrapScore="20" visitedClasses="0" numClasses="0" visitedMethods="0" numMethods="1" />
<MetadataToken>100664627</MetadataToken>
<Name>project.BusinessEntities.CoordinationNotes.CoordinationNotesInfo project.CoordinationNotes.DalCoordinationNotes::GetDetails(project.BusinessEntities.SystemManagement.GeneralRequest,project.BusinessEntities.Member.MemberTaskList&,System.Object&)</Name>
<FileRef uid="2505" />
<SequencePoints>
<SequencePoint vc="0" uspid="75974" ordinal="0" offset="0" sl="38" sc="9" el="38" ec="10" bec="0" bev="0" fileid="2505" />
<SequencePoint vc="0" uspid="75975" ordinal="1" offset="1" sl="39" sc="13" el="39" ec="131" bec="0" bev="0" fileid="2505" />
<SequencePoint vc="0" uspid="75976" ordinal="2" offset="44" sl="41" sc="20" el="41" ec="56" bec="0" bev="0" fileid="2505" />
<SequencePoint vc="0" uspid="75977" ordinal="3" offset="56" sl="42" sc="13" el="42" ec="14" bec="0" bev="0" fileid="2505" />
<SequencePoint vc="0" uspid="75978" ordinal="4" offset="57" sl="43" sc="17" el="43" ec="75" bec="0" bev="0" fileid="2505" />
<SequencePoint vc="0" uspid="75979" ordinal="5" offset="72" sl="45" sc="17" el="45" ec="115" bec="2" bev="0" fileid="2505" />
<SequencePoint vc="0" uspid="75980" ordinal="6" offset="99" sl="47" sc="17" el="47" ec="29" bec="0" bev="0" fileid="2505" />
<SequencePoint vc="0" uspid="75981" ordinal="7" offset="114" sl="49" sc="9" el="49" ec="10" bec="0" bev="0" fileid="2505" />
</SequencePoints>
<BranchPoints>
<BranchPoint vc="0" uspid="75982" ordinal="0" offset="79" sl="45" path="0" offsetend="81" fileid="2505" />
<BranchPoint vc="0" uspid="75983" ordinal="1" offset="79" sl="45" path="1" offsetend="84" fileid="2505" />
</BranchPoints>
<MethodPoint xsi:type="SequencePoint" vc="0" uspid="75974" ordinal="0" offset="0" sl="38" sc="9" el="38" ec="10" bec="0" bev="0" fileid="2505" />
</Method>
有什么建议吗?我究竟做错了什么?或者 c# 社区版中代码覆盖率的任何替代方案?
【问题讨论】:
标签: unit-testing code-coverage visual-studio-2019 xunit opencover