Skip to content

Commit 69d204e

Browse files
committed
Use xUnit v3 through Microsoft Testing Platform
Remaining issues * GitHub action: how to replace GitHubActionsTestLogger? See microsoft/testfx#4365 * HTML logger: could not find an equivalent for Microsoft.Testing.Platform * Stryker: does not support xunit v3, even if we add back the `Microsoft.NET.Test.Sdk` and `xunit.runner.visualstudio` packages. See stryker-mutator/stryker-net#3117
1 parent 0c86246 commit 69d204e

2 files changed

Lines changed: 31 additions & 30 deletions

File tree

tests/Serilog.Formatting.Log4Net.Tests.csproj

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

33
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
45
<TargetFramework>net8.0</TargetFramework>
56
<Nullable>enable</Nullable>
67
</PropertyGroup>
78

89
<ItemGroup>
910
<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" />
11+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.1.0" />
12+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="2.0.2" />
1213
<PackageReference Include="PublicApiGenerator" Version="11.5.4" />
1314
<PackageReference Include="ReportGenerator" Version="5.5.1" PrivateAssets="all" />
1415
<PackageReference Include="Serilog" Version="4.3.0" />
1516
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
1617
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
1718
<PackageReference Include="Verify" Version="31.9.0" GeneratePathProperty="true" />
1819
<PackageReference Include="Verify.XunitV3" Version="31.9.0" />
19-
<PackageReference Include="xunit.v3" Version="3.2.1" />
20-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all" />
20+
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.1" />
2121
</ItemGroup>
2222

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>
23+
<PropertyGroup Label="xUnit">
24+
<!-- UseMicrosoftTestingPlatformRunner is required for JetBrains Rider to see the tests -->
25+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
26+
<!-- TestingPlatformDotnetTestSupport is ignored with the .NET 10 SDK but is required for older SDKs -->
27+
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
28+
</PropertyGroup>
2729

2830
<PropertyGroup Label="Coverage">
2931
<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>
32+
<CoverageReportDirectory>$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(RootDirectory),'coverage',$(TargetFramework)))))</CoverageReportDirectory>
33+
<CoverageReportFile>$([System.IO.Path]::Combine($(CoverageReportDirectory),'$(MSBuildProjectName).cobertura.xml'))</CoverageReportFile>
34+
<ArgsCoverage>--coverage --coverage-output-format cobertura --coverage-output $(CoverageReportFile) --coverage-settings coverage.xml</ArgsCoverage>
35+
<ArgsTrx Condition="$(ContinuousIntegrationBuild) == 'true'"> --report-trx --report-trx-filename $(MSBuildProjectName).trx --results-directory $(RootDirectory)</ArgsTrx>
36+
<TestingPlatformCommandLineArguments>$(ArgsCoverage)$(ArgsTrx)</TestingPlatformCommandLineArguments>
3537
</PropertyGroup>
3638

37-
<Target Name="GenerateHtmlCoverageReport" AfterTargets="VSTest" Condition="$(TargetFramework) != ''">
39+
<Target Name="GenerateCoverageReports" AfterTargets="VSTest" Condition="$(TargetFramework) != ''">
3840
<ItemGroup>
39-
<CoverageReport Include="$(VSTestResultsDirectory)/*/coverage.cobertura.xml" />
41+
<CoverageReport Include="$(CoverageReportDirectory)/*.cobertura.xml" />
4042
</ItemGroup>
4143
<ReportGenerator ReportFiles="@(CoverageReport)" TargetDirectory="$(CoverageReportDirectory)" ReportTypes="HtmlInline;TextSummary" />
4244
</Target>
4345

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) != ''">
46+
<Target Name="DisplayCoverageSummary" AfterTargets="GenerateCoverageReports" Condition="$(TargetFramework) != ''">
5747
<PropertyGroup>
5848
<CatCommand Condition="!$([MSBuild]::IsOSPlatform('Windows'))">cat</CatCommand>
5949
<CatCommand Condition="$([MSBuild]::IsOSPlatform('Windows'))">type</CatCommand>
6050
</PropertyGroup>
6151
<Exec WorkingDirectory="$(CoverageReportDirectory)" Command="$(CatCommand) Summary.txt" />
6252
</Target>
63-
64-
<Target Name="OpenHtmlCoverageReport" AfterTargets="MoveCoverageReport" Condition="$(TargetFramework) != '' AND $(ContinuousIntegrationBuild) != 'true'">
53+
54+
<Target Name="OpenHtmlCoverageReport" AfterTargets="DisplayCoverageSummary" Condition="$(TargetFramework) != '' AND $(ContinuousIntegrationBuild) != 'true'">
6555
<PropertyGroup>
6656
<OpenCommand Condition="$([MSBuild]::IsOSPlatform('Linux'))">xdg-open</OpenCommand>
6757
<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)