Skip to content

Unable to get coverlet to work with vstest #595

Closed
@nzain

Description

@nzain

I'm using coverlet.msbuild on several modern netstandard2.0 nunit test projects. A simple dotnet test Some.csproj /p:CollectCoverage=true together with smart Directory.Build.Targets like this

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <PropertyGroup>
    <CoverletOutputFormat>opencover</CoverletOutputFormat>
    <CoverletOutput>$(MSBuildThisFileDirectory)TestResults/Coverage_$(AssemblyName).xml</CoverletOutput>
  </PropertyGroup>
</Project>

creates SonarQube compatible coverage files. This works really well.

However, one of my test projects is ugly, has many dependencies (full net472 framework), and a ton of native libraries as a bonus. The tests are important, but I don't own the dependencies and the owners are very conservative - so I can't change this situation right now. In this case dotnet test doesn't work, but dotnet vstest does work fine (and the vstest.console.exe as well).

Problem: I can't get coverlet to work with VSTest. Following coverlet's Readme.md I referenced coverlet.collector instead of its msbuild brother. Since I have to target a dll instead of a project, I have to build first. I'm using msbuild here, not dotnet publish for the same reasons dotnet test doesn't work. Then dotnet vstest SomeUglyTest.dll runs my tests as expected. However, all of the following attempts to collect coverage failed:

  1. dotnet vstest SomeUglyTest.dll --settings:coverletArgs.runsettings (with a unmodified example from somewhere here in the repository) prints the warning Data collection : Could not find data collector 'XPlat Code Coverage' and obviously doesn't create any coverage output.
  2. dotnet vstest SomeUglyTest.dll --collect:"XPlat Code Coverage" prints the same warning, no output file.

related: #395 #190

vstest is very difficult to understand... but I think that it requires some kind of "collector.dll", which should be satisfied by referencing the coverlet.collector nuget package. However, just referencing the package does not mean msbuild will copy something to bin\debug\. In fact, I haven't found such a dll. dotnet publish might do things differently, but I can't use it.

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions