-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for TestAdapterLoadingStrategy. (#3374)
* Added the playground project. * Added support for TestAdapterLoadingStrategy.
- Loading branch information
Showing
41 changed files
with
1,815 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot> | ||
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> | ||
</PropertyGroup> | ||
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks Condition=" '$(OS)' == 'WINDOWS_NT' ">$(TargetFrameworks);net472</TargetFrameworks> | ||
<!-- We build this on linux as well, and are including ref assemblies for this framework only. --> | ||
<TargetFrameworks Condition=" '$(OS)' != 'WINDOWS_NT' ">$(TargetFrameworks);net451</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' "> | ||
<Reference Include="netstandard" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Runtime" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
</ItemGroup> | ||
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace MSTest1 | ||
{ | ||
[TestClass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Playground | ||
|
||
This Plaground directory contains projects to aid interactive debugging of test platform. TestPlatform is normally built | ||
as a set of distinct pieces and then assembled in the artifacts folder. This forces rebuilding using build.cmd to try out | ||
changes. The TestPlatform.Playground project builds a simpler version of TestPlatform to avoid always rebuilding via | ||
build.cmd, offering a tighther development loop. | ||
|
||
The project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure | ||
we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from | ||
their original build locations, to $(TargetDir)\vstest.console directory, and it's subfolders to create an executable | ||
copy of TestPlatform that is similar to what we ship. | ||
|
||
The copying might trigger only on re-build, if you see outdated dependencies, Rebuild this project instead of just Build. | ||
|
||
Use this as playground for your debugging of end-to-end scenarios, it will automatically attach vstest.console and teshost | ||
sub-processes. It won't stop at entry-point automatically, don't forget to set your breakpoints, or remove VSTEST_DEBUG_NOBP | ||
from the environment variables of this project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
|
||
namespace TestPlatform.Playground | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
// This project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure | ||
// we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from | ||
// their original build locations, to $(TargetDir)\vstest.console directory, and it's subfolders to create an executable | ||
// copy of TestPlatform that is similar to what we ship. | ||
// | ||
// The copying might trigger only on re-build, if you see outdated dependencies, Rebuild this project instead of just Build. | ||
// | ||
// Use this as playground for your debugging of end-to-end scenarios, it will automatically attach vstest.console and teshost | ||
// sub-processes. It won't stop at entry-point automatically, don't forget to set your breakpoints, or remove VSTEST_DEBUG_NOBP | ||
// from the environment variables of this project. | ||
|
||
var thisAssemblyPath = Assembly.GetEntryAssembly().Location; | ||
var here = Path.GetDirectoryName(thisAssemblyPath); | ||
var playground = Path.GetFullPath(Path.Combine(here, "..", "..", "..", "..")); | ||
|
||
var console = Path.Combine(here, "vstest.console", "vstest.console.exe"); | ||
var consoleOptions = new ConsoleParameters | ||
{ | ||
LogFilePath = Path.Combine(here, "logs", "log.txt"), | ||
TraceLevel = TraceLevel.Verbose, | ||
}; | ||
|
||
var r = new VsTestConsoleWrapper(console, consoleOptions); | ||
|
||
var sourceSettings = @" | ||
<RunSettings> | ||
<RunConfiguration> | ||
<InIsolation>true</InIsolation> | ||
</RunConfiguration> | ||
</RunSettings> | ||
"; | ||
var sources = new[] { | ||
Path.Combine(playground, "MSTest1", "bin", "Debug", "net472", "MSTest1.dll") | ||
}; | ||
|
||
var options = new TestPlatformOptions(); | ||
r.RunTestsWithCustomTestHost(sources, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher()); | ||
} | ||
|
||
public class TestRunHandler : ITestRunEventsHandler | ||
{ | ||
|
||
public TestRunHandler() | ||
{ | ||
} | ||
|
||
public void HandleLogMessage(TestMessageLevel level, string message) | ||
{ | ||
Console.WriteLine($"[{level.ToString().ToUpper()}]: {message}"); | ||
} | ||
|
||
public void HandleRawMessage(string rawMessage) | ||
{ | ||
Console.WriteLine($"[MESSAGE]: { rawMessage}"); | ||
} | ||
|
||
public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris) | ||
{ | ||
Console.WriteLine($"[COMPLETE]: err: { testRunCompleteArgs.Error }, lastChunk: {WriteTests(lastChunkArgs?.NewTestResults)}"); | ||
} | ||
|
||
public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs) | ||
{ | ||
Console.WriteLine($"[PROGRESS - NEW RESULTS]: {WriteTests(testRunChangedArgs.NewTestResults)}"); | ||
} | ||
|
||
public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private string WriteTests(IEnumerable<TestResult> testResults) | ||
{ | ||
return WriteTests(testResults?.Select(t => t.TestCase)); | ||
} | ||
|
||
private string WriteTests(IEnumerable<TestCase> testCases) | ||
{ | ||
return testCases == null ? null : "\t" + string.Join("\n\t", testCases.Select(r => r.DisplayName)); | ||
} | ||
} | ||
|
||
internal class DebuggerTestHostLauncher : ITestHostLauncher2 | ||
{ | ||
public bool IsDebug => true; | ||
|
||
public bool AttachDebuggerToProcess(int pid) | ||
{ | ||
return true; | ||
} | ||
|
||
public bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken) | ||
{ | ||
return true; | ||
} | ||
|
||
public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo) | ||
{ | ||
return 1; | ||
} | ||
|
||
public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken) | ||
{ | ||
return 1; | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
playground/TestPlatform.Playground/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"profiles": { | ||
"TestPlatform.Playground": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"VSTEST_CONNECTION_TIMEOUT": "999", | ||
"VSTEST_DEBUG_NOBP": "1", | ||
"VSTEST_RUNNER_DEBUG_ATTACHVS": "1", | ||
"VSTEST_HOST_DEBUG_ATTACHVS": "1", | ||
"VSTEST_DATACOLLECTOR_DEBUG_ATTACHVS": "1" | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
playground/TestPlatform.Playground/TestPlatform.Playground.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot> | ||
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> | ||
<!-- MSB3270 Suppress warnings about testhost being x64 (AMD64)/x86 when imported into AnyCPU (MSIL) projects. --> | ||
<!-- MSB3276 Suppress warnings about conflicts between different versions of the same dependent assembly --> | ||
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3270;MSB3276</MSBuildWarningsAsMessages> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" /> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks Condition=" '$(OS)' == 'WINDOWS_NT' ">$(TargetFrameworks);net472</TargetFrameworks> | ||
<!-- We build this on linux as well, and are including ref assemblies for this framework only. --> | ||
<TargetFrameworks Condition=" '$(OS)' != 'WINDOWS_NT' ">$(TargetFrameworks);net451</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\datacollector\datacollector.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.TestHostProvider\Microsoft.TestPlatform.TestHostProvider.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.VsTestConsole.TranslationLayer\Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj" /> | ||
<ProjectReference Include="..\..\src\testhost.x86\testhost.x86.csproj" /> | ||
<ProjectReference Include="..\..\src\testhost\testhost.csproj" /> | ||
<ProjectReference Include="..\..\src\vstest.console\vstest.console.csproj" /> | ||
<ProjectReference Include="..\MSTest1\MSTest1.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' "> | ||
<Reference Include="netstandard" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Runtime" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
</ItemGroup> | ||
|
||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(OS)' == 'WINDOWS_NT' "> | ||
<Exec Command="xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\vstest.console\bin\$(Configuration)\net451\win7-x64\ $(TargetDir)\vstest.console\
xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\testhost\bin\$(Configuration)\net451\win7-x64\ $(TargetDir)\vstest.console\
xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\Microsoft.TestPlatform.TestHostProvider\bin\$(Configuration)\net451\ $(TargetDir)\vstest.console\Extensions\
xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\testhost.x86\bin\$(Configuration)\net472\win7-x86 $(TargetDir)\vstest.console\TestHost\" /> | ||
</Target> | ||
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" /> | ||
</Project> |
Oops, something went wrong.