Skip to content

Commit c267ad6

Browse files
committed
Fix code coverage collection with VSTest
1 parent 9a1962f commit c267ad6

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ jobs:
3535
run: dotnet build -c Release --no-restore
3636
- name: Test & collect coverage
3737
run: |
38-
dotnet test -c Release --no-restore --no-build -- \
39-
--coverage --coverage-output-format xml --coverage-output ${{ github.workspace }}/coverage.xml
38+
dotnet test -c Release --no-restore --no-build \
39+
--settings coverage.runsettings --results-directory ${{ github.workspace }}/test-results/coverage.xml
4040
env:
4141
USE_MOCKING: ${{ vars.USE_MOCKING }}
4242
SHOW_MOCKING_LOGS: ${{ vars.SHOW_MOCKING_LOGS }}
4343
- name: Find coverage files and generate report
4444
run: |
45-
dotnet tool run reportgenerator -reports:"${{ github.workspace }}/**/coverage.xml" \
45+
dotnet tool run reportgenerator -reports:"${{ github.workspace }}/test-results/**/*cobertura.xml" \
4646
-targetdir:"coverage-report" \
4747
-reporttypes:MarkdownSummaryGithub
4848
- name: Upload coverage report

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ bld/
2626
[Ll]ogs/
2727

2828
# Coverage
29-
[Cc]overagereport
30-
coverage.*.xml
29+
[Cc]overage-report
30+
*coverage.*.xml
31+
*cobertura.xml
3132

3233
# PDFs
3334
*.pdf

coverage.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
dotnet test -c Debug --no-restore --no-build -- --coverage --coverage-output-format xml --coverage-output coverage.xml
1+
dotnet test -c Release --settings coverage.runsettings --results-directory test-results
22

3-
$coverageFiles = Get-ChildItem -Path "tests" -Recurse -Filter "coverage.xml"
3+
$coverageFiles = Get-ChildItem -Path "test-results" -Recurse -Filter "*cobertura.xml"
44

55
if ($coverageFiles) {
66
$reportFiles = ($coverageFiles | ForEach-Object { $_.FullName }) -join ";"
7-
dotnet tool run reportgenerator -reports:$reportFiles -targetdir:coveragereport
7+
dotnet tool run reportgenerator -reports:$reportFiles -targetdir:coverage-report
88

9-
Start-Process "coveragereport/index.html"
9+
Start-Process "coverage-report/index.html"
1010
} else {
1111
Write-Host "Coverage reports not found."
1212
}
1313

14-
Get-ChildItem -Path "tests" -Recurse -Filter "TestResults" | ForEach-Object { Remove-Item -Recurse -Force -Path $_.FullName }
14+
Get-ChildItem -Path "test-results" -Recurse | ForEach-Object { Remove-Item -Recurse -Force -Path $_.FullName }

coverage.runsettings

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RunSettings>
3+
<DataCollectionRunSettings>
4+
<DataCollectors>
5+
<DataCollector friendlyName="Code Coverage">
6+
<Configuration>
7+
<Format>cobertura</Format>
8+
<Include>
9+
<ModulePath>.*[\\/]src[\\/].*\.dll$</ModulePath>
10+
</Include>
11+
<Exclude>
12+
<ModulePath>.*Microsoft.*</ModulePath>
13+
<ModulePath>.*System.*</ModulePath>
14+
<ModulePath>.*Docker.*</ModulePath>
15+
<ModulePath>.*Testcontainers.*</ModulePath>
16+
<ModulePath>.*xunit.*</ModulePath>
17+
</Exclude>
18+
</Configuration>
19+
</DataCollector>
20+
</DataCollectors>
21+
</DataCollectionRunSettings>
22+
</RunSettings>

0 commit comments

Comments
 (0)