I am trying to exclude a folder from the code coverage analysis but I haven’t had any success after a lot of trial and error attempts and research on here.
This is my test task in the build pipeline:
- task: DotNetCoreCLI@2
displayName: 'Running Unit Tests'
inputs:
command: test
projects: '$(unitTestsProject)'
arguments: '--configuration $(buildConfiguration) --settings ./cover.runsettings'
publishTestResults: true
continueOnError: false
and in the run settings I have tried different approaches, some of them are as bellow:*
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Exclude>
<ModulePath>.*Migrations.*</ModulePath>
<ModulePath>.*\Migrations\.*</ModulePath>
</Exclude>
</ModulePaths>
</CodeCoverage>
</Configuration>
</DataCollector>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<CodeCoverage>
<ExcludeDirectories>
<Directory>.*\Migrations\.*</Directory>
</ExcludeDirectories>
</CodeCoverage>
</Configuration>
</DataCollector>
All of the variations above didn’t work. But when I used the attribute [ExcludeFromCodeCoverage] on each class I didn’t want included in the code coverage, it worked well. I need it to work from the runsettings file as the migrations folder will grow quickly and it’s not practical to keep going through the generated classes and adding attributes.
Any help or guidance will be highly appreciated. Thank you
2
Answers
According to this doc for Customize code coverage analysis, you could test to define your code with below.
My guess is, it would be easier to block them by namespace…
Source files relies on the symbol data being present and a few other things. The namespace is embedded in the assembly itself.
Make sure you try it locally to see if it work, before putting it on the build server too….