Skip to content

Commit 387858f

Browse files
authored
fix(dev): Actually report code coverage (#231)
* chore: Update test projects to use MSTest.Sdk and remove unnecessary package references * ci: Update test command in GitHub Actions to use MSTest.Sdk * ci: Enhance test command in GitHub Actions to include Cobertura format and convert results to JUnit * ci: Add trx2junit for GitHub Actions build
1 parent 8275905 commit 387858f

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"trx2junit": {
6+
"version": "2.1.0",
7+
"commands": [
8+
"trx2junit"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

.github/workflows/dotnet.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,26 @@ jobs:
2626
uses: actions/setup-dotnet@v4
2727
with:
2828
global-json-file: global.json
29+
- name: Restore tools
30+
run: dotnet tool restore
2931
- name: Restore dependencies
3032
run: dotnet restore --locked-mode
3133
- name: Build
3234
run: dotnet build --no-restore
3335
- name: Test
34-
run: dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage"
36+
run: dotnet test --no-build --verbosity normal -p:TestingPlatformCommandLineArguments="--report-trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml"
37+
- name: Convert test results
38+
if: ${{ !cancelled() }}
39+
run: |
40+
find . -name "*.trx" -exec dotnet tool run trx2junit --output TestResults/JUnit {} +
3541
- name: Upload coverage reports to Codecov
3642
uses: codecov/codecov-action@v5.1.2
3743
with:
3844
token: ${{ secrets.CODECOV_TOKEN }}
39-
slug: hangy/AntiXss/hangy/AntiXss
45+
slug: hangy/AntiXss
4046
- name: Upload test results to Codecov
4147
if: ${{ !cancelled() }}
4248
uses: codecov/test-results-action@v1
4349
with:
50+
files: TestResults/JUnit/*.xml
4451
token: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="MSTest.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net9.0</TargetFramework>
44
<RootNamespace>Microsoft.Security.Application.Tests</RootNamespace>
55
<AssemblyTitle>AntiXSS Unit Tests</AssemblyTitle>
66
<AssemblyDescription>Unit Tests for the AntiXSS Library</AssemblyDescription>
7-
<IsTestProject>true</IsTestProject>
7+
<TestingExtensionsProfile>AllMicrosoft</TestingExtensionsProfile>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<ProjectReference Include="..\Microsoft.Security.Application.Encoder\Microsoft.Security.Application.Encoder.csproj" />
1212
</ItemGroup>
13-
14-
<ItemGroup>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
16-
<PackageReference Include="MSTest.TestAdapter" Version="3.8.2" />
17-
<PackageReference Include="MSTest.TestFramework" Version="3.8.2" />
18-
</ItemGroup>
1913
</Project>
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="MSTest.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net9.0</TargetFramework>
44
<RootNamespace>Microsoft.Security.Application.HtmlSanitization.Tests</RootNamespace>
55
<AssemblyName>Microsoft.Security.Application.HtmlSanitization.Tests</AssemblyName>
6-
<IsTestProject>true</IsTestProject>
6+
<TestingExtensionsProfile>AllMicrosoft</TestingExtensionsProfile>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<ProjectReference Include="..\Microsoft.Security.Application.HtmlSanitization\Microsoft.Security.Application.HtmlSanitization.csproj" />
1111
</ItemGroup>
12-
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
15-
<PackageReference Include="MSTest.TestAdapter" Version="3.8.2" />
16-
<PackageReference Include="MSTest.TestFramework" Version="3.8.2" />
17-
</ItemGroup>
1812
</Project>

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"sdk": {
33
"version": "9.0.200",
44
"rollForward": "latestFeature"
5+
},
6+
"msbuild-sdks": {
7+
"MSTest.Sdk": "3.8.2"
58
}
69
}

0 commit comments

Comments
 (0)