我正在使用以下批处理文件来尝试生成代码覆盖率结果:
@echo off
SET dotnet="C:/Program Files/dotnet/dotnet.exe"
SET opencover=.packagesOpenCover.4.6.519toolsOpenCover.Console.exe
SET reportgenerator=.packagesReportGenerator.2.5.8toolsReportGenerator.exe
SET targetargs="test .testIdentityServer.UnitTestsIdentityServer.UnitTests.csproj -f net461"
SET filter="+[*]QuickstartIdentityServer* -[*.Tests]* -[xunit.*]* -[FluentValidation]*"
SET coveragefile=Coverage.xml
SET coveragedir=Coverage
REM Run code coverage analysis
%opencover% -oldStyle -register:user -target:%dotnet% -output:%coveragefile% -targetargs:%targetargs% -filter:%filter% -skipautoprops -hideskipped:All
REM Generate the report
%reportgenerator% -targetdir:%coveragedir% -reporttypes:Html;Badges -reports:%coveragefile% -verbosity:Error
REM Open the report
start "report" "%coveragedir%index.htm"
测试似乎运行良好,但我收到以下错误消息:
Starting test execution, please wait...
Total tests: 12. Passed: 12. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 4.0469 Seconds
Committing...
No results, this could be for a number of reasons. The most common reasons are:
1) missing PDBs for the assemblies that match the filter please review the
output file and refer to the Usage guide (Usage.rtf) about filters.
2) the profiler may not be registered correctly, please refer to the Usage
guide and the -register switch.
有关项目的更多背景信息:
解决方案结构:
test project:SolutionDirtestIdentityServer.UnitTestsIdentityServer.UnitTests.csproj
project being tested:
path: SolutionDirsrcQuickstartIdentityServerQuickstartIdentityServer.csproj
target framework: net461
任何帮助不胜感激!
您可能
还需要在.csproj
文件中将DebugType
设置为full
:
<DebugType>full</DebugType>
我没有使用过OpenCover,但成功使用了被套
您可以在此链接中看到完整示例:.NET Core 的跨平台代码覆盖率。
基本上,您可以全局添加包或在项目中添加包,如下所示:
dotnet add package coverlet.msbuild
比简单地使用命令:
dotnet test /p:CollectCoverage=true