Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -20,8 +20,8 @@ A clear and concise description of what you expected to happen.

**Other details**

- [ ] Here's a minimal repro project <include link to a git repo>
- [ ] 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 <include link to a git repo>
- [ ] 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.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,4 @@ site
.vscode/settings.json

*.received.txt
global.json
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<SourceRoot Condition="$(SourceRoot) == ''">$(MSBuildThisFileDirectory)</SourceRoot>
<SourcePrefix>7.0.1</SourcePrefix>
<SourcePrefix>8.0.0</SourcePrefix>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="15.5.0" />
<PackageVersion Include="Microsoft.Testing.Platform" Version="1.8.4" />
<PackageVersion Include="Microsoft.Testing.Platform" Version="2.0.2" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />

<PackageVersion Include="Stylecop.Analyzers" Version="1.2.0-beta.556" />
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
27 changes: 27 additions & 0 deletions src/TestLogger.MTPv1/TestLogger.MTPv1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- This project ensures we accidentally don't break MTP v1. No assemblies or tests use this. -->
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Spekt.TestLogger</AssemblyName>
<Version>$(PackageVersion)</Version>
<IsPackable>true</IsPackable>
<DebugType>embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<DefineConstants>$(DefineConstants);MTP_V1</DefineConstants>
</PropertyGroup>

<PropertyGroup Label="Configuration">
<RootNamespace>Spekt.TestLogger</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="../TestLogger/**/*.cs" Exclude="../TestLogger/obj/**;../TestLogger/bin/**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />
<PackageReference Include="Microsoft.Testing.Platform" VersionOverride="1.9.1"/>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/TestLogger/TestReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ public Task<bool> 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<TargetFrameworkAttribute>()?.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;
Expand Down
29 changes: 21 additions & 8 deletions test/TestLogger.Fixtures/DotnetTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}"
}
};

Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions test/assets/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
<TestingPlatformCaptureOutput>false</TestingPlatformCaptureOutput>

<!-- Need a combination with VSTestBridge >= 1.82.0 dependency -->
<NUnitTestAdapterVersion>5.1.1-alpha.1</NUnitTestAdapterVersion>
<MSTestVersion>3.10.1</MSTestVersion>
<NUnitTestAdapterVersion>6.0.0</NUnitTestAdapterVersion>
<MSTestVersion>4.0.0</MSTestVersion>
<XunitV3Version>3.2.1</XunitV3Version>
<XunitV3TestAdapterVersion>3.1.5</XunitV3TestAdapterVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition="'$(UsesXunit3)'=='true'">net10.0</TargetFramework>
<!-- Disable stylecop for test assets -->
<StylecopEnabled>false</StylecopEnabled>
<!-- <OutputType Condition="'$(UsesXunit3)'=='true'">exe</OutputType> -->
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,11 +11,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(NETTestSdkMinimumVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" Condition="'$(UsesXunit3)' != 'true'" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitTestAdapterVersion)" Condition="'$(UsesXunit3)' != 'true'" />
<PackageReference Condition="'$(UsesXunit3)' != 'true'" Include="xunit" Version="$(XunitVersion)" />
<PackageReference Condition="'$(UsesXunit3)' != 'true'" Include="xunit.runner.visualstudio" Version="$(XunitTestAdapterVersion)" />

<PackageReference Include="xunit.v3" Version="$(XunitV3Version)" Condition="'$(UsesXunit3)' == 'true'" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitV3TestAdapterVersion)" Condition="'$(UsesXunit3)' == 'true'" />
<PackageReference Condition="'$(UsesXunit3)' == 'true'" Include="xunit.v3.mtp-v2" Version="$(XunitV3Version)" />
<PackageReference Condition="'$(UsesXunit3)' == 'true'" Include="xunit.runner.visualstudio" Version="$(XunitV3TestAdapterVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition="'$(UsesXunit3)'=='true'">net10.0</TargetFramework>
<OutputType Condition="'$(UsesXunit3)'=='true'">exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../src/Xunit.Xml.TestLogger/Xunit.Xml.TestLogger.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.2.0" Condition="'$(UsesXunit3)' != 'true'"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" Condition="'$(UsesXunit3)' != 'true'" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(NETTestSdkMinimumVersion)" />
<PackageReference Condition="'$(UsesXunit3)' != 'true'" Include="xunit" Version="$(XunitVersion)" />
<PackageReference Condition="'$(UsesXunit3)' != 'true'" Include="xunit.runner.visualstudio" Version="$(XunitTestAdapterVersion)" />

<PackageReference Condition="'$(UsesXunit3)' == 'true'" Include="xunit.v3" Version="$(XunitV3Version)" />
<PackageReference Condition="'$(UsesXunit3)' == 'true'" Include="xunit.v3.mtp-v2" Version="$(XunitV3Version)" />
<PackageReference Condition="'$(UsesXunit3)' == 'true'" Include="xunit.runner.visualstudio" Version="$(XunitV3TestAdapterVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<FrameworkPathOverride Condition="'$(OS)' != 'Windows_NT'">/usr/lib/mono/4.5/</FrameworkPathOverride>
<OutputType Condition="'$(UsesXunit3)'=='true'">exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../src/Xunit.Xml.TestLogger/Xunit.Xml.TestLogger.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.2.0" Condition="'$(UsesXunit3)' != 'true'"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" Condition="'$(UsesXunit3)' != 'true'" />
<PackageReference Include="xunit.v3" Version="$(XunitV3Version)" Condition="'$(UsesXunit3)' == 'true'" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitV3TestAdapterVersion)" Condition="'$(UsesXunit3)' == 'true'" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(NETTestSdkMinimumVersion)" />
<PackageReference Condition="'$(UsesXunit3)' != 'true'" Include="xunit" Version="$(XunitVersion)" />
<PackageReference Condition="'$(UsesXunit3)' != 'true'" Include="xunit.runner.visualstudio" Version="$(XunitTestAdapterVersion)" />

<PackageReference Condition="'$(UsesXunit3)' == 'true'" Include="xunit.v3.mtp-v2" Version="$(XunitV3Version)" />
<PackageReference Condition="'$(UsesXunit3)' == 'true'" Include="xunit.runner.visualstudio" Version="$(XunitV3TestAdapterVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions test/assets/global.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
1 change: 1 addition & 0 deletions testlogger.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Project Path="src/JUnit.Xml.TestLogger/JUnit.Xml.TestLogger.csproj" />
<Project Path="src/NUnit.Xml.Package/NUnit.Xml.Package.csproj" />
<Project Path="src/NUnit.Xml.TestLogger/NUnit.Xml.TestLogger.csproj" />
<Project Path="src/TestLogger.MTPv1/TestLogger.MTPv1.csproj" />
<Project Path="src/TestLogger/TestLogger.csproj" />
<Project Path="src/Xunit.Xml.Package/Xunit.Xml.Package.csproj" />
<Project Path="src/Xunit.Xml.TestLogger/Xunit.Xml.TestLogger.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.1.0
8.0.0