Search code examples
visual-studiounit-testing.net-corecommand-line-interfacecobertura

dotnet Cli error trying to generate code coverage stats


I'm running the following command to run my .net Core tests:

dotnet test

This runs fine. I want to now generate code coverage stats, so after following this article, I ran this:

dotnet test AI.Core.Tests.csproj 
  /p:CollectCoverage=true 
  /p:CoverletOutputFormat=cobertura 
  /p:CoverletOutput=TestResults\Coverage

I get the following output from this command:

C:\Users\sp4_rm\.nuget\packages\coverlet.msbuild\2.2.1\build\netstandard2.0\coverlet.msbuild.targets(23,5): error : 
  Index was out of range. Must be non-negative and less than the size of the collection. 
  [C:\Users\sp4_rm\Desktop\EVO\AI.Core\src\Tests\AI.Core.Tests.csproj]

 C:\Users\sp4_rm\.nuget\packages\coverlet.msbuild\2.2.1\build\netstandard2.0\coverlet.msbuild.targets(23,5): error : 
  Parameter name: index 
  [C:\Users\sp4_rm\Desktop\EVO\AI.Core\src\Tests\AI.Core.Tests.csproj]

See screen shot below:

enter image description here

Has anyone got this command running? What am I doing wrong?


Solution

  • Ok so this was due to a school boy error in not actually have any code to test (or test case to test it) in my sample project!! Adding a couple of classes into the main projects and a couple of tests in the test project does away with this problem! (just in case anyway does the same thing as me!)