11

My project structure is the following:

.
├── Application
├── Application.Core
├── Application.Domain
├── Application.Tests
├── Application.IntegrationTests
└── README.md

And the command to run my test I use the following input:

dotnet test $folder.FullName -c Release --no-build /p:CoverletOutput='$root\coverage' /p:MergeWith='$root\coverage.json' /p:CoverletOutputFormat=opencover 

where $folder is pointing to my Application.Tests path: C:\projects\coredemoapp\CoreDemoApp.Tests and $root to C:\projects\coredemoapp\

All the tests are run successfully. However, the problem is that coverage.json nor coverage.opencover.xml files are not created.

I also tried to use coverlet directly with the following command:

coverlet <path to test.dll> -
-target "dotnet" --targetargs "test --no-build" --merge-with $root\coverage.json --format opencover

, everything works on my local machine with explicit path to the dll. But in the case of running the command with the previous $folder.FullName as the <path to assembly>, coverlet assumes a path to the debug dll, not release version as it should and fails.

Link to the full build script

ajr
  • 874
  • 2
  • 13
  • 29
  • At least a partial solution is to take advance of the coverlet --targetargs and pass it the release parameter: `--targetargs "test -c Release --no-build"` – ajr Nov 02 '19 at 12:20

1 Answers1

29

Basically I forgot to add the coverlet msbuild NuGet package into my test project. After that, all worked fine with the following command:

dotnet test $folder.FullName -c Release --no-build /p:CollectCoverage=true /p:CoverletOutput=$root\coverage /p:CoverletOutputFormat=opencover
ajr
  • 874
  • 2
  • 13
  • 29
  • I think argument would be `--targetargs "test [path to test project].csproj --no-build"` instead of `--targetargs "test -c Release --no-build"` – Sasha Bond Jan 27 '21 at 21:03
  • what is /p: used for? Im a bit confused – Sujit.Warrier Jan 17 '22 at 06:36
  • @ajr Worked perfectly with `coverlet.msbuild`. Strange that `coverlet.collector` is included in a new test project but not `coverlet.msbuild`. – Ogglas Feb 08 '22 at 16:25