.NET 中的常见模式是在单独的项目中进行单元测试,这似乎可以正常工作,但是,我们正在尝试实现一种模式,其中单元测试与实现一起存在于项目中。
当尝试使用 Coverlet 生成覆盖文件时,sonarscanner 工具正在接受多个文件,但它没有报告覆盖范围:
dotnet-sonarscanner /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml"
...
dotnet test --configuration Release \
--no-build \
--no-restore \
--logger "trx;LogFileName=testresults.trx" \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=opencover
...
INFO: Parsing the OpenCover report /root/app/src/./Project.Data/coverage.opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: /root/app/src/./Project.Data/coverage.opencover.xml
INFO: Parsing the OpenCover report /root/app/src/./Project.WebAPI/coverage.opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: /root/app/src/./Project.WebAPI/coverage.opencover.xml
INFO: Parsing the OpenCover report /root/app/src/./Project.Domain/coverage.opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: /root/app/src/./Project.Domain/coverage.opencover.xml
WARN: The Code Coverage report doesn't contain any coverage data for the included files. For troubleshooting hints, please refer to https://docs.sonarqube.org/x/CoBh
提供的链接在这种情况下没有显示任何帮助,并且在项目文件中添加 DebugType Full (来自相关答案)不会产生不同的结果。