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

Unable to exclude files using .runsettings in dotnet test. #1683

Closed
ashishbhatt-afk opened this issue Aug 7, 2024 · 4 comments
Closed

Unable to exclude files using .runsettings in dotnet test. #1683

ashishbhatt-afk opened this issue Aug 7, 2024 · 4 comments
Labels
question This issue is a question

Comments

@ashishbhatt-afk
Copy link

ashishbhatt-afk commented Aug 7, 2024

I am trying to exclude few files from code coverage but I cant do it.

  1. My .runsettings file is in the root folder.
  2. I am sure that .runsetting file is picked up by the pipeline.

Below is my runsettings file:


   <?xml version="1.0" encoding="utf-8" ?>
   <RunSettings>
     <DataCollectionRunSettings>
       <DataCollectors>
         <DataCollector friendlyName="XPlat code coverage">
           <Configuration>
             <Format>cobertura,opencover</Format>
             <Exclude>[*.Tests?]*</Exclude>
             <ExcludeByFile>**/IRISElementsBookkeeping/*.cs,</ExcludeByFile>
             <SkipAutoProps>true</SkipAutoProps>
           </Configuration>
         </DataCollector>
       </DataCollectors>
     </DataCollectionRunSettings>
   </RunSettings>


Below is my YAML:

- task: DotNetCoreCLI@2
    displayName: Build Unit tests
    inputs:
      command: 'build'
      arguments: '--configuration $(BUILD_CONFIGURATION)'
      projects: '$(TEST_PROJECT_PATH)'
  
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: |
        pwd
        ls
        brew install findutils
        gfind . -regex '.*App.xaml.cs'
        
  - task: DotNetCoreCLI@2
    displayName: 'Run Tests and Collect Coverage'
    inputs:
      command: 'test'
      projects: '**/*Tests.csproj'
      arguments: '--configuration $(BUILD_CONFIGURATION) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(COVERAGE_DIRECTORY)/ --settings "demo.runsettings"'
      publishTestResults: true
  
  - script: |
      dotnet tool install --global dotnet-reportgenerator-globaltool
      reportgenerator -reports:$(COVERAGE_DIRECTORY)/coverage.cobertura.xml -targetdir:$(COVERAGE_REPORT_DIRECTORY) -reporttypes:Html
    displayName: 'Generate Coverage Report'

  - task: PublishCodeCoverageResults@2
    displayName: 'Publish Code Coverage'
    inputs:
      summaryFileLocation: '$(COVERAGE_DIRECTORY)/coverage.cobertura.xml'

Please help.

@github-actions github-actions bot added the untriaged To be investigated label Aug 7, 2024
@ashishbhatt-afk
Copy link
Author

@Bertk
@daveMueller
Would you guys be able to help here. I saw your few comments on a similar issue.

@Bertk
Copy link
Collaborator

Bertk commented Aug 13, 2024

@ashishbhatt-afk
I use the report from reportgenerator to identify the assemblies and classes which should be excluded.

I have doubts using [*.Tests?]*. Please use assembly names instead

<Exclude>[typename1]*, [typename2]*</Exclude>
<ExcludeByFile>**/IRISElementsBookkeeping/*.cs</ExcludeByFile>

https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#filters

example from Coverlet CI

dotnet test test/coverlet.collector.tests/coverlet.collector.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.collector.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*%2c[testgen_]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.collector.test.diag.log;tracelevel=verbose"

@Bertk Bertk added question This issue is a question and removed untriaged To be investigated labels Aug 13, 2024
@fossbrandon
Copy link

I'm running into similar issues. I created an issue here with my findings #1695

From what I found, the generated report that you specified under CoverletOutput is not using the runsettings file properly. Until this gets fixed, you could manually add the exclusions using the property /p:CoverletOutput=... I believe.

@Bertk
Copy link
Collaborator

Bertk commented Sep 5, 2024

The VSTest integration with coverlet.collector uses the .runsettings file (see VSTestIntegration.md)

You are using coverlet.msbuild which only supports MSBuild properties.

  - task: DotNetCoreCLI@2
    displayName: 'Run Tests and Collect Coverage'
    inputs:
      command: 'test'
      projects: '**/*Tests.csproj'
      arguments: '--configuration $(BUILD_CONFIGURATION) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(COVERAGE_DIRECTORY)/ --settings "demo.runsettings"'
      publishTestResults: true
  

@Bertk Bertk closed this as completed Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This issue is a question
Projects
None yet
Development

No branches or pull requests

3 participants