diff --git a/src/Microsoft.TestPlatform.Client/TestPlatform.cs b/src/Microsoft.TestPlatform.Client/TestPlatform.cs index 6bbfb39f5f..aeb339dfa4 100644 --- a/src/Microsoft.TestPlatform.Client/TestPlatform.cs +++ b/src/Microsoft.TestPlatform.Client/TestPlatform.cs @@ -4,11 +4,15 @@ namespace Microsoft.VisualStudio.TestPlatform.Client { using System; + using System.IO; using System.Collections.Generic; using Microsoft.VisualStudio.TestPlatform.Client.Discovery; using Microsoft.VisualStudio.TestPlatform.Client.Execution; + using Microsoft.VisualStudio.TestPlatform.Common; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; @@ -54,6 +58,8 @@ public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCrite throw new ArgumentNullException("discoveryCriteria"); } + UpdateTestAdapterPaths(discoveryCriteria.RunSettings); + var runconfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings); var testHostManager = this.TestEngine.GetDefaultTestHostManager(runconfiguration); @@ -76,6 +82,8 @@ public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria) throw new ArgumentNullException("testRunCriteria"); } + UpdateTestAdapterPaths(testRunCriteria.TestRunSettings); + var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings); var testHostManager = this.TestEngine.GetDefaultTestHostManager(runConfiguration); @@ -121,5 +129,33 @@ public void UpdateExtensions(IEnumerable pathToAdditionalExtensions, boo this.TestEngine.GetExtensionManager() .UseAdditionalExtensions(pathToAdditionalExtensions, loadOnlyWellKnownExtensions); } + + /// + /// Update the test adapter paths provided through run settings to be used by the test service + /// + private void UpdateTestAdapterPaths(string runSettings) + { + IEnumerable customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(runSettings); + + if (customTestAdaptersPaths != null) + { + foreach (string customTestAdaptersPath in customTestAdaptersPaths) + { + var adapterPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(customTestAdaptersPath)); + if (!Directory.Exists(adapterPath)) + { + EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); + continue; + } + List adapterFiles = new List( + Directory.EnumerateFiles(adapterPath,TestPlatformConstants.TestAdapterPattern , SearchOption.AllDirectories) + ); + if (adapterFiles.Count > 0) + { + this.UpdateExtensions(adapterFiles, false); + } + } + } + } } } diff --git a/src/Microsoft.TestPlatform.Common/Constants.cs b/src/Microsoft.TestPlatform.Common/Constants.cs index edca32e733..45aa420aee 100644 --- a/src/Microsoft.TestPlatform.Common/Constants.cs +++ b/src/Microsoft.TestPlatform.Common/Constants.cs @@ -4,7 +4,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common { /// - /// Defines the defaults/constants used across different components. + /// Defines the defaults used across different components. /// public static class TestPlatformDefaults { @@ -38,4 +38,21 @@ public static class TestPlatformDefaults /// public const bool DefaultEnableBoundsOnLoggerEventQueue = true; } + + /// + /// Defines the constants used across different components. + /// + public static class TestPlatformConstants + { + /// + /// string pattern used to find the test adapters + /// + public const string TestAdapterPattern = @"*.TestAdapter.dll"; + + /// + /// Regex pattern used to find the test adapters + /// + public const string TestAdapterRedexPattern = @".*.TestAdapter.dll"; + + } } diff --git a/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs b/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs index ad33056032..aba69fca5b 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs @@ -4,6 +4,8 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Utilities { using System; + using System.Collections.Generic; + using System.Linq; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; @@ -112,5 +114,27 @@ public static int GetMaxCpuCount(RunConfiguration runConfiguration) return cpuCount; } + /// + /// Gets the test adapters path from the run configuration + /// + /// Test run settings + /// True to return null, if adapter paths is not set. + /// Test adapters paths + public static IEnumerable GetTestAdaptersPaths(string runSettings) + { + var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings); + + IEnumerable testAdaptersPaths = Enumerable.Empty(); + if (runConfiguration != null) + { + if (runConfiguration.TestAdaptersPathsSet) + { + testAdaptersPaths = runConfiguration.TestAdaptersPaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + } + } + + return testAdaptersPaths; + } + } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs index e52bcadb23..c8c9339d0b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs @@ -10,6 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting using System.Linq; using Microsoft.Extensions.DependencyModel; + using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; @@ -191,7 +192,7 @@ public IEnumerable GetTestPlatformExtensions(IEnumerable sources if (!string.IsNullOrEmpty(sourceDirectory) && this.fileHelper.DirectoryExists(sourceDirectory)) { - return this.fileHelper.EnumerateFiles(sourceDirectory, ".*.TestAdapter.dll", SearchOption.TopDirectoryOnly); + return this.fileHelper.EnumerateFiles(sourceDirectory, TestPlatformConstants.TestAdapterRedexPattern, SearchOption.TopDirectoryOnly); } return Enumerable.Empty(); diff --git a/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs b/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs index a0162aa36b..acb9359b83 100644 --- a/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs +++ b/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors using System.Globalization; using System.IO; + using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.Utilities; @@ -195,7 +196,7 @@ public ArgumentProcessorResult Execute() /// The list of test adapter assemblies. internal virtual IEnumerable GetTestAdaptersFromDirectory(string directory) { - return Directory.EnumerateFiles(directory, @"*.TestAdapter.dll", SearchOption.AllDirectories); + return Directory.EnumerateFiles(directory, TestPlatformConstants.TestAdapterPattern, SearchOption.AllDirectories); } #endregion diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs index 7497a3acc6..c2570c2fd9 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs @@ -217,8 +217,6 @@ public void RunSettingsWithParallelAndPlatformX64(string runnerFramework, string this.RunTestWithRunSettings(runConfigurationDictionary, null, null, testhostProcessName, expectedProcessCreated); } - // Known issue https://github.com/Microsoft/vstest/issues/135 - [Ignore] [CustomDataTestMethod] [NET46TargetFramework] [NETCORETargetFramework] diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/RunSettingsUtilitiesTests.cs b/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/RunSettingsUtilitiesTests.cs index 9180e14e4a..b17412518d 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/RunSettingsUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/RunSettingsUtilitiesTests.cs @@ -10,6 +10,8 @@ namespace TestPlatform.Common.UnitTests.Utilities using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using System.Xml; using ExtensionFramework; + using System.Collections.Generic; + [TestClass] public class RunSettingsUtilitiesTests { @@ -93,6 +95,17 @@ public void GetMaxCpuCountWithInvalidCpuCountShouldReturnDefaultCpuCount() Assert.AreEqual(expectedResult, result); } + + [TestMethod] + public void GetTestAdaptersPaths() + { + string settingXml = @"C:\testadapterpath;D:\secondtestadapterpath"; + string[] expectedResult = new string[] { @"C:\testadapterpath", @"D:\secondtestadapterpath" }; + + string[] result = (string[])RunSettingsUtilities.GetTestAdaptersPaths(settingXml); + + CollectionAssert.AreEqual(expectedResult, result); + } } [SettingsName("DummyMSTest")]