Skip to content

vstest.console.exe not detecting data collectors for code coverage #15049

Open
@davidkeaveny

Description

@davidkeaveny

I am attempting to run code coverage on a .NET Framework 4.7.2 application using vstest.console.exe, but when I run the tests from the command line, the tests themselves pass but a coverage report is not generated.

My test project file looks like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <DebugType>full</DebugType>
  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="6.0.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="FluentAssertions" Version="5.10.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
    <PackageReference Include="NUnit" Version="3.14.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>

and if I run the following command from the solution root folder then all tests pass:

> vstest.console.exe MyProject.Tests\bin\Debug\net472\MyProject.Tests.dll

VSTest version 17.13.0 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
NUnit Adapter 3.17.0.0: Test execution started
Running all tests in C:\work\MyProject.Tests\bin\Debug\net472\MyProject.Tests.dll

All good so far; however, if I then change the command to run code coverage:

> vstest.console.exe MyProject.Tests\bin\Debug\net472\MyProject.Tests.dll /EnableCodeCoverage

VSTest version 17.13.0 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
Data collection : Could not find data collector 'Code Coverage'
NUnit Adapter 3.17.0.0: Test execution started

So I then go and create CodeCoverage.runsettings as follows:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <DataCollectionRunSettings>
        <DataCollectors>
            <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
                <Configuration>
                    <CodeCoverage>
                        <ModulePaths>
                            <Exclude>
                                <ModulePath>.*FluentValidation.*</ModulePath>
                                <ModulePath>.*NUnit3.*</ModulePath>
                            </Exclude>
                        </ModulePaths>
                        <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
                        <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
                        <CollectFromChildProcesses>True</CollectFromChildProcesses>
                        <CollectAspDotNet>False</CollectAspDotNet>
                    </CodeCoverage>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

and run my new command:

> vstest.console.exe MyProject.Tests\bin\Debug\net472\MyProject.Tests.dll /EnableCodeCoverage /Settings:CodeCoverage.runsettings

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
Data collection : Could not find data collector 'Code Coverage'
NUnit Adapter 3.17.0.0: Test execution started

so no change at all, whether or not I specify the .runsettings file.

How can I get coverage to run? Should I be referencing coverlet.collector at all, or is that .NET Core-only assembly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions