Skip to content

Commit 11a8e5a

Browse files
committedJun 16, 2025·
Experiment with using TUnit instead of xUnit
Remaining issues * TUnit provides a very basic [GitHub summary reporter][1] out of the box, but the more feature complete GitHubActionsTestLogger is currently [not supported for Microsoft.Testing.Platform][2] * HTML logger: could not find an equivalent for Microsoft.Testing.Platform * Stryker: currently [not supported for Microsoft.Testing.Platform][3] [1]: https://github.com/thomhurst/TUnit/blob/f857682f30e767df0f352fc2f5218c6fb5127ed3/TUnit.Engine/Reporters/GitHubReporter.cs [2]: Tyrrrz/GitHubActionsTestLogger#41 [3]: stryker-mutator/stryker-net#3094
1 parent d0b993e commit 11a8e5a

File tree

6 files changed

+124
-147
lines changed

6 files changed

+124
-147
lines changed
 

‎.github/workflows/continuous-integration.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
if: matrix.os == 'ubuntu-latest' && env.CODECOV_TOKEN != ''
7171
uses: codecov/codecov-action@v5
7272
with:
73-
files: coverage/*/coverage.cobertura.xml
73+
files: coverage/*/*.cobertura.xml
7474
token: ${{ env.CODECOV_TOKEN }}
7575
- name: ☂️ Upload coverage report to Codacy
7676
env:
@@ -79,7 +79,7 @@ jobs:
7979
uses: codacy/codacy-coverage-reporter-action@v1
8080
with:
8181
project-token: ${{ env.CODACY_PROJECT_TOKEN }}
82-
coverage-reports: coverage/*/coverage.cobertura.xml
82+
coverage-reports: coverage/*/*.cobertura.xml
8383
- name: 📦 Create NuGet package
8484
run: dotnet pack --no-build --output .
8585
- name: 📤 Upload NuGet package artifact
@@ -91,7 +91,7 @@ jobs:
9191
- name: 👽 Run mutation tests and upload report to Stryker dashboard
9292
env:
9393
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
94-
if: matrix.os == 'ubuntu-latest' && env.STRYKER_DASHBOARD_API_KEY != ''
94+
if: matrix.os == 'DISABLED' && env.STRYKER_DASHBOARD_API_KEY != ''
9595
run: |
9696
dotnet tool restore
9797
dotnet tool run dotnet-stryker --reporter dashboard --open-report:dashboard --version ${GITHUB_REF_NAME} --dashboard-api-key ${{ env.STRYKER_DASHBOARD_API_KEY }}

‎tests/IndentationSettingsTest.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using System;
22
using AwesomeAssertions;
3-
using Xunit;
43

54
namespace Serilog.Formatting.Log4Net.Tests;
65

76
public class IndentationSettingsTest
87
{
9-
[Theory]
10-
[InlineData(Indentation.Space, 2, " ")]
11-
[InlineData(Indentation.Tab, 2, "\t\t")]
12-
[InlineData(Indentation.Space, 4, " ")]
13-
[InlineData(Indentation.Tab, 4, "\t\t\t\t")]
8+
[Test]
9+
[Arguments(Indentation.Space, (byte)2, " ")]
10+
[Arguments(Indentation.Tab, (byte)2, "\t\t")]
11+
[Arguments(Indentation.Space, (byte)4, " ")]
12+
[Arguments(Indentation.Tab, (byte)4, "\t\t\t\t")]
1413
public void IndentationSettingsToString(Indentation indentation, byte size, string expectedString)
1514
{
1615
// Arrange
@@ -23,7 +22,7 @@ public void IndentationSettingsToString(Indentation indentation, byte size, stri
2322
indentationString.Should().Be(expectedString);
2423
}
2524

26-
[Fact]
25+
[Test]
2726
public void InvalidIndentation()
2827
{
2928
// Act
@@ -34,7 +33,7 @@ public void InvalidIndentation()
3433
.Which.Message.Should().StartWith("The value of argument 'indentation' (-1) is invalid for enum type 'Indentation'.");
3534
}
3635

37-
[Fact]
36+
[Test]
3837
public void InvalidSize()
3938
{
4039
// Act

‎tests/LineEndingTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
22
using AwesomeAssertions;
3-
using Xunit;
43

54
namespace Serilog.Formatting.Log4Net.Tests;
65

76
public class LineEndingTest
87
{
9-
[Fact]
8+
[Test]
109
public void InvalidLineEnding()
1110
{
1211
Action action = () => _ = new Log4NetTextFormatter(c => c.UseLineEnding((LineEnding)4));

‎tests/Log4NetTextFormatterTest.cs

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

‎tests/PublicApi.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
1+
using System.Collections.Generic;
12
using System.IO;
23
using System.Reflection;
34
using System.Runtime.CompilerServices;
45
using System.Threading.Tasks;
56
using System.Xml.Linq;
67
using System.Xml.XPath;
78
using PublicApiGenerator;
8-
using VerifyXunit;
9-
using Xunit;
9+
using VerifyTUnit;
1010

1111
namespace Serilog.Formatting.Log4Net.Tests;
1212

1313
public class PublicApi
1414
{
15-
[Theory]
16-
[ClassData(typeof(TargetFrameworksTheoryData))]
15+
[Test]
16+
[MethodDataSource(nameof(GetTargetFrameworks))]
1717
public Task ApprovePublicApi(string targetFramework)
1818
{
1919
var testAssembly = typeof(PublicApi).Assembly;
2020
var configuration = testAssembly.GetCustomAttribute<AssemblyConfigurationAttribute>()?.Configuration
2121
?? throw new InvalidDataException($"{nameof(AssemblyConfigurationAttribute)} not found in {testAssembly.Location}");
2222
var assemblyPath = Path.Combine(GetSrcDirectoryPath(), "bin", configuration, targetFramework, "Serilog.Formatting.Log4Net.dll");
23-
var assembly = Assembly.LoadFile(assemblyPath);
23+
var assembly = System.Reflection.Assembly.LoadFile(assemblyPath);
2424
var publicApi = assembly.GeneratePublicApi();
2525
return Verifier.Verify(publicApi, "cs").UseFileName($"PublicApi.{targetFramework}");
2626
}
2727

2828
private static string GetSrcDirectoryPath([CallerFilePath] string path = "") => Path.Combine(Path.GetDirectoryName(path)!, "..", "src");
2929

30-
private class TargetFrameworksTheoryData : TheoryData<string>
30+
public static IEnumerable<string> GetTargetFrameworks()
3131
{
32-
public TargetFrameworksTheoryData()
33-
{
34-
var csprojPath = Path.Combine(GetSrcDirectoryPath(), "Serilog.Formatting.Log4Net.csproj");
35-
var project = XDocument.Load(csprojPath);
36-
var targetFrameworks = project.XPathSelectElement("/Project/PropertyGroup/TargetFrameworks")
37-
?? throw new InvalidDataException($"TargetFrameworks element not found in {csprojPath}");
38-
AddRange(targetFrameworks.Value.Split(';'));
39-
}
32+
var csprojPath = Path.Combine(GetSrcDirectoryPath(), "Serilog.Formatting.Log4Net.csproj");
33+
var project = XDocument.Load(csprojPath);
34+
var targetFrameworks = project.XPathSelectElement("/Project/PropertyGroup/TargetFrameworks")
35+
?? throw new InvalidDataException($"TargetFrameworks element not found in {csprojPath}");
36+
return targetFrameworks.Value.Split(';');
4037
}
4138
}

‎tests/Serilog.Formatting.Log4Net.Tests.csproj

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,42 @@
77

88
<ItemGroup>
99
<PackageReference Include="AwesomeAssertions" Version="9.0.0" />
10-
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="all" />
11-
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
10+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" />
11+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.7.2" />
1312
<PackageReference Include="PublicApiGenerator" Version="11.4.6" />
1413
<PackageReference Include="ReportGenerator" Version="5.4.8" PrivateAssets="all" />
1514
<PackageReference Include="Serilog" Version="4.3.0" />
1615
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
1716
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
18-
<PackageReference Include="Verify.Xunit" Version="30.4.0" />
19-
<PackageReference Include="xunit" Version="2.9.3" />
20-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1" PrivateAssets="all" />
21-
</ItemGroup>
22-
23-
<ItemGroup>
24-
<VSTestLogger Include="GitHubActions%3Bsummary.includePassedTests=true%3Bsummary.includeSkippedTests=true" Visible="false" Condition="$(GITHUB_STEP_SUMMARY) != ''" />
25-
<VSTestLogger Include="trx%3BLogFileName=TestResults-$(TargetFramework).trx" Visible="false" Condition="$(ContinuousIntegrationBuild) == 'true'" />
26-
<VSTestLogger Include="html%3BLogFileName=TestResults-$(TargetFramework).html" Visible="false" />
17+
<PackageReference Include="TUnit.Engine" Version="0.25.21" />
18+
<PackageReference Include="Verify.TUnit" Version="30.4.0" />
2719
</ItemGroup>
2820

2921
<PropertyGroup Label="Coverage">
3022
<RootDirectory>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</RootDirectory>
31-
<CoverageReportDirectory>$([System.IO.Path]::Combine($(RootDirectory),'coverage',$(TargetFramework)))</CoverageReportDirectory>
32-
<VSTestResultsDirectory Condition="$(ContinuousIntegrationBuild) == 'true'">$(RootDirectory)</VSTestResultsDirectory>
33-
<VSTestResultsDirectory Condition="$(ContinuousIntegrationBuild) != 'true'">$([System.IO.Path]::Combine($(CoverageReportDirectory),'results'))</VSTestResultsDirectory>
34-
<VSTestCollect>XPlat Code Coverage</VSTestCollect>
35-
<VSTestLogger>@(VSTestLogger)</VSTestLogger>
23+
<CoverageReportDirectory>$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(RootDirectory),'coverage',$(TargetFramework)))))</CoverageReportDirectory>
24+
<CoverageReportFile>$([System.IO.Path]::Combine($(CoverageReportDirectory),'$(MSBuildProjectName).cobertura.xml'))</CoverageReportFile>
25+
<ArgsCoverage>--coverage --coverage-output-format cobertura --coverage-output $(CoverageReportFile)</ArgsCoverage>
26+
<ArgsTrx Condition="$(ContinuousIntegrationBuild) == 'true'"> --report-trx --report-trx-filename $(MSBuildProjectName).trx --results-directory $(RootDirectory)</ArgsTrx>
27+
<TestingPlatformCommandLineArguments>$(ArgsCoverage)$(ArgsTrx)</TestingPlatformCommandLineArguments>
3628
</PropertyGroup>
3729

38-
<Target Name="GenerateHtmlCoverageReport" AfterTargets="VSTest" Condition="$(TargetFramework) != ''">
30+
<Target Name="GenerateCoverageReports" AfterTargets="VSTest" Condition="$(TargetFramework) != ''">
3931
<ItemGroup>
40-
<CoverageReport Include="$(VSTestResultsDirectory)/*/coverage.cobertura.xml" />
32+
<CoverageReport Include="$(CoverageReportDirectory)/*.cobertura.xml" />
4133
</ItemGroup>
4234
<ReportGenerator ReportFiles="@(CoverageReport)" TargetDirectory="$(CoverageReportDirectory)" ReportTypes="HtmlInline;TextSummary" />
4335
</Target>
4436

45-
<!-- Because of https://github.com/microsoft/vstest/issues/2378 -->
46-
<Target Name="MoveCoverageReport" AfterTargets="GenerateHtmlCoverageReport" Condition="$(TargetFramework) != ''">
47-
<Move SourceFiles="@(CoverageReport)" DestinationFolder="$(CoverageReportDirectory)" />
48-
<PropertyGroup>
49-
<CoverageReport>@(CoverageReport)</CoverageReport>
50-
</PropertyGroup>
51-
<ItemGroup>
52-
<CoverageReportParentDirectory Include="$([System.IO.Path]::Combine($(CoverageReport),'..'))" Condition="$(CoverageReport) != ''" />
53-
</ItemGroup>
54-
<RemoveDir Directories="@(CoverageReportParentDirectory)" />
55-
</Target>
56-
57-
<Target Name="DisplayCoverageSummary" AfterTargets="MoveCoverageReport" Condition="$(TargetFramework) != ''">
37+
<Target Name="DisplayCoverageSummary" AfterTargets="GenerateCoverageReports" Condition="$(TargetFramework) != ''">
5838
<PropertyGroup>
5939
<CatCommand Condition="!$([MSBuild]::IsOSPlatform('Windows'))">cat</CatCommand>
6040
<CatCommand Condition="$([MSBuild]::IsOSPlatform('Windows'))">type</CatCommand>
6141
</PropertyGroup>
6242
<Exec WorkingDirectory="$(CoverageReportDirectory)" Command="$(CatCommand) Summary.txt" />
6343
</Target>
6444

65-
<Target Name="OpenHtmlCoverageReport" AfterTargets="MoveCoverageReport" Condition="$(TargetFramework) != '' AND $(ContinuousIntegrationBuild) != 'true'">
45+
<Target Name="OpenHtmlCoverageReport" AfterTargets="DisplayCoverageSummary" Condition="$(TargetFramework) != '' AND $(ContinuousIntegrationBuild) != 'true'">
6646
<PropertyGroup>
6747
<OpenCommand Condition="$([MSBuild]::IsOSPlatform('Linux'))">xdg-open</OpenCommand>
6848
<OpenCommand Condition="$([MSBuild]::IsOSPlatform('OSX'))">open</OpenCommand>

0 commit comments

Comments
 (0)
Please sign in to comment.