Skip to content

Commit 3fc456b

Browse files
committed
Use xUnit v3 through Microsoft Testing Platform
Remaining issues * HTML logger: could not find an equivalent for Microsoft.Testing.Platform * Stryker: has early support for MTP with `dotnet stryker -t mtp` but the results are currently not 100% (which they should) * The VSTest target is not called anymore when running `dotnet test` under the .NET 10 SDK ⇒ coverage related targets are not run anymore. * Stryker should properly identify the test project without having to explicitly set the `IsTestProject` property, see stryker-mutator/stryker-net#3423
1 parent 97af47e commit 3fc456b

4 files changed

Lines changed: 44 additions & 35 deletions

File tree

.github/workflows/continuous-integration.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ jobs:
4343
- name: ⚙️ Restore NuGet packages
4444
run: dotnet restore
4545
- name: 🏗 Build solution
46-
run: dotnet build --no-restore
46+
# --configuration should not be needed, see https://github.com/dotnet/sdk/issues/52358
47+
run: dotnet build --no-restore --configuration ${{ env.Configuration }}
4748
- name: 🧪 Run tests
48-
run: dotnet test --no-build
49+
# --configuration should not be needed, see https://github.com/dotnet/sdk/issues/52358
50+
run: dotnet test --no-build --configuration ${{ env.Configuration }}
4951
- name: 📤 Upload received files from failing tests
5052
uses: actions/upload-artifact@v4
5153
if: failure()
@@ -88,7 +90,8 @@ jobs:
8890
project-token: ${{ env.CODACY_PROJECT_TOKEN }}
8991
coverage-reports: coverage/*/coverage.cobertura.xml
9092
- name: 📦 Create NuGet package
91-
run: dotnet pack --no-build --output .
93+
# --configuration should not be needed, see https://github.com/dotnet/sdk/issues/52358
94+
run: dotnet pack --no-build --output . --configuration ${{ env.Configuration }}
9295
- name: 📤 Upload NuGet package artifact
9396
if: matrix.os == 'ubuntu-latest'
9497
uses: actions/upload-artifact@v4
@@ -101,7 +104,7 @@ jobs:
101104
if: matrix.os == 'ubuntu-latest' && env.STRYKER_DASHBOARD_API_KEY != ''
102105
run: |
103106
dotnet tool restore
104-
dotnet tool run dotnet-stryker --reporter dashboard --open-report:dashboard --version ${GITHUB_REF_NAME} --dashboard-api-key ${{ env.STRYKER_DASHBOARD_API_KEY }} --configuration ${{ env.Configuration }}
107+
dotnet tool run dotnet-stryker --testrunner mtp --reporter dashboard --open-report:dashboard --version ${GITHUB_REF_NAME} --dashboard-api-key ${{ env.STRYKER_DASHBOARD_API_KEY }} --configuration ${{ env.Configuration }}
105108
- name: 📝 Retrieve release notes from tag
106109
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
107110
run: |

global.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"$schema": "https://json.schemastore.org/global",
33
"sdk": {
4-
"version": "8.0.300",
4+
"version": "10.0.100",
55
"allowPrerelease": false,
66
"rollForward": "latestFeature"
7+
},
8+
"test": {
9+
"runner": "Microsoft.Testing.Platform"
710
}
811
}

tests/Serilog.Formatting.Log4Net.Tests.csproj

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,59 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
45
<TargetFramework>net8.0</TargetFramework>
56
<Nullable>enable</Nullable>
7+
<!-- Should not be needed, see https://github.com/stryker-mutator/stryker-net/pull/3423 -->
8+
<IsTestProject>true</IsTestProject>
69
</PropertyGroup>
710

811
<ItemGroup>
912
<PackageReference Include="AwesomeAssertions" Version="9.3.0" />
10-
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="all" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
13+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.3.2" />
14+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="2.0.2" />
1215
<PackageReference Include="PublicApiGenerator" Version="11.5.4" />
1316
<PackageReference Include="ReportGenerator" Version="5.5.1" PrivateAssets="all" />
1417
<PackageReference Include="Serilog" Version="4.3.0" />
1518
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
1619
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
1720
<PackageReference Include="Verify" Version="31.10.0" GeneratePathProperty="true" />
1821
<PackageReference Include="Verify.XunitV3" Version="31.10.0" />
19-
<PackageReference Include="xunit.v3" Version="3.2.2" />
20-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all" />
22+
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" />
2123
</ItemGroup>
2224

23-
<ItemGroup>
24-
<VSTestLogger Include="trx%3BLogFileName=TestResults-$(TargetFramework).trx" Visible="false" Condition="$(ContinuousIntegrationBuild) == 'true'" />
25-
<VSTestLogger Include="html%3BLogFileName=TestResults-$(TargetFramework).html" Visible="false" />
26-
</ItemGroup>
25+
<PropertyGroup Label="xUnit">
26+
<!-- UseMicrosoftTestingPlatformRunner is required for JetBrains Rider to see the tests when discovery is configured to use metadata (Settings | Build, Execution, Deployment | Unit Testing | xUnit.net) -->
27+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
28+
<!-- TestingPlatformDotnetTestSupport is ignored with the .NET 10 SDK but is required for older SDKs -->
29+
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
30+
</PropertyGroup>
2731

2832
<PropertyGroup Label="Coverage">
2933
<RootDirectory>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</RootDirectory>
30-
<CoverageReportDirectory>$([System.IO.Path]::Combine($(RootDirectory),'coverage',$(TargetFramework)))</CoverageReportDirectory>
31-
<VSTestResultsDirectory Condition="$(ContinuousIntegrationBuild) == 'true'">$(RootDirectory)</VSTestResultsDirectory>
32-
<VSTestResultsDirectory Condition="$(ContinuousIntegrationBuild) != 'true'">$([System.IO.Path]::Combine($(CoverageReportDirectory),'results'))</VSTestResultsDirectory>
33-
<VSTestCollect>XPlat Code Coverage%3BExcludeByAttribute=GeneratedCodeAttribute</VSTestCollect>
34-
<VSTestLogger>@(VSTestLogger)</VSTestLogger>
34+
<CoverageReportDirectory>$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(RootDirectory),'coverage',$(TargetFramework)))))</CoverageReportDirectory>
35+
<CoverageReportFile>$([System.IO.Path]::Combine($(CoverageReportDirectory),'$(MSBuildProjectName).cobertura.xml'))</CoverageReportFile>
36+
<ArgsCoverage>--coverage --coverage-output-format cobertura --coverage-output $(CoverageReportFile) --coverage-settings $([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(MSBuildThisFileDirectory), 'coverage.xml'))))</ArgsCoverage>
37+
<ArgsTrx Condition="$(ContinuousIntegrationBuild) == 'true'"> --report-trx --report-trx-filename $(MSBuildProjectName).trx --results-directory $(RootDirectory)</ArgsTrx>
38+
<TestingPlatformCommandLineArguments>$(ArgsCoverage)$(ArgsTrx)</TestingPlatformCommandLineArguments>
3539
</PropertyGroup>
3640

37-
<Target Name="GenerateHtmlCoverageReport" AfterTargets="VSTest" Condition="$(TargetFramework) != ''">
41+
<Target Name="GenerateCoverageReports" AfterTargets="VSTest" Condition="$(TargetFramework) != ''">
3842
<ItemGroup>
39-
<CoverageReport Include="$(VSTestResultsDirectory)/*/coverage.cobertura.xml" />
43+
<CoverageReport Include="$(CoverageReportDirectory)/*.cobertura.xml" />
4044
</ItemGroup>
4145
<ReportGenerator ReportFiles="@(CoverageReport)" TargetDirectory="$(CoverageReportDirectory)" ReportTypes="HtmlInline;TextSummary" />
4246
</Target>
4347

44-
<!-- Because of https://github.com/microsoft/vstest/issues/2378 -->
45-
<Target Name="MoveCoverageReport" AfterTargets="GenerateHtmlCoverageReport" Condition="$(TargetFramework) != ''">
46-
<Move SourceFiles="@(CoverageReport)" DestinationFolder="$(CoverageReportDirectory)" />
47-
<PropertyGroup>
48-
<CoverageReport>@(CoverageReport)</CoverageReport>
49-
</PropertyGroup>
50-
<ItemGroup>
51-
<CoverageReportParentDirectory Include="$([System.IO.Path]::Combine($(CoverageReport),'..'))" Condition="$(CoverageReport) != ''" />
52-
</ItemGroup>
53-
<RemoveDir Directories="@(CoverageReportParentDirectory)" />
54-
</Target>
55-
56-
<Target Name="DisplayCoverageSummary" AfterTargets="MoveCoverageReport" Condition="$(TargetFramework) != ''">
48+
<Target Name="DisplayCoverageSummary" AfterTargets="GenerateCoverageReports" Condition="$(TargetFramework) != ''">
5749
<PropertyGroup>
5850
<CatCommand Condition="!$([MSBuild]::IsOSPlatform('Windows'))">cat</CatCommand>
5951
<CatCommand Condition="$([MSBuild]::IsOSPlatform('Windows'))">type</CatCommand>
6052
</PropertyGroup>
6153
<Exec WorkingDirectory="$(CoverageReportDirectory)" Command="$(CatCommand) Summary.txt" />
6254
</Target>
63-
64-
<Target Name="OpenHtmlCoverageReport" AfterTargets="MoveCoverageReport" Condition="$(TargetFramework) != '' AND $(ContinuousIntegrationBuild) != 'true'">
55+
56+
<Target Name="OpenHtmlCoverageReport" AfterTargets="DisplayCoverageSummary" Condition="$(TargetFramework) != '' AND $(ContinuousIntegrationBuild) != 'true'">
6557
<PropertyGroup>
6658
<OpenCommand Condition="$([MSBuild]::IsOSPlatform('Linux'))">xdg-open</OpenCommand>
6759
<OpenCommand Condition="$([MSBuild]::IsOSPlatform('OSX'))">open</OpenCommand>

tests/coverage.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-coverage#settings -->
3+
<Configuration>
4+
<CodeCoverage>
5+
<Attributes>
6+
<Exclude>
7+
<Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
8+
</Exclude>
9+
</Attributes>
10+
</CodeCoverage>
11+
</Configuration>

0 commit comments

Comments
 (0)