Skip to content

Commit 5ddc479

Browse files
[CORELIB-342] Switch to XUnit v3 and MTP
1 parent 4ce8124 commit 5ddc479

7 files changed

Lines changed: 64 additions & 74 deletions

File tree

.config/dotnet-tools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"csharpier"
99
],
1010
"rollForward": false
11+
},
12+
"dotnet-coverage": {
13+
"version": "18.1.0",
14+
"commands": [
15+
"dotnet-coverage"
16+
],
17+
"rollForward": false
1118
}
1219
}
1320
}

.github/workflows/ci.yml

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ jobs:
1212
env:
1313
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
1414
DOTNET_CLI_TELEMETRY_OPTOUT: 1
15+
permissions:
16+
contents: read
17+
checks: write
18+
pull-requests: write
1519
steps:
1620
- name: Checkout
17-
uses: actions/checkout@v2
21+
uses: actions/checkout@v4
1822
with:
1923
lfs: true
2024
- name: Setup .NET SDK
21-
uses: actions/setup-dotnet@v3
25+
uses: actions/setup-dotnet@v4
2226
with:
2327
dotnet-version: |
2428
8.0.x
@@ -31,44 +35,39 @@ jobs:
3135
- name: Check formatting
3236
run: dotnet tool run csharpier -- check .
3337
- name: Build
34-
run: dotnet build --framework net${{ matrix.dotnet }}
38+
run: dotnet build --framework net${{ matrix.dotnet }} --no-restore
3539
- name: Test
36-
run: dotnet test --no-build --collect "XPlat Code Coverage" --settings coverlet.runsettings --logger trx --framework net${{ matrix.dotnet }}
40+
run: >
41+
dotnet test
42+
--project src/LeanCode.ContractsGenerator.Tests/LeanCode.ContractsGenerator.Tests.csproj
43+
--no-build
44+
--framework net${{ matrix.dotnet }}
45+
- name: Process test results
46+
if: always()
47+
run: |
48+
# Strip BOM from JSON files
49+
find TestResults -name '*.json' | xargs -n 1 sed -i "$(printf '1s/^\357\273\277//')"
50+
# Merge coverage XML files
51+
dotnet tool run dotnet-coverage merge TestResults/*.xml -o TestResults/cobertura.xml -f cobertura
3752
- name: Upload coverage to Codecov
38-
uses: codecov/codecov-action@v3
53+
uses: codecov/codecov-action@v5
3954
with:
55+
token: ${{ secrets.CODECOV_TOKEN }}
56+
files: TestResults/cobertura.xml
4057
flags: net${{ matrix.dotnet }}
58+
fail_ci_if_error: false
4159
if: always()
42-
- name: Upload Test Results
60+
- name: Publish test report
61+
uses: ctrf-io/github-test-reporter@v1
4362
if: always()
44-
uses: actions/upload-artifact@v4
45-
with:
46-
name: test_results_${{ matrix.dotnet }}.zip
47-
path: TestResults/*.trx
48-
49-
publish-test-results:
50-
name: "Publish Tests Results"
51-
needs: ci
52-
runs-on: ubuntu-latest
53-
permissions:
54-
checks: write
55-
pull-requests: write
56-
if: always()
57-
steps:
58-
- name: Download Artifacts
59-
uses: actions/download-artifact@v4
60-
with:
61-
path: artifacts
62-
- name: Extract Artifacts
63-
run: |
64-
for file in artifacts/*.zip; do
65-
if [[ -f "$file" ]]; then
66-
dir="${file%.zip}"
67-
mkdir -p "$dir"
68-
unzip -d "$dir" "$file"
69-
fi
70-
done
71-
- name: Publish Test Results
72-
uses: EnricoMi/publish-unit-test-result-action@v2
7363
with:
74-
trx_files: "artifacts/*/**/*.trx"
64+
report-path: 'TestResults/*.json'
65+
summary-report: true
66+
failed-folded-report: true
67+
skipped-report: true
68+
annotate: true
69+
pull-request: true
70+
overwrite-comment: true
71+
comment-tag: 'net${{ matrix.dotnet }}'
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
steps:
1515
- name: Get the version
1616
id: get_version
17-
run: echo ::set-output name=version::$(echo $GITHUB_REF | cut -d / -f 3 | cut -c2-)
17+
run: echo "version=$(echo $GITHUB_REF | cut -d / -f 3 | cut -c2-)" >> $GITHUB_OUTPUT
1818
- name: Checkout
19-
uses: actions/checkout@v2
19+
uses: actions/checkout@v4
2020
with:
2121
lfs: true
2222
- name: Setup .NET SDK
23-
uses: actions/setup-dotnet@v3
23+
uses: actions/setup-dotnet@v4
2424
with:
2525
dotnet-version: |
2626
8.0.x
@@ -35,7 +35,11 @@ jobs:
3535
- name: Test
3636
env:
3737
BUILD_VERSION: ${{ steps.get_version.outputs.version }}
38-
run: dotnet test --no-build --configuration Release
38+
run: >
39+
dotnet test
40+
--project src/LeanCode.ContractsGenerator.Tests/LeanCode.ContractsGenerator.Tests.csproj
41+
--no-build
42+
--configuration Release
3943
- name: Publish
4044
env:
4145
BUILD_VERSION: ${{ steps.get_version.outputs.version }}

Directory.Build.targets

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@
3737
<PackageReference Include="LeanCode.CodeAnalysis" Version="$(LncdCaVer)" PrivateAssets="all" />
3838
</ItemGroup>
3939
<ItemGroup>
40-
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="18.0.1" />
41-
<PackageReference Update="xunit" Version="2.9.3" />
42-
<PackageReference Update="xunit.analyzers" Version="1.21.0" />
43-
<PackageReference Update="xunit.runner.visualstudio" Version="3.1.0" />
40+
<PackageReference Update="Microsoft.Testing.Extensions.CodeCoverage" Version="18.1.0" />
41+
<PackageReference Update="xunit.v3.mtp-v2" Version="3.2.0" />
42+
<PackageReference Update="xunit.analyzers" Version="1.25.0" />
4443
<PackageReference Update="FluentAssertions" Version="7.2.0" />
45-
<PackageReference Update="coverlet.collector" Version="6.0.4" />
4644
<!-- Use latest NuGet.Frameworks available at build time for tests
4745
to make sure we don't reference anything older than what current MSBuild uses -->
4846
<PackageReference Update="NuGet.Frameworks" Version="*" />

coverlet.runsettings

Lines changed: 0 additions & 19 deletions
This file was deleted.

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"version": "10.0.100",
44
"allowPrerelease": true,
55
"rollForward": "latestMajor"
6+
},
7+
"test": {
8+
"runner": "Microsoft.Testing.Platform"
69
}
710
}

src/LeanCode.ContractsGenerator.Tests/LeanCode.ContractsGenerator.Tests.csproj

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
44
<PreserveCompilationContext>true</PreserveCompilationContext>
55
<IsPackable>false</IsPackable>
6+
<OutputType>Exe</OutputType>
7+
</PropertyGroup>
8+
<PropertyGroup>
9+
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
10+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
11+
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --report-ctrf --coverage --ignore-exit-code 8 --results-directory $(MSBuildThisFileDirectory)/../../TestResults --coverage-output-format cobertura --report-ctrf-filename $(MSBuildProjectName)-$([System.DateTime]::Now.ToString("HH-mm-ss")).json --coverage-output $(MSBuildProjectName)-$([System.DateTime]::Now.ToString("HH-mm-ss")).xml</TestingPlatformCommandLineArguments>
612
</PropertyGroup>
713
<Target Name="PackDependenciesForTests" BeforeTargets="AfterBuild">
814
<Message Text="Packing the LeanCode.Contracts" Importance="high" />
@@ -28,18 +34,10 @@
2834
</Content>
2935
</ItemGroup>
3036
<ItemGroup>
31-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
32-
<PackageReference Include="xunit" />
37+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
38+
<PackageReference Include="xunit.v3.mtp-v2" />
3339
<PackageReference Include="xunit.analyzers" />
34-
<PackageReference Include="xunit.runner.visualstudio">
35-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
36-
<PrivateAssets>all</PrivateAssets>
37-
</PackageReference>
3840
<PackageReference Include="FluentAssertions" />
39-
<PackageReference Include="coverlet.collector">
40-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
41-
<PrivateAssets>all</PrivateAssets>
42-
</PackageReference>
4341
<!-- workaround for MSBuild trying to load multiple versions of this package into the process -->
4442
<PackageReference Include="NuGet.Frameworks" PrivateAssets="all" />
4543
</ItemGroup>

0 commit comments

Comments
 (0)