question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VSTest with coverlet collector fails

See original GitHub issue

I have a .NETCore 3.1 test project with "Microsoft.NET.Test.Sdk" 16.7.1 of and "coverlet.collector" 1.3.0.

I am getting an exception when running tests using VSTest (I can’t switch to dotnet test approach, unfortunatly - there is a strong requirement to stick to vstest)

vstest.console.exe --collect:"XPlat Code Coverage" C:\Projects\test\Web.Tests\bin\Debug\Web.Tests.dll /TestAdapterPath:C:\.nuget\packages\coverlet.collector\1.3.0\build --Diag:"C:\Projects\diag.txt"

I get the following warning in the console:

Data collection : Unable to find a datacollector with friendly name 'XPlat code coverage'.
Data collection : Could not find data collector 'XPlat code coverage'

And in diag.txt file I see:


datacollector.exe, TestPluginDiscoverer: Failed to get types from assembly 'coverlet.collector, Version=1.3.0.0, Culture=neutral, PublicKeyToken=4beb1ad7f05a1c71'.  Skipping test extension scan for this assembly.  Error: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginDiscoverer.GetTestExtensionsFromAssembly[TPluginInfo,TExtension](Assembly assembly, Dictionary`2 pluginInfos)
TpTrace Warning: 0 : 60664, 1, 2020/11/14, 22:42:00.029, 8944115731653, datacollector.exe, LoaderExceptions: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

I followed the discussion mentioned on https://github.com/microsoft/vstest/issues/2278 but it seems like a separate issue. It feels I am missing some type of configuration.

I can’t figure out the source of the problem. Any help is highly appreciated. Thanks in advance.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:24

github_iconTop GitHub Comments

1reaction
MarcoRossignolicommented, Jan 16, 2022

, but for another .netcore3.1 test project reference a .netstandard2.0 project without specifying the test adapter path worked, but that too gave an empty coverage file

Depends on how the compilation is done…sometimes collector is copied inside bin folder(publish for instance) in some other scenario not, so to be sure to always load it you should specify /TestAdapterPath: when you use vstest.console.exe directly. Test platform by design search extensions in some predefined places(I don’t remember all the place) and one of these is the folder where the test container is placed, so I suspect that the coverlet extension was found here in you working sample.

if you run with dotnet test project coverlet is injected using msbuild target and so we’re adding correct path to the TestAdapterPath in a transparent way.

could you let me know how to generate coverage results correctly

can you provide a repro?It’s hard without it. Usually we need a repro and the command line.

1reaction
MarcoRossignolicommented, Jan 16, 2022

@ManikandanMani I think that in your case the issue is that you didn’t set the /TestAdapterPath if used with vstest.console.exe test platform needs to know where to discover the extensions and coverlet is not shipped together with the plat self. You should point to the folder that contains the coverlet collector like /TestAdapterPath:C:\Users\Marco\.nuget\packages\coverlet.collector\3.1.0\build\netstandard1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can you use Coverlet to get code coverage data in a .NET ...
Install Coverlet.MSbuild; Install Coverlet.Collector; Rebuild the project; Click on Tools > Nuget Package Manager > Package Manager Console ...
Read more >
coverlet
Coverlet is a cross platform code coverage framework for .NET, with support for line, branch and method coverage. It works with .NET Framework...
Read more >
dotnet test command - .NET CLI
The test host executes tests in the given project using a test framework, for example: MSTest, NUnit, or xUnit, and reports the success...
Read more >
Unit testing C# with MSTest and .NET
Create the first test. Write a failing test, make it pass, then repeat the process. Remove UnitTest1.cs from the PrimeService.Tests directory ...
Read more >
mirrors_DataDog/coverlet
VSTest stops process execution early · Upgrade coverlet.collector to version > 1.0.0 · Nerdbank.GitVersioning and /p:UseSourceLink=true option · Failed to resolve ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found