Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GoFightNguyen opened this issue Feb 8, 2019 · 10 comments
Closed

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

GoFightNguyen opened this issue Feb 8, 2019 · 10 comments

Comments

@GoFightNguyen
Copy link

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

@GoFightNguyen
Copy link
Author

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>

@nigurr
Copy link

nigurr commented Feb 12, 2019

@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 :)

@nigurr nigurr closed this as completed Feb 12, 2019
@gioce90
Copy link

gioce90 commented Feb 19, 2022

Exclusion by .runsettings file is a bit painful. Exclude 3rd party and Tests assemblies it would be nice.

@BradleyBarnett
Copy link

Agree 99% of the time no one would want to include nuget packages or test assesmblies, this should be default behaviour.

@cliffAtOsaic
Copy link

I agree 100% the default behavior should not include extra DLLs. Futhermore, filtering by .runsettings file is not working for both "dotnet test" and "dotnet-coverage". This should be reopened and the default behavior should be changed. Alternatively, an easy switch should be added to remove 3rd party imported NuGets/DLLs etc.

@LoupaLoupa
Copy link

LoupaLoupa commented Oct 15, 2024

This should be reopened as a feature request, I can't fathom reasons the default behavior should be to include assemblies we have 0 control over

@cliffAtOsaic
Copy link

cliffAtOsaic commented Oct 15, 2024

@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 :)

This is not working as designed, because the runsettings does not exclude extra DLLs even when explicitly told to do so.

(Nor does this make any sense to have this as the default behavior.)

@hughbidone
Copy link

hughbidone commented Jan 7, 2025

Please reopen this as other already mentioned, it makes no sense to include the coverage for the source files we have no control over i.e the 3rd party packages

@nohwnd
Copy link
Member

nohwnd commented Jan 7, 2025

@fhnaseer is there anything that can be done to exclude 3-rd party dlls automatically or to help in this area?

@fhnaseer
Copy link
Member

fhnaseer commented Jan 8, 2025

You can try to restrict symbols search paths to skip third party dependencies. You can try the following options in the runsettings file.

Name Values Default Description Example
SymbolsRestrictOriginalPathAccess True, False False Determines if looking for a .pdb file in the original debug directory. <SymbolsRestrictOriginalPathAccess>True</SymbolsRestrictOriginalPathAccess>
SymbolsRestrictReferencePathAccess True, False False Determines if looking for a .pdb file is allowed in the path where the .exe file is located. <SymbolsRestrictReferencePathAccess>True</SymbolsRestrictReferencePathAccess>
SymbolsRestrictDBGAccess True, False False Determines if looking for debug information is allowed from .dbg files. <SymbolsRestrictDBGAccess>True</SymbolsRestrictDBGAccess>
SymbolsRestrictSystemRootAccess True, False False Determines if searching for .pdb files is allowed in the system root directory. <SymbolsRestrictSystemRootAccess>True</SymbolsRestrictSystemRootAccess>

Docs: https://github.com/microsoft/codecoverage/blob/main/docs/configuration.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants