SSWConsulting / SSWConsulting/SSW.CleanArchitecture
🐛 Using code coverage cause DomainModel_ShouldInheritsBaseClasses to fail when github action build-and-test is run
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 199
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
Cc:
Hi
Describe the Bug
When you add code coverage reports to the build-and-test workflow, the DomainModel_ShouldInheritsBaseClasses test fails. It runs fine locally. This is because the coverlet action inserts an instrumentation class into the assembly and it does not get filtered out Types filter.
To Reproduce
Steps to reproduce the behavior:
I added these actions to the build-and-test workflow
1.
name: Test
run: dotnet test --no-build --no-restore --verbosity normal /p:CollectCoverage=true --configuration Release --logger trx --collect:"XPlat Code Coverage"
- name: Combine Coverage Reports # This is because one report is produced per project, and we want one result for all of them.
uses: danielpalme/ReportGenerator-GitHub-Action@v5.4.5
with:
reports: "**/*.cobertura.xml" # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported.
targetdir: "${{ github.workspace }}" # REQUIRED # The directory where the generated report should be saved.
reporttypes: "Cobertura" # The output formats and scope (separated by semicolon)
verbosity: "Info"
title: "Code Coverage"
tag: "${{ github.run_number }}_${{ github.run_id }}"
assemblyfilters: "-MigrationService" # Exclude MigrationService assembly
toolpath: "reportgeneratortool"
- name: Upload Combined Coverage XML
uses: actions/upload-artifact@v4
with:
name: coverage
path: ${{ github.workspace }}/Cobertura.xml
retention-days: 5
- name: Publish Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: "Cobertura.xml"
badge: true
fail_below_min: false # just informative for now
format: markdown
hide_branch_rate: false
hide_complexity: false
indicators: true
output: both
thresholds: "10 30"
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Upload Test Result Files
uses: actions/upload-artifact@v4
with:
name: test-results
path: ${{ github.workspace }}/**/TestResults/**/*
retention-days: 5
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2.19.0
if: always()
with:
# NOTE: using trx_files instead of files due to https://github.com/EnricoMi/publish-unit-test-result-action/issues/424
trx_files: "${{ github.workspace }}/**/*.trx"
- run the workflow and that 1 test will fail
Expected Behavior
Test should pass. I fixed it by adding an additional filter for the types
.And().ResideInNamespaceStartingWith("Radiant.Domain"); this will exclude the temporary classes injected by coverlet
Tasks
- Investigate
- Fix
More Information
Environment
- Device: [e.g. iPhone 12]
- Browser: [e.g. chrome, safari]
- OS: [e.g. iOS]
Screenshots
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DomainModel_ShouldInheritsBaseClasses test and the build-and-test GitHub Actions workflow, then reproduce it with the coverage-enabled dotnet test command. Check how the coverage instrumentation affects the type filter. Done means the test passes in the coverage workflow while still validating the intended domain types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, github-actions
- Domain
- ci-cd, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100