Coverlet lcov.info file not generated for dotnet core project

2.9k views Asked by At

I'm working on dotnet core project withd VS code inside a linux machine.

following below blog to generate coverage report: https://www.hanselman.com/blog/AutomaticUnitTestingInNETCorePlusCodeCoverageInVisualStudioCode.aspx

as mentioned there Im passing dotnet test arguments as below:

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info

and expecting to lcov.info file to be generated, but it doesn't.

am I missing anything here?

ps: I have this package already included

 <PackageReference Include="coverlet.collector" Version="1.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
1

There are 1 answers

0
Samuel Utbult On BEST ANSWER

I use to have the exact problem. Hanselman's guide never explicitly instructs the reader that the package coverlet.msbuild is required to instruct .NET to collect code coverage using the /p: syntax. Include coverlet.msbuild in a test project by executing the following command inside the test project folder:

dotnet add package coverlet.msbuild

The test project's *.csproj file should include a statement similar to the following:

<PackageReference Include="coverlet.msbuild" Version="2.9.0"
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
</PackageReference>

With this fix, VSCode's Coverage Gutters extension works out of the box for me when I run the exact same command as you posted.