3

have .net core 3.1 Microsoft.net.sdk projects, with lots of async xUnit tests.

  • tried - adding coverlet.msbuild 2.9.0 to the project, and then running: dotnet test Common\Common.csproj /p:CollectCoverage=true / got 100% displayed, but an empty coverage file created
  • tried - adding coverlet.collector 1.3.0 to the project and then running: dotnet test Common\Common.csproj --collect:"XPlat Code Coverage" got a file created in testresults\{guid}\coverage.cobertura.xml - but it just says lines-covered=0

whereas stdout is saying 88 tests run in 4s. What am I doing wrong?

Darren Oakey
  • 2,894
  • 3
  • 29
  • 55

1 Answers1

6

For me coverlet.msbuild works perfect with command: dotnet test Common\Common.csproj /p:CollectCoverage=true /p:IncludeTestAssembly=true /p:CoverletOutputFormat=cobertura /p:ExcludeByFile=\"**/Microsoft.NET.Test.Sdk.Program.cs\"

So, I guess you missed CoverletOutputFormat here.

  • 3
    thank you! it's not the output format - but what I _was_ missing that is the key was /p:IncludeTestAssembly=true. Now it works perfectly. – Darren Oakey Jul 07 '20 at 07:25
  • 1
    `/p:IncludeTestAssembly=true` saved my day..!! – Arjit Sharma Nov 05 '22 at 14:20
  • I am using dotnet 8, from `dotnet test DemoTest\DemoTest.csproj --no-build --collect:"XPlat Code Coverage" --logger "trx;LogFileName=tests.xml" /p:CollectCoverage=true /p:IncludeTestAssembly=true /p:CoverletOutputFormat=opencover` - in the log all tests run, but .../TestResults/../coverage.cobertura.xml file has no sources, packages... genrated html report is empty. – Sasha Bond Jul 12 '23 at 22:59
  • @SashaBond may be try `/p:CoverletOutputFormat=cobertura` instead `/p:CoverletOutputFormat=opencover` – Yevheniy Tymchishin Jul 13 '23 at 13:50