我的项目结构如下:
.
├── Application
├── Application.Core
├── Application.Domain
├── Application.Tests
├── Application.IntegrationTests
└── README.md
运行测试的命令我使用以下输入:
dotnet test $folder.FullName -c Release --no-build /p:CoverletOutput='$rootcoverage' /p:MergeWith='$rootcoverage.json' /p:CoverletOutputFormat=opencover
其中$folder
指向我的应用程序。测试路径:C:projectscoredemoappCoreDemoApp.Tests
和$root
到C:projectscoredemoapp
所有测试都已成功运行。但是,问题是没有创建coverage.json
和coverage.opencover.xml
文件。
我还尝试通过以下命令直接使用coverlet
:
coverlet <path to test.dll> -
-target "dotnet" --targetargs "test --no-build" --merge-with $rootcoverage.json --format opencover
,在我的本地机器上,所有的东西都可以通过dll的显式路径工作。但是,在使用以前的$folder.FullName
作为<path to assembly>
运行命令的情况下,coverlet会采用调试dll的路径,而不是发布版本的路径,但会失败。
完整构建脚本的链接
基本上我忘记了将coverlet msbuild NuGet包添加到我的测试项目中。在那之后,所有操作都很好,使用以下命令:
dotnet test $folder.FullName -c Release --no-build /p:CollectCoverage=true /p:CoverletOutput=$rootcoverage /p:CoverletOutputFormat=opencover