我正在使用以下批处理文件来尝试生成代码覆盖率结果:
@echo off
SET dotnet="C:/Program Files/dotnet/dotnet.exe"
SET opencover=.\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe
SET reportgenerator=.\packages\ReportGenerator.2.5.8\tools\ReportGenerator.exe
SET targetargs="test .\test\IdentityServer.UnitTests\IdentityServer.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:SolutionDir\test\IdentityServer.UnitTests\IdentityServer.UnitTests.csproj
project being tested:
path: SolutionDir\src\QuickstartIdentityServer\QuickstartIdentityServer.csproj
target framework: net461
感谢任何帮助!
答案 0 :(得分:0)
您可能还需要.csproj
文件中的set DebugType
to full
:
<DebugType>full</DebugType>
答案 1 :(得分:0)
我没有使用过OpenCover,但是成功使用过coverlet
您可以看到完整的示例in this link: Cross platform code coverage arrives for .NET Core。
基本上,您可以在全局或在项目中添加软件包,如下所示:
dotnet add package coverlet.msbuild
比简单地使用命令:
dotnet test /p:CollectCoverage=true