Description
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:
dotnet vstest SomeUglyTest.dll --settings:coverletArgs.runsettings
(with a unmodified example from somewhere here in the repository) prints the warningData collection : Could not find data collector 'XPlat Code Coverage'
and obviously doesn't create any coverage output.dotnet vstest SomeUglyTest.dll --collect:"XPlat Code Coverage"
prints the same warning, no output file.
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?