Vstest: dotnet test --collect:"code coverage" includes 3rd party dlls

Created on 8 Feb 2019  路  2Comments  路  Source: microsoft/vstest

Description

.NET Core 2.1
MSTest.TestAdapter v1.4.0
MSTest.TestFramework v.1.4.0
Microsoft.NET.Test.Sdk v 15.9.0

Steps to reproduce

Create a .NET Core Test project with a test
Add a dependency to the FluentAssertions NuGet pkg
dotnet test --blame --collect:"Code Coverage"
Open the coverage file

Expected behavior

I would not see coverage details for FluentAssertions

Actual behavior

I see coverage details for FluentAssertions

Most helpful comment

I discovered the .runsettings file. At the solution level, I created a codecoverage.runsettings file. I then run this command:
dotnet test --blame --collect:"Code Coverage" --settings:..\codecoverage.runsettings

This appears to give me what I need. Here are my runsettings. Hopefully I'm not leaving out anything important.

<?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, Culture=neutral"> <Configuration> <CodeCoverage> <!-- Match assembly file paths: --> <ModulePaths> <Include> <ModulePath>.*\mydomains.*.dll</ModulePath> </Include> <Exclude> <ModulePath>.*tests.dll</ModulePath> </Exclude> </ModulePaths> </CodeCoverage> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings> </RunSettings>

All 2 comments

I discovered the .runsettings file. At the solution level, I created a codecoverage.runsettings file. I then run this command:
dotnet test --blame --collect:"Code Coverage" --settings:..\codecoverage.runsettings

This appears to give me what I need. Here are my runsettings. Hopefully I'm not leaving out anything important.

<?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, Culture=neutral"> <Configuration> <CodeCoverage> <!-- Match assembly file paths: --> <ModulePaths> <Include> <ModulePath>.*\mydomains.*.dll</ModulePath> </Include> <Exclude> <ModulePath>.*tests.dll</ModulePath> </Exclude> </ModulePaths> </CodeCoverage> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings> </RunSettings>

@GoFightNguyen Currently we do instrument all dependent dlls (whether they come from 3rd part dependency or nuget reference).
In this case we try to collect code coverage for FluentAssertions.

However this package can be excluded from coverage report by modifying the runsettings as you have mentioned.
This is working as designed :)

Was this page helpful?
0 / 5 - 0 ratings