-
Notifications
You must be signed in to change notification settings - Fork 81
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 1 commit
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="C:\src\visualstudio.xunit\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,30 @@ | ||
<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.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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); | ||
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 the runsettings support. |
||
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,15 @@ | ||
using System.Reflection; | ||
|
||
using Microsoft.Testing.Platform.Builder; | ||
|
||
namespace Xunit.Runner.VisualStudio; | ||
|
||
public static class TestingPlatformBuilderHook | ||
{ | ||
#pragma warning disable IDE0060 // Remove unused parameter | ||
public static void AddExtensions(ITestApplicationBuilder testApplicationBuilder, string[] arguments) | ||
#pragma warning restore IDE0060 // Remove unused parameter | ||
{ | ||
testApplicationBuilder.AddXunit(() => [Assembly.GetEntryAssembly()!]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; | ||
|
||
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)) | ||
{ | ||
((ITestDiscoverer)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)) | ||
{ | ||
var executor = (ITestExecutor)runner; | ||
if (request.VSTestFilter.TestCases is { } testCases) | ||
{ | ||
executor.RunTests(testCases, request.RunContext, request.FrameworkHandle); | ||
} | ||
else | ||
{ | ||
executor.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"; | ||
|
||
public string Version => ThisAssembly.AssemblyVersion; | ||
|
||
public string Description => "xUnit Framework for Microsoft Testing Platform"; | ||
|
||
public Task<bool> IsEnabledAsync() => Task.FromResult(true); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
<?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> | ||
|
||
<ItemGroup> | ||
<None Include="$(MSBuildThisFileDirectory)xunit.runner.visualstudio.testadapter.dll"> | ||
<Link>xunit.runner.visualstudio.testadapter.dll</Link> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<Visible>False</Visible> | ||
</None> | ||
<!-- | ||
!!! IMPORTANT !!! | ||
DO NOT CHANGE THE GUID, IT'S A WELL KNOWN EXTENSION POINT AND THIS EXTENSION NEEDS TO BE REGISTERED AT THE END | ||
WE HAVE CODE INSIDE THE TASK 'TestingPlatformEntryPoint' TO ENSURE THE ORDER OF THE REGISTRATION BASED ON THIS GUID | ||
--> | ||
<TestingPlatformBuilderHook Include="17E773D9-071C-4C66-97DD-57A450BDB027" Condition=" $(GenerateTestingPlatformEntryPoint) == 'true' " > | ||
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. Allows |
||
<DisplayName>xUnit</DisplayName> | ||
<TypeFullName>Xunit.Runner.VisualStudio.TestingPlatformBuilderHook</TypeFullName> | ||
</TestingPlatformBuilderHook> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- Adapter dll is included in the .targets --> | ||
<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 coexistance between testing platform and Microsoft.NET.Test.Sdk --> | ||
<PropertyGroup> | ||
<GenerateTestingPlatformEntryPoint Condition=" '$(GenerateTestingPlatformEntryPoint)' == '' ">$(EnableXunitRunner)</GenerateTestingPlatformEntryPoint> | ||
<GenerateProgramFile Condition=" '$(EnableXunitRunner)' == 'true' ">false</GenerateProgramFile> | ||
<DisableTestingPlatformServerCapability Condition=" '$(EnableXunitRunner)' == 'false' or '$(EnableXunitRunner)' == '' " >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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,15 @@ | |
<dependencies> | ||
<group targetFramework="net462"> | ||
<dependency id="Microsoft.TestPlatform.ObjectModel" version="$MicrosoftTestPlatformObjectModelVersion$" /> | ||
<dependency id="Microsoft.Testing.Extensions.Telemetry" version="$MicrosoftTestingPlatformVersion$" /> | ||
<dependency id="Microsoft.Testing.Extensions.VSTestBridge" version="$MicrosoftTestingPlatformVersion$" /> | ||
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. 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 is mixing tabs/spaces, you'll need to configure your editor to show whistespaces |
||
<dependency id="Microsoft.Testing.Platform.MSBuild" version="$MicrosoftTestingPlatformVersion$" /> | ||
</group> | ||
<group targetFramework="net6.0" /> | ||
<group targetFramework="net6.0"> | ||
<dependency id="Microsoft.Testing.Extensions.Telemetry" version="$MicrosoftTestingPlatformVersion$" /> | ||
<dependency id="Microsoft.Testing.Extensions.VSTestBridge" version="$MicrosoftTestingPlatformVersion$" /> | ||
<dependency id="Microsoft.Testing.Platform.MSBuild" version="$MicrosoftTestingPlatformVersion$" /> | ||
</group> | ||
</dependencies> | ||
<frameworkAssemblies> | ||
<frameworkAssembly assemblyName="mscorlib" targetFramework="net462" /> | ||
|
@@ -35,12 +42,14 @@ | |
<file target="build\net462\" src="bin\$Configuration$\net462\xunit.runner.utility.net452.dll" /> | ||
<file target="build\net462\" src="bin\$Configuration$\net462\$SignedPath$xunit.runner.visualstudio.testadapter.dll" /> | ||
<file target="build\net462\xunit.runner.visualstudio.props" src="build\xunit.runner.visualstudio.desktop.props" /> | ||
<file target="build\net462\xunit.runner.visualstudio.targets" src="build\xunit.runner.visualstudio.targets" /> | ||
|
||
<file target="build\net6.0\" src="bin\$Configuration$\net6.0\xunit.abstractions.dll" /> | ||
<file target="build\net6.0\" src="bin\$Configuration$\net6.0\xunit.runner.reporters.netcoreapp10.dll" /> | ||
<file target="build\net6.0\" src="bin\$Configuration$\net6.0\xunit.runner.utility.netcoreapp10.dll" /> | ||
<file target="build\net6.0\" src="bin\$Configuration$\net6.0\$SignedPath$xunit.runner.visualstudio.testadapter.dll" /> | ||
<file target="build\net6.0\xunit.runner.visualstudio.props" src="build\xunit.runner.visualstudio.dotnetcore.props" /> | ||
<file target="build\net6.0\xunit.runner.visualstudio.targets" src="build\xunit.runner.visualstudio.targets" /> | ||
|
||
<file target="lib\net462\" src="build\_._" /> | ||
|
||
|
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 shouldn't be kept, this is just a temp change for you to test locally (you'll need to update the path as you know).