Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -76,6 +82,8 @@ public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria)
throw new ArgumentNullException("testRunCriteria");
}

UpdateTestAdapterPaths(testRunCriteria.TestRunSettings);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused issue in Tpv1, when in VS IDE scenario data collectors were enabled, & runsettings were used to provide adapter path, it resulted in DataCollection(fakes, CodeCoverage) not working.

The workaround we used was to not update them here, but instead like we process TestAdapterPath in CLI, similarly process it, & apply it on ITestPlatform when provided via runsettings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to take a deeper look at the datacollector scenarios. but right now TPv2 does not support DataCollectors.

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings);
var testHostManager = this.TestEngine.GetDefaultTestHostManager(runConfiguration);

Expand Down Expand Up @@ -121,5 +129,33 @@ public void UpdateExtensions(IEnumerable<string> pathToAdditionalExtensions, boo
this.TestEngine.GetExtensionManager()
.UseAdditionalExtensions(pathToAdditionalExtensions, loadOnlyWellKnownExtensions);
}

/// <summary>
/// Update the test adapter paths provided through run settings to be used by the test service
/// </summary>
private void UpdateTestAdapterPaths(string runSettings)
{
IEnumerable<string> 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<string> adapterFiles = new List<string>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is duplicated across many files. Should we consolidate?

Directory.EnumerateFiles(adapterPath,TestPlatformConstants.TestAdapterPattern , SearchOption.AllDirectories)
);
if (adapterFiles.Count > 0)
{
this.UpdateExtensions(adapterFiles, false);
}
}
}
}
}
}
19 changes: 18 additions & 1 deletion src/Microsoft.TestPlatform.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Microsoft.VisualStudio.TestPlatform.Common
{
/// <summary>
/// Defines the defaults/constants used across different components.
/// Defines the defaults used across different components.
/// </summary>
public static class TestPlatformDefaults
{
Expand Down Expand Up @@ -38,4 +38,21 @@ public static class TestPlatformDefaults
/// </summary>
public const bool DefaultEnableBoundsOnLoggerEventQueue = true;
}

/// <summary>
/// Defines the constants used across different components.
/// </summary>
public static class TestPlatformConstants
{
/// <summary>
/// string pattern used to find the test adapters
/// </summary>
public const string TestAdapterPattern = @"*.TestAdapter.dll";

/// <summary>
/// Regex pattern used to find the test adapters
/// </summary>
public const string TestAdapterRedexPattern = @".*.TestAdapter.dll";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -112,5 +114,27 @@ public static int GetMaxCpuCount(RunConfiguration runConfiguration)
return cpuCount;
}

/// <summary>
/// Gets the test adapters path from the run configuration
/// </summary>
/// <param name="runSettings">Test run settings</param>
/// <param name="returnNullIfNotSet">True to return null, if adapter paths is not set.</param>
/// <returns>Test adapters paths</returns>
public static IEnumerable<string> GetTestAdaptersPaths(string runSettings)
{
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings);

IEnumerable<string> testAdaptersPaths = Enumerable.Empty<string>();
if (runConfiguration != null)
{
if (runConfiguration.TestAdaptersPathsSet)
{
testAdaptersPaths = runConfiguration.TestAdaptersPaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
}

return testAdaptersPaths;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -191,7 +192,7 @@ public IEnumerable<string> GetTestPlatformExtensions(IEnumerable<string> 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<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -195,7 +196,7 @@ public ArgumentProcessorResult Execute()
/// <returns> The list of test adapter assemblies. </returns>
internal virtual IEnumerable<string> GetTestAdaptersFromDirectory(string directory)
{
return Directory.EnumerateFiles(directory, @"*.TestAdapter.dll", SearchOption.AllDirectories);
return Directory.EnumerateFiles(directory, TestPlatformConstants.TestAdapterPattern, SearchOption.AllDirectories);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -93,6 +95,17 @@ public void GetMaxCpuCountWithInvalidCpuCountShouldReturnDefaultCpuCount()

Assert.AreEqual(expectedResult, result);
}

[TestMethod]
public void GetTestAdaptersPaths()
{
string settingXml = @"<RunSettings><RunConfiguration><TestAdaptersPaths>C:\testadapterpath;D:\secondtestadapterpath</TestAdaptersPaths></RunConfiguration ></RunSettings>";
string[] expectedResult = new string[] { @"C:\testadapterpath", @"D:\secondtestadapterpath" };

string[] result = (string[])RunSettingsUtilities.GetTestAdaptersPaths(settingXml);

CollectionAssert.AreEqual(expectedResult, result);
}
}

[SettingsName("DummyMSTest")]
Expand Down