Skip to content

Commit 61072e4

Browse files
authored
infra: add Coverlet for code coverage in tests (#328)
1 parent 693635a commit 61072e4

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

.config/dotnet-tools.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"commands": [
1414
"NuGetKeyVaultSignTool"
1515
]
16+
},
17+
"dotnet-reportgenerator-globaltool": {
18+
"version": "4.4.0",
19+
"commands": [
20+
"reportgenerator"
21+
]
1622
}
1723
}
1824
}

azure-pipelines.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ jobs:
4242
env:
4343
KEYVAULT_CLIENT_SECRET: $(kv-access-token)
4444
- task: PublishTestResults@2
45-
displayName: Upload test results
45+
displayName: Publish test results
4646
condition: always()
4747
continueOnError: true
4848
inputs:
4949
testRunTitle: $(vmImage)
5050
testRunner: vstest
5151
testResultsFiles: '**/*.trx'
52+
- task: PublishCodeCoverageResults@1
53+
displayName: Publish code coverage results
54+
inputs:
55+
codeCoverageTool: cobertura
56+
summaryFileLocation: coverlet/reports/Cobertura.xml
5257
- publish: artifacts/
5358
artifact: Packages
5459
displayName: Publish artifacts

build.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ if (-not (Test-Path variable:\IsCoreCLR)) {
4242
$CodeSign = $sign -or ($ci -and -not $isPr -and $IsWindows)
4343

4444
if ($CodeSign) {
45-
exec dotnet tool restore
4645
$MSBuildArgs += '-p:CodeSign=true'
4746
}
4847

4948
$artifacts = "$PSScriptRoot/artifacts/"
5049

5150
Remove-Item -Recurse $artifacts -ErrorAction Ignore
5251

52+
exec dotnet tool restore
5353
exec dotnet build --configuration $Configuration '-warnaserror:CS1591' @MSBuildArgs
5454
exec dotnet pack --no-restore --no-build --configuration $Configuration -o $artifacts @MSBuildArgs
5555
exec dotnet build --configuration $Configuration "$PSScriptRoot/docs/samples/samples.sln"
@@ -63,7 +63,15 @@ if ($env:TF_BUILD) {
6363
}
6464

6565
exec dotnet test --no-restore --no-build --configuration $Configuration `
66+
--collect:"XPlat Code Coverage" `
6667
@testArgs `
6768
@MSBuildArgs
6869

70+
if ($ci) {
71+
exec dotnet tool run reportgenerator `
72+
"-reports:$PSScriptRoot/**/coverage.cobertura.xml" `
73+
"-targetdir:$PSScriptRoot/coverlet/reports" `
74+
"-reporttypes:Cobertura"
75+
}
76+
6977
write-host -f magenta 'Done'

test/CommandLineUtils.Tests/McMaster.Extensions.CommandLineUtils.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17+
<PackageReference Include="coverlet.collector" Version="1.1.0" />
1718
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
1819
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
1920
<PackageReference Include="FluentAssertions" Version="5.9.0" />

test/Hosting.CommandLine.Tests/McMaster.Extensions.Hosting.CommandLine.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17+
<PackageReference Include="coverlet.collector" Version="1.1.0" />
1718
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
1819
<PackageReference Include="Moq" Version="4.13.1" />
1920
<PackageReference Include="xunit" Version="2.4.1" />

0 commit comments

Comments
 (0)