coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.94k stars 386 forks source link

Coverage Report not Generated When Running through VS 2019 Test Explorer -- coverlet.collector #485

Closed Stefanie899 closed 5 years ago

Stefanie899 commented 5 years ago

This issue is occurring when using coverlet.collector v1.0.0. Essentially coverage reports are generated when I run tests through the command line, but when running through the Test Explorer, coverage reports are not generated.

I have set up a .runsettings file which essentially just describes which format to use and some custom exclusions I need for my project:

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="XPlat code coverage">
        <Configuration>
          <Format>lcov</Format>
          <Exclude>[*.tests]*,[*.testing]*,[xunit.*]*,[*.SqlServer]*</Exclude> <!-- [Assembly-Filter]Type-Filter -->
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

I have selected this .runsettings file to be used in VS2019 through the Test > Test Settings > Select Test Settings File option. When I run a test using the Test Explorer, it generates the folder, but never actually spits out the coverage report.

Additional Details: I have a tests project called Refactored.Web.Tests. When I run through the console: dotnet test dotnet/Tests/Presentation/Refactored.Web.Tests/Refactored.Web.Tests.csproj --no-restore --settings coverletArgs.runsettings it generates a folder in dotnet/Tests/Presentation/Refactored.Web.Tests/TestResults with the coverage report in said folder.

When I run it through the Test Explorer, it generates a folder in the root of the solution at dotnet/TestResults but without the associated coverage report.

Is there something I'm missing to get this to generate as expected?

MarcoRossignoli commented 5 years ago

Essentially coverage reports are generated when I run tests through the command line, but when running through the Test Explorer

@vagisha-nidhi any ideas? Seem related to VS integration

vagisha-nidhi commented 5 years ago

@MarcoRossignoli @Stefanie899 Yes the issue is related to VS integration. Any custom datacollector path is not automatically known when running via VS. In dotnet test, this happens because we set the test adapter path to find the datacollector in the targets file https://github.com/tonerdo/coverlet/blob/master/src/coverlet.collector/build/netstandard1.0/coverlet.collector.targets

As a workaround, you can specify the test adapter path to the coverlet.collector nuget path as below.

<RunSettings>
  <RunConfiguration>
    <TestAdaptersPaths>C:\Users\vanidhi\.nuget\packages\coverlet.collector\1.0.1\build\netstandard1.0\</TestAdaptersPaths>
  </RunConfiguration>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="XPlat code coverage">
        <Configuration>
          <Format>lcov</Format>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

Meanwhile, I will log this issue on vstest to get this addressed.

MarcoRossignoli commented 5 years ago

Thanks Vagisha for investigation, can you link here issue from vstest repo for @Stefanie899? I'm going to close this because unrelated to Coverlet.

tonyhallett commented 2 years ago

I am not getting any coverage with test explorer and run settings as above although with .nuget\packages\coverlet.collector\3.1.2\build\netstandard1.0

Should I try version 1.0.0 ?

MarcoRossignoli commented 2 years ago

@tonyhallett this issue is pretty old can you open a new one? You can also enable logs in VS and verify if coverlet datacollector is loaded correctly

image
tonyhallett commented 2 years ago

responding in https://github.com/coverlet-coverage/coverlet/issues/1332