I run my tests with VSTest@2
step with codeCoverageEnabled: true
(.NET project)
- task: VSTest@2
displayName: 'Run Tests'
inputs:
vsTestVersion: 'toolsInstaller'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
codeCoverageEnabled: true
But in the Code Coverage tab, I can see all the external dependencies (Managed via NuGet, and Native):
I hid all the names, but the red ones are external dependencies and only the green one is my assembly that I want to test. As a result, the total line coverage is way below the actual relevant value...
How can I filter out all the external resources to get the results for my code only?
After some research, if you want to filter out all the external resources, i found a workaround to exclude assemblies manually.You have to add all external resources in your .runsetting file one by one. You can check the steps below.
1.In the .runsettings file,add the following configuration to exclude specific modules (DLLs) from code coverage:
<ModulePaths>
<Exclude>
<ModulePath>.*XXXX.dll</ModulePath>
<!-- Add more ModulePath nodes here. -->
</Exclude>
</ModulePaths>
2 Refer to the .runsettings file using the runSettingsFile
argument in the VSTest tasK.
- task: VSTest@2
displayName: 'Run Tests'
inputs:
vsTestVersion: 'toolsInstaller'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
codeCoverageEnabled: true
runSettingsFile: '<PATH/TO/FILE.RUNSETTINGS>'
Hope it can help you.