-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial support for Microsoft.Testing.Platform #403
Changes from all commits
a7721a9
7c7d7ab
80083a4
001053f
f856d53
c2cd6ad
bba850b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> | ||
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||
<add key="feedz.io/xunit/xunit" value="https://f.feedz.io/xunit/xunit/nuget/index.json" protocolVersion="3" /> | ||
<add key="local" value=".\artifacts\packages\" /> | ||
</packageSources> | ||
</configuration> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace xunit_runner_sample; | ||
|
||
public class UnitTest1 | ||
{ | ||
[Fact] | ||
public void Test1() | ||
{ | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net462;net6.0</TargetFrameworks> | ||
<RootNamespace>xunit_runner_sample</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
|
||
<EnableXunitRunner>true</EnableXunitRunner> | ||
<OutputType>Exe</OutputType> | ||
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="xunit" Version="2.7.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8-pre.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xunit-runner-sample", "xunit-runner-sample.csproj", "{CA7073C4-D751-474E-80E0-C252F722DBAE}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CA7073C4-D751-474E-80E0-C252F722DBAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CA7073C4-D751-474E-80E0-C252F722DBAE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CA7073C4-D751-474E-80E0-C252F722DBAE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CA7073C4-D751-474E-80E0-C252F722DBAE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Microsoft.Testing.Extensions.VSTestBridge.Capabilities; | ||
using Microsoft.Testing.Extensions.VSTestBridge.Helpers; | ||
using Microsoft.Testing.Platform.Builder; | ||
using Microsoft.Testing.Platform.Capabilities.TestFramework; | ||
|
||
namespace Xunit.Runner.VisualStudio; | ||
|
||
public static class TestApplicationBuilderExtensions | ||
{ | ||
public static void AddXunit( | ||
this ITestApplicationBuilder testApplicationBuilder, | ||
Func<IEnumerable<Assembly>> getTestAssemblies) | ||
{ | ||
XunitExtension extension = new(); | ||
testApplicationBuilder.AddRunSettingsService(extension); | ||
testApplicationBuilder.AddTestCaseFilterService(extension); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This provides support for the vstest way of filtering tests. |
||
testApplicationBuilder.RegisterTestFramework( | ||
_ => new TestFrameworkCapabilities(new VSTestBridgeExtensionBaseCapabilities()), | ||
(capabilities, serviceProvider) => new XunitBridgedTestFramework(extension, getTestAssemblies, serviceProvider, capabilities) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Reflection; | ||
using Microsoft.Testing.Platform.Builder; | ||
|
||
namespace Xunit.Runner.VisualStudio; | ||
|
||
public static class TestingPlatformBuilderHook | ||
{ | ||
public static void AddExtensions( | ||
ITestApplicationBuilder testApplicationBuilder, | ||
string[] _) => | ||
testApplicationBuilder.AddXunit(() => [Assembly.GetEntryAssembly()!]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Testing.Extensions.VSTestBridge; | ||
using Microsoft.Testing.Extensions.VSTestBridge.Requests; | ||
using Microsoft.Testing.Platform.Capabilities.TestFramework; | ||
using Microsoft.Testing.Platform.Messages; | ||
|
||
namespace Xunit.Runner.VisualStudio; | ||
|
||
internal sealed class XunitBridgedTestFramework : SynchronizedSingleSessionVSTestBridgedTestFramework | ||
{ | ||
public XunitBridgedTestFramework( | ||
XunitExtension extension, | ||
Func<IEnumerable<Assembly>> getTestAssemblies, | ||
IServiceProvider serviceProvider, | ||
ITestFrameworkCapabilities capabilities) : | ||
base(extension, getTestAssemblies, serviceProvider, capabilities) | ||
{ } | ||
|
||
/// <inheritdoc /> | ||
protected override Task SynchronizedDiscoverTestsAsync( | ||
VSTestDiscoverTestExecutionRequest request, | ||
IMessageBus messageBus, | ||
CancellationToken cancellationToken) | ||
{ | ||
var discoverer = new VsTestRunner(); | ||
|
||
using (cancellationToken.Register(discoverer.Cancel)) | ||
discoverer.DiscoverTests(request.AssemblyPaths, request.DiscoveryContext, request.MessageLogger, request.DiscoverySink); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override Task SynchronizedRunTestsAsync( | ||
VSTestRunTestExecutionRequest request, | ||
IMessageBus messageBus, | ||
CancellationToken cancellationToken) | ||
{ | ||
var runner = new VsTestRunner(); | ||
|
||
using (cancellationToken.Register(runner.Cancel)) | ||
if (request.VSTestFilter.TestCases is { } testCases) | ||
runner.RunTests(testCases, request.RunContext, request.FrameworkHandle); | ||
else | ||
runner.RunTests(request.AssemblyPaths, request.RunContext, request.FrameworkHandle); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Testing.Platform.Extensions; | ||
|
||
namespace Xunit.Runner.VisualStudio; | ||
|
||
internal sealed class XunitExtension : IExtension | ||
{ | ||
public string Uid => nameof(XunitExtension); | ||
|
||
public string DisplayName => "xUnit.net"; | ||
|
||
public string Version => ThisAssembly.AssemblyVersion; | ||
|
||
public string Description => "xUnit.net for Microsoft Testing Platform"; | ||
|
||
public Task<bool> IsEnabledAsync() => Task.FromResult(true); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<EnableXunitRunner Condition=" '$(EnableXunitRunner)' == '' ">false</EnableXunitRunner> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll let you decide on the name, this is just an example. |
||
<IsTestingPlatformApplication>$(EnableXunitRunner)</IsTestingPlatformApplication> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(EnableXunitRunner)' == 'true' "> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- This GUID comes from Microsoft.Testing.Platform, do not modify --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The GUID is actually just any random GUID but it needs to be unique across the various extensions registered through the hook. |
||
<TestingPlatformBuilderHook Include="17E773D9-071C-4C66-97DD-57A450BDB027" Condition=" '$(GenerateTestingPlatformEntryPoint)' == 'true' " > | ||
<DisplayName>xUnit.net</DisplayName> | ||
<TypeFullName>Xunit.Runner.VisualStudio.TestingPlatformBuilderHook</TypeFullName> | ||
</TestingPlatformBuilderHook> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="$(MSBuildThisFileDirectory)xunit.runner.visualstudio.testadapter.dll"> | ||
<Link>xunit.runner.visualstudio.testadapter.dll</Link> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<Visible>False</Visible> | ||
</None> | ||
<None Include="$(MSBuildThisFileDirectory)xunit.abstractions.dll"> | ||
<Link>xunit.abstractions.dll</Link> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<!-- Handle the coexistence between testing platform and Microsoft.NET.Test.Sdk --> | ||
<PropertyGroup> | ||
<GenerateTestingPlatformEntryPoint Condition=" '$(GenerateTestingPlatformEntryPoint)' == '' ">$(EnableXunitRunner)</GenerateTestingPlatformEntryPoint> | ||
<GenerateProgramFile Condition=" '$(EnableXunitRunner)' == 'true' ">false</GenerateProgramFile> | ||
<DisableTestingPlatformServerCapability Condition=" '$(EnableXunitRunner)' != 'true' " >true</DisableTestingPlatformServerCapability> | ||
</PropertyGroup> | ||
|
||
<Choose> | ||
<!-- Avoid false warning about missing reference (msbuild bug) --> | ||
<!-- https://github.com/dotnet/msbuild/issues/9698#issuecomment-1945763467 --> | ||
<When Condition=" '$(EnableXunitRunner)' == 'true' "> | ||
<ItemGroup> | ||
<Reference Include="xunit.runner.visualstudio.testadapter"> | ||
<HintPath>$(MSBuildThisFileDirectory)xunit.runner.visualstudio.testadapter.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</When> | ||
<Otherwise> | ||
<ItemGroup> | ||
<None Include="$(MSBuildThisFileDirectory)xunit.runner.visualstudio.testadapter.dll"> | ||
<Link>xunit.runner.visualstudio.testadapter.dll</Link> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<Visible>False</Visible> | ||
</None> | ||
</ItemGroup> | ||
</Otherwise> | ||
</Choose> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provides the runsettings support.