diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 54da5145..b212a0bf 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 0f4d8d4f..21bdf5b8 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 78cdaadd..67622614 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ $(MSBuildThisFileDirectory) - 7.0.1 + 8.0.0 diff --git a/Directory.Packages.props b/Directory.Packages.props index 88812834..a76538ec 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,7 +5,7 @@ - + diff --git a/README.md b/README.md index f09993fd..8aa35c02 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/src/TestLogger.MTPv1/TestLogger.MTPv1.csproj b/src/TestLogger.MTPv1/TestLogger.MTPv1.csproj new file mode 100644 index 00000000..4178efef --- /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 8c1d5518..5a97531d 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/test/TestLogger.Fixtures/DotnetTestFixture.cs b/test/TestLogger.Fixtures/DotnetTestFixture.cs index 85d105d6..f06827b9 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}" } }; @@ -104,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/Directory.Build.props b/test/assets/Directory.Build.props index a311da4e..7555e135 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/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 33499e50..05e26f43 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 37eb612f..cccb57ce 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 6c412dc0..17a339e6 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 @@ - - - - - + + + + + + diff --git a/test/assets/global.json.template b/test/assets/global.json.template new file mode 100644 index 00000000..8f73781c --- /dev/null +++ b/test/assets/global.json.template @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +} \ No newline at end of file diff --git a/testlogger.slnx b/testlogger.slnx index 9145f736..bbb78559 100644 --- a/testlogger.slnx +++ b/testlogger.slnx @@ -9,6 +9,7 @@ + diff --git a/version.txt b/version.txt index a3fcc712..ae9a76b9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -7.1.0 +8.0.0