From 61bb9a0482f1454364e4f80821329fa4fcbc9a18 Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Sat, 20 Dec 2025 11:43:06 +0530 Subject: [PATCH 1/5] feat: use MTP v2 in testlogger --- Directory.Packages.props | 2 +- src/TestLogger.MTPv1/TestLogger.MTPv1.csproj | 27 ++++++++++++++++++++ src/TestLogger/TestReporter.cs | 8 ++++++ testlogger.slnx | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/TestLogger.MTPv1/TestLogger.MTPv1.csproj diff --git a/Directory.Packages.props b/Directory.Packages.props index 8881283..a76538e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,7 +5,7 @@ - + diff --git a/src/TestLogger.MTPv1/TestLogger.MTPv1.csproj b/src/TestLogger.MTPv1/TestLogger.MTPv1.csproj new file mode 100644 index 0000000..4178efe --- /dev/null +++ b/src/TestLogger.MTPv1/TestLogger.MTPv1.csproj @@ -0,0 +1,27 @@ + + + + + netstandard2.0 + Spekt.TestLogger + $(PackageVersion) + true + embedded + true + $(DefineConstants);MTP_V1 + + + + Spekt.TestLogger + + + + + + + + + + + + diff --git a/src/TestLogger/TestReporter.cs b/src/TestLogger/TestReporter.cs index 8c1d551..5a97531 100644 --- a/src/TestLogger/TestReporter.cs +++ b/src/TestLogger/TestReporter.cs @@ -87,14 +87,22 @@ public Task IsEnabledAsync() return Task.FromResult(isEnabled); } +#if MTP_V1 public Task OnTestSessionStartingAsync(SessionUid sessionUid, CancellationToken cancellationToken) +#else + public Task OnTestSessionStartingAsync(ITestSessionContext testSessionContext) +#endif { var assembly = Assembly.GetEntryAssembly(); ((TestRun)this.testRun).RunConfiguration = this.testRun.Start(assembly.Location, assembly.GetCustomAttribute()?.FrameworkName ?? "unknown-targetframework"); return Task.CompletedTask; } +#if MTP_V1 public Task OnTestSessionFinishingAsync(SessionUid sessionUid, CancellationToken cancellationToken) +#else + public Task OnTestSessionFinishingAsync(ITestSessionContext testSessionContext) +#endif { this.testRun.Complete(this.testAttachmentInfos); return Task.CompletedTask; diff --git a/testlogger.slnx b/testlogger.slnx index 9145f73..bbb7855 100644 --- a/testlogger.slnx +++ b/testlogger.slnx @@ -9,6 +9,7 @@ + From e359bbdd200f2308551bd95e7524b15c90293673 Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Sat, 20 Dec 2025 13:41:40 +0530 Subject: [PATCH 2/5] fix: partial fix for tests in mtp v2 --- test/TestLogger.Fixtures/DotnetTestFixture.cs | 26 ++++++++++++++----- test/assets/Directory.Build.props | 6 +++-- test/assets/global.json | 5 ++++ test/assets/global.json.template | 5 ++++ 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 test/assets/global.json create mode 100644 test/assets/global.json.template diff --git a/test/TestLogger.Fixtures/DotnetTestFixture.cs b/test/TestLogger.Fixtures/DotnetTestFixture.cs index 85d105d..e0f02af 100644 --- a/test/TestLogger.Fixtures/DotnetTestFixture.cs +++ b/test/TestLogger.Fixtures/DotnetTestFixture.cs @@ -57,9 +57,12 @@ public string Execute(string assemblyName, string loggerArgs, bool collectCovera cleanProcess.WaitForExit(); } - if (!isMTP) + // Clean up global.json to allow running both VSTest and MTP tests in the same build + var globalJsonTemplate = Path.Combine(assemblyName.ToAssetDirectoryPath(), "..", "global.json.template"); + var globalJsonPath = Path.Combine(assemblyName.ToAssetDirectoryPath(), "..", "global.json"); + if (File.Exists(globalJsonPath)) { - loggerArgs = $"--logger:\"{loggerArgs}\""; + File.Delete(globalJsonPath); } var resultsDirectory = Path.Combine(assemblyName.ToAssetDirectoryPath(), this.relativeResultsDirectory); @@ -71,27 +74,36 @@ public string Execute(string assemblyName, string loggerArgs, bool collectCovera // Run dotnet test with logger var buildArgs = this.buildProject ? string.Empty : "--no-build"; + var resultDirectoryArgs = string.IsNullOrEmpty(this.relativeResultsDirectory) ? string.Empty : $"--results-directory \"{resultsDirectory}\""; + if (isMTP) { buildArgs += " -p:IsMTP=true"; - } + if (resultDirectoryArgs.Length == 0) + { + resultDirectoryArgs = $"--results-directory \"{resultsDirectory}\""; + } - var resultDirectoryArgs = string.IsNullOrEmpty(this.relativeResultsDirectory) ? string.Empty : $"--results-directory \"{resultsDirectory}\""; - if (isMTP && resultDirectoryArgs.Length == 0) + File.Copy(globalJsonTemplate, globalJsonPath); + } + else { - resultDirectoryArgs = $"--results-directory \"{resultsDirectory}\""; + loggerArgs = $"--logger:\"{loggerArgs}\""; } + var testProjectPath = Path.Combine(assemblyName.ToAssetDirectoryPath(), $"{assemblyName}.csproj"); var commandlineSuffix = string.IsNullOrEmpty(this.runSettingsSuffix) ? string.Empty : $"--{(isMTP ? "test-parameter" : string.Empty)} {this.runSettingsSuffix}"; + var testCommand = isMTP ? $"test --project \"{testProjectPath}\"" : $"test \"{testProjectPath}\""; using var dotnet = new Process { StartInfo = { + WorkingDirectory = assemblyName.ToAssetDirectoryPath(), UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, FileName = "dotnet", - Arguments = $"test \"{assemblyName.ToAssetDirectoryPath()}\\{assemblyName}.csproj\" {buildArgs}{(isMTP ? " --" : string.Empty)} {loggerArgs} {resultDirectoryArgs} {commandlineSuffix}" + Arguments = $"{testCommand} {buildArgs} {loggerArgs} {resultDirectoryArgs} {commandlineSuffix}" } }; diff --git a/test/assets/Directory.Build.props b/test/assets/Directory.Build.props index a311da4..7555e13 100644 --- a/test/assets/Directory.Build.props +++ b/test/assets/Directory.Build.props @@ -31,8 +31,10 @@ false - 5.1.1-alpha.1 - 3.10.1 + 6.0.0 + 4.0.0 + 3.2.1 + 3.1.5 diff --git a/test/assets/global.json b/test/assets/global.json new file mode 100644 index 0000000..8f73781 --- /dev/null +++ b/test/assets/global.json @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +} \ No newline at end of file diff --git a/test/assets/global.json.template b/test/assets/global.json.template new file mode 100644 index 0000000..8f73781 --- /dev/null +++ b/test/assets/global.json.template @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +} \ No newline at end of file From 3a1a73c7a8bf0d4c62c6c4ac5420f695844cbf7c Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Sun, 21 Dec 2025 08:03:41 +0530 Subject: [PATCH 3/5] fix: xunit mtp v2 tests --- .../JUnit.Xml.TestLogger.XUnit.NetCore.Tests.csproj | 12 +++++------- .../Xunit.Xml.TestLogger.NetCore.Tests.csproj | 10 +++++----- .../Xunit.Xml.TestLogger.NetFull.Tests.csproj | 12 +++++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/test/assets/JUnit.Xml.TestLogger.XUnit.NetCore.Tests/JUnit.Xml.TestLogger.XUnit.NetCore.Tests.csproj b/test/assets/JUnit.Xml.TestLogger.XUnit.NetCore.Tests/JUnit.Xml.TestLogger.XUnit.NetCore.Tests.csproj index 33499e5..05e26f4 100644 --- a/test/assets/JUnit.Xml.TestLogger.XUnit.NetCore.Tests/JUnit.Xml.TestLogger.XUnit.NetCore.Tests.csproj +++ b/test/assets/JUnit.Xml.TestLogger.XUnit.NetCore.Tests/JUnit.Xml.TestLogger.XUnit.NetCore.Tests.csproj @@ -2,9 +2,7 @@ net8.0 - net10.0 - - false + @@ -13,11 +11,11 @@ - - + + - - + + diff --git a/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/Xunit.Xml.TestLogger.NetCore.Tests.csproj b/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/Xunit.Xml.TestLogger.NetCore.Tests.csproj index 37eb612..cccb57c 100644 --- a/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/Xunit.Xml.TestLogger.NetCore.Tests.csproj +++ b/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/Xunit.Xml.TestLogger.NetCore.Tests.csproj @@ -2,7 +2,7 @@ net8.0 - net10.0 + exe @@ -10,11 +10,11 @@ - - - + + + - + diff --git a/test/assets/Xunit.Xml.TestLogger.NetFull.Tests/Xunit.Xml.TestLogger.NetFull.Tests.csproj b/test/assets/Xunit.Xml.TestLogger.NetFull.Tests/Xunit.Xml.TestLogger.NetFull.Tests.csproj index 6c412dc..17a339e 100644 --- a/test/assets/Xunit.Xml.TestLogger.NetFull.Tests/Xunit.Xml.TestLogger.NetFull.Tests.csproj +++ b/test/assets/Xunit.Xml.TestLogger.NetFull.Tests/Xunit.Xml.TestLogger.NetFull.Tests.csproj @@ -3,6 +3,7 @@ net472 /usr/lib/mono/4.5/ + exe @@ -10,11 +11,12 @@ - - - - - + + + + + + From b693c9fedc2a676c3a77da7427e7e9756af98e92 Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Sun, 21 Dec 2025 08:23:36 +0530 Subject: [PATCH 4/5] docs: add note for MTPv1 support --- .github/ISSUE_TEMPLATE/bug_report.md | 16 ++++++++-------- .gitignore | 1 + Directory.Build.props | 2 +- README.md | 4 ++++ test/TestLogger.Fixtures/DotnetTestFixture.cs | 3 ++- test/assets/global.json | 5 ----- 6 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 test/assets/global.json diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 54da514..b212a0b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,17 +1,17 @@ --- name: Bug report about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- **Describe the bug** -A clear and concise description of what the bug is. +A clear and concise description of the problem. +- **Test Runner** (choose one): VSTest/MTPv1/MTPv2 - **Test Framework** (choose one): MSTest/Nunit/Xunit -- **.NET project version, sdk version** (choose applicable): net7.0/net8.0/net48 +- **.NET project version, sdk version** (choose applicable): net10.0/net48 - **Command line used** (please share the test run command): `dotnet test --logger:xyz...` - **OS**: Linux/Windows/Mac @@ -20,8 +20,8 @@ A clear and concise description of what you expected to happen. **Other details** -- [ ] Here's a minimal repro project -- [ ] I have attached logs from `dotnet test --diag:log.txt` to the issue. Please redact any confidential info from the logs before attaching. See https://github.com/spekt/testlogger/wiki/Collecting-vstest-logs +- [ ] Minimal repro project +- [ ] Logs from `dotnet test --diag:log.txt` are attached. Please redact any confidential info from the logs before attaching. See https://github.com/spekt/testlogger/wiki/Collecting-vstest-logs **Additional context** Add any other context about the problem here. diff --git a/.gitignore b/.gitignore index 0f4d8d4..21bdf5b 100644 --- a/.gitignore +++ b/.gitignore @@ -344,3 +344,4 @@ site .vscode/settings.json *.received.txt +global.json \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 78cdaad..6762261 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ $(MSBuildThisFileDirectory) - 7.0.1 + 8.0.0 diff --git a/README.md b/README.md index f09993f..8aa35c0 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ Junit, NUnit and Xunit logger/reporter extensions for [Visual Studio Test Platfo ## Packages +> [!IMPORTANT] +> If you're using MTPv1 runner, kindly use v7.x of the loggers. +> v8+ supports MTPv2 and VSTest runners. + | Logger | Stable Package | Pre-release Package | Usage | | ------ | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | | JUnit | [![NuGet](https://img.shields.io/nuget/v/JUnitXml.TestLogger.svg)](https://www.nuget.org/packages/JUnitXml.TestLogger/) | [![MyGet Pre Release](https://img.shields.io/myget/spekt/vpre/junitxml.testlogger.svg)](https://www.myget.org/feed/spekt/package/nuget/JunitXml.TestLogger) | [README](src/JUnit.Xml.Package/README.md) | diff --git a/test/TestLogger.Fixtures/DotnetTestFixture.cs b/test/TestLogger.Fixtures/DotnetTestFixture.cs index e0f02af..f06827b 100644 --- a/test/TestLogger.Fixtures/DotnetTestFixture.cs +++ b/test/TestLogger.Fixtures/DotnetTestFixture.cs @@ -116,7 +116,8 @@ public string Execute(string assemblyName, string loggerArgs, bool collectCovera throw new NotSupportedException("Coverlet isn't supported with MTP yet."); } - dotnet.StartInfo.Arguments += " --collect:\"XPlat Code Coverage\" --settings coverlet.runsettings"; + var coverletRunSettingsPath = Path.Combine(Environment.CurrentDirectory, "coverlet.runsettings"); + dotnet.StartInfo.Arguments += $" --collect:\"XPlat Code Coverage\" --settings \"{coverletRunSettingsPath}\""; } this.LogTestAssetOutDir(assemblyName); diff --git a/test/assets/global.json b/test/assets/global.json deleted file mode 100644 index 8f73781..0000000 --- a/test/assets/global.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "test": { - "runner": "Microsoft.Testing.Platform" - } -} \ No newline at end of file From afc88a0960255ca7413238c4890f25d7ecab74d9 Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Sun, 21 Dec 2025 08:29:03 +0530 Subject: [PATCH 5/5] chore: update version to 8.0.0 --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index a3fcc71..ae9a76b 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -7.1.0 +8.0.0