Skip to content

Commit fcc0e3a

Browse files
authored
Added support for TestAdapterLoadingStrategy. (#3374)
* Added the playground project. * Added support for TestAdapterLoadingStrategy.
1 parent d3c6439 commit fcc0e3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1815
-220
lines changed

TestPlatform.sln

+35
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DumpMinitool.x86", "src\Dat
170170
EndProject
171171
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttachVS", "src\AttachVS\AttachVS.csproj", "{8238A052-D626-49EB-A011-51DC6D0DBA30}"
172172
EndProject
173+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "playground", "playground", "{6CE2F530-582B-4695-A209-41065E103426}"
174+
ProjectSection(SolutionItems) = preProject
175+
playground\README.md = playground\README.md
176+
EndProjectSection
177+
EndProject
178+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestPlatform.Playground", "playground\TestPlatform.Playground\TestPlatform.Playground.csproj", "{545A88D3-1AE2-4D39-9B7C-C691768AD17F}"
179+
EndProject
180+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest1", "playground\MSTest1\MSTest1.csproj", "{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}"
181+
EndProject
173182
Global
174183
GlobalSection(SharedMSBuildProjectFiles) = preSolution
175184
src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{10b6ade1-f808-4612-801d-4452f5b52242}*SharedItemsImports = 5
@@ -835,6 +844,30 @@ Global
835844
{8238A052-D626-49EB-A011-51DC6D0DBA30}.Release|x64.Build.0 = Release|Any CPU
836845
{8238A052-D626-49EB-A011-51DC6D0DBA30}.Release|x86.ActiveCfg = Release|Any CPU
837846
{8238A052-D626-49EB-A011-51DC6D0DBA30}.Release|x86.Build.0 = Release|Any CPU
847+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
848+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Debug|Any CPU.Build.0 = Debug|Any CPU
849+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Debug|x64.ActiveCfg = Debug|Any CPU
850+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Debug|x64.Build.0 = Debug|Any CPU
851+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Debug|x86.ActiveCfg = Debug|Any CPU
852+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Debug|x86.Build.0 = Debug|Any CPU
853+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|Any CPU.ActiveCfg = Release|Any CPU
854+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|Any CPU.Build.0 = Release|Any CPU
855+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|x64.ActiveCfg = Release|Any CPU
856+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|x64.Build.0 = Release|Any CPU
857+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|x86.ActiveCfg = Release|Any CPU
858+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|x86.Build.0 = Release|Any CPU
859+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
860+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
861+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x64.ActiveCfg = Debug|Any CPU
862+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x64.Build.0 = Debug|Any CPU
863+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x86.ActiveCfg = Debug|Any CPU
864+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x86.Build.0 = Debug|Any CPU
865+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
866+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|Any CPU.Build.0 = Release|Any CPU
867+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x64.ActiveCfg = Release|Any CPU
868+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x64.Build.0 = Release|Any CPU
869+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x86.ActiveCfg = Release|Any CPU
870+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x86.Build.0 = Release|Any CPU
838871
EndGlobalSection
839872
GlobalSection(SolutionProperties) = preSolution
840873
HideSolutionNode = FALSE
@@ -907,6 +940,8 @@ Global
907940
{33A20B85-7024-4112-B1E7-00CD0E4A9F96} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB}
908941
{2C88C923-3D7A-4492-9241-7A489750CAB7} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB}
909942
{8238A052-D626-49EB-A011-51DC6D0DBA30} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
943+
{545A88D3-1AE2-4D39-9B7C-C691768AD17F} = {6CE2F530-582B-4695-A209-41065E103426}
944+
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7} = {6CE2F530-582B-4695-A209-41065E103426}
910945
EndGlobalSection
911946
GlobalSection(ExtensibilityGlobals) = postSolution
912947
SolutionGuid = {0541B30C-FF51-4E28-B172-83F5F3934BCD}

playground/MSTest1/MSTest1.csproj

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
4+
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
5+
</PropertyGroup>
6+
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
7+
8+
<PropertyGroup>
9+
<TargetFrameworks Condition=" '$(OS)' == 'WINDOWS_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
10+
<!-- We build this on linux as well, and are including ref assemblies for this framework only. -->
11+
<TargetFrameworks Condition=" '$(OS)' != 'WINDOWS_NT' ">$(TargetFrameworks);net451</TargetFrameworks>
12+
<IsPackable>false</IsPackable>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
17+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
18+
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
19+
<PackageReference Include="coverlet.collector" Version="1.2.0" />
20+
</ItemGroup>
21+
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
22+
<Reference Include="netstandard" />
23+
<Reference Include="System" />
24+
<Reference Include="System.Runtime" />
25+
<Reference Include="System.Xml" />
26+
<Reference Include="System.Xml.Linq" />
27+
<Reference Include="Microsoft.CSharp" />
28+
</ItemGroup>
29+
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
30+
</Project>

playground/MSTest1/UnitTest1.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace MSTest1
7+
{
8+
[TestClass]
9+
public class UnitTest1
10+
{
11+
[TestMethod]
12+
public void TestMethod1()
13+
{
14+
}
15+
}
16+
}

playground/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Playground
2+
3+
This Plaground directory contains projects to aid interactive debugging of test platform. TestPlatform is normally built
4+
as a set of distinct pieces and then assembled in the artifacts folder. This forces rebuilding using build.cmd to try out
5+
changes. The TestPlatform.Playground project builds a simpler version of TestPlatform to avoid always rebuilding via
6+
build.cmd, offering a tighther development loop.
7+
8+
The project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure
9+
we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from
10+
their original build locations, to $(TargetDir)\vstest.console directory, and it's subfolders to create an executable
11+
copy of TestPlatform that is similar to what we ship.
12+
13+
The copying might trigger only on re-build, if you see outdated dependencies, Rebuild this project instead of just Build.
14+
15+
Use this as playground for your debugging of end-to-end scenarios, it will automatically attach vstest.console and teshost
16+
sub-processes. It won't stop at entry-point automatically, don't forget to set your breakpoints, or remove VSTEST_DEBUG_NOBP
17+
from the environment variables of this project.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer;
5+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
6+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
7+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
8+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
9+
10+
using System;
11+
using System.Collections.Generic;
12+
using System.Diagnostics;
13+
using System.IO;
14+
using System.Linq;
15+
using System.Reflection;
16+
using System.Threading;
17+
18+
namespace TestPlatform.Playground
19+
{
20+
internal class Program
21+
{
22+
static void Main(string[] args)
23+
{
24+
// This project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure
25+
// we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from
26+
// their original build locations, to $(TargetDir)\vstest.console directory, and it's subfolders to create an executable
27+
// copy of TestPlatform that is similar to what we ship.
28+
//
29+
// The copying might trigger only on re-build, if you see outdated dependencies, Rebuild this project instead of just Build.
30+
//
31+
// Use this as playground for your debugging of end-to-end scenarios, it will automatically attach vstest.console and teshost
32+
// sub-processes. It won't stop at entry-point automatically, don't forget to set your breakpoints, or remove VSTEST_DEBUG_NOBP
33+
// from the environment variables of this project.
34+
35+
var thisAssemblyPath = Assembly.GetEntryAssembly().Location;
36+
var here = Path.GetDirectoryName(thisAssemblyPath);
37+
var playground = Path.GetFullPath(Path.Combine(here, "..", "..", "..", ".."));
38+
39+
var console = Path.Combine(here, "vstest.console", "vstest.console.exe");
40+
var consoleOptions = new ConsoleParameters
41+
{
42+
LogFilePath = Path.Combine(here, "logs", "log.txt"),
43+
TraceLevel = TraceLevel.Verbose,
44+
};
45+
46+
var r = new VsTestConsoleWrapper(console, consoleOptions);
47+
48+
var sourceSettings = @"
49+
<RunSettings>
50+
<RunConfiguration>
51+
<InIsolation>true</InIsolation>
52+
</RunConfiguration>
53+
</RunSettings>
54+
";
55+
var sources = new[] {
56+
Path.Combine(playground, "MSTest1", "bin", "Debug", "net472", "MSTest1.dll")
57+
};
58+
59+
var options = new TestPlatformOptions();
60+
r.RunTestsWithCustomTestHost(sources, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher());
61+
}
62+
63+
public class TestRunHandler : ITestRunEventsHandler
64+
{
65+
66+
public TestRunHandler()
67+
{
68+
}
69+
70+
public void HandleLogMessage(TestMessageLevel level, string message)
71+
{
72+
Console.WriteLine($"[{level.ToString().ToUpper()}]: {message}");
73+
}
74+
75+
public void HandleRawMessage(string rawMessage)
76+
{
77+
Console.WriteLine($"[MESSAGE]: { rawMessage}");
78+
}
79+
80+
public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris)
81+
{
82+
Console.WriteLine($"[COMPLETE]: err: { testRunCompleteArgs.Error }, lastChunk: {WriteTests(lastChunkArgs?.NewTestResults)}");
83+
}
84+
85+
public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs)
86+
{
87+
Console.WriteLine($"[PROGRESS - NEW RESULTS]: {WriteTests(testRunChangedArgs.NewTestResults)}");
88+
}
89+
90+
public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo)
91+
{
92+
throw new NotImplementedException();
93+
}
94+
95+
private string WriteTests(IEnumerable<TestResult> testResults)
96+
{
97+
return WriteTests(testResults?.Select(t => t.TestCase));
98+
}
99+
100+
private string WriteTests(IEnumerable<TestCase> testCases)
101+
{
102+
return testCases == null ? null : "\t" + string.Join("\n\t", testCases.Select(r => r.DisplayName));
103+
}
104+
}
105+
106+
internal class DebuggerTestHostLauncher : ITestHostLauncher2
107+
{
108+
public bool IsDebug => true;
109+
110+
public bool AttachDebuggerToProcess(int pid)
111+
{
112+
return true;
113+
}
114+
115+
public bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken)
116+
{
117+
return true;
118+
}
119+
120+
public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo)
121+
{
122+
return 1;
123+
}
124+
125+
public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken)
126+
{
127+
return 1;
128+
}
129+
}
130+
}
131+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"profiles": {
3+
"TestPlatform.Playground": {
4+
"commandName": "Project",
5+
"environmentVariables": {
6+
"VSTEST_CONNECTION_TIMEOUT": "999",
7+
"VSTEST_DEBUG_NOBP": "1",
8+
"VSTEST_RUNNER_DEBUG_ATTACHVS": "1",
9+
"VSTEST_HOST_DEBUG_ATTACHVS": "1",
10+
"VSTEST_DATACOLLECTOR_DEBUG_ATTACHVS": "1"
11+
}
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
4+
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
5+
<!-- MSB3270 Suppress warnings about testhost being x64 (AMD64)/x86 when imported into AnyCPU (MSIL) projects. -->
6+
<!-- MSB3276 Suppress warnings about conflicts between different versions of the same dependent assembly -->
7+
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3270;MSB3276</MSBuildWarningsAsMessages>
8+
</PropertyGroup>
9+
10+
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
11+
<PropertyGroup>
12+
<OutputType>Exe</OutputType>
13+
<TargetFrameworks Condition=" '$(OS)' == 'WINDOWS_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
14+
<!-- We build this on linux as well, and are including ref assemblies for this framework only. -->
15+
<TargetFrameworks Condition=" '$(OS)' != 'WINDOWS_NT' ">$(TargetFrameworks);net451</TargetFrameworks>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
20+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\..\src\datacollector\datacollector.csproj" />
25+
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.TestHostProvider\Microsoft.TestPlatform.TestHostProvider.csproj" />
26+
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.VsTestConsole.TranslationLayer\Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj" />
27+
<ProjectReference Include="..\..\src\testhost.x86\testhost.x86.csproj" />
28+
<ProjectReference Include="..\..\src\testhost\testhost.csproj" />
29+
<ProjectReference Include="..\..\src\vstest.console\vstest.console.csproj" />
30+
<ProjectReference Include="..\MSTest1\MSTest1.csproj" />
31+
</ItemGroup>
32+
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
33+
<Reference Include="netstandard" />
34+
<Reference Include="System" />
35+
<Reference Include="System.Runtime" />
36+
<Reference Include="System.Xml" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="Microsoft.CSharp" />
39+
</ItemGroup>
40+
41+
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(OS)' == 'WINDOWS_NT' ">
42+
<Exec Command="xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\vstest.console\bin\$(Configuration)\net451\win7-x64\ $(TargetDir)\vstest.console\&#xD;&#xA;xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\testhost\bin\$(Configuration)\net451\win7-x64\ $(TargetDir)\vstest.console\&#xD;&#xA;xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\Microsoft.TestPlatform.TestHostProvider\bin\$(Configuration)\net451\ $(TargetDir)\vstest.console\Extensions\&#xD;&#xA;xcopy /i /y $(MSBuildProjectDirectory)\..\..\src\testhost.x86\bin\$(Configuration)\net472\win7-x86 $(TargetDir)\vstest.console\TestHost\" />
43+
</Target>
44+
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
45+
</Project>

0 commit comments

Comments
 (0)