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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
Microsoft.TestPlatform.VsTestConsole.TranslationLayer.VsTestConsoleWrapper.VsTestConsoleWrapper(string! vstestConsolePath, string! dotnetExePath, Microsoft.TestPlatform.VsTestConsole.TranslationLayer.ConsoleParameters! consoleParameters) -> void
Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces.IVsTestConsoleWrapper.RunTests(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase!>! testCases, string? runSettings, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestPlatformOptions? options, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestSessionInfo? testSessionInfo, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITestRunEventsHandler! testRunEventsHandler, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITelemetryEventsHandler! telemetryEventsHandler) -> void
Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces.IVsTestConsoleWrapper.RunTests(System.Collections.Generic.IEnumerable<string!>! sources, string? runSettings, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestPlatformOptions? options, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestSessionInfo? testSessionInfo, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITestRunEventsHandler! testRunEventsHandler, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITelemetryEventsHandler! telemetryEventsHandler) -> void
Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces.IVsTestConsoleWrapper.RunTestsWithCustomTestHost(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase!>! testCases, string? runSettings, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestPlatformOptions? options, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestSessionInfo? testSessionInfo, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITestRunEventsHandler! testRunEventsHandler, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITelemetryEventsHandler! telemetryEventsHandler, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces.ITestHostLauncher! customTestHostLauncher) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ consoleWrapper.DiscoverTests(testAssemblies, settings, discoveryHandler);
consoleWrapper.RunTests(testAssemblies, settings, executionHandler);
```

To launch `vstest.console.dll` with a particular .NET installation, specify its
`dotnet` executable when creating the wrapper:

```csharp
var consoleWrapper = new VsTestConsoleWrapper(
vstestConsolePath,
dotnetExePath: "<full path to dotnet or dotnet.exe>",
consoleParameters: new ConsoleParameters());
```

The host selection applies only to this wrapper; it does not modify the
process-wide `PATH`. The existing constructors continue to resolve the host
automatically, as does an empty `dotnetExePath`. When launching
`vstest.console.exe`, the runner is started directly and `dotnetExePath` is ignored.

## Links

- [Visual Studio Test Platform Documentation](https://github.com/microsoft/vstest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ public VsTestConsoleWrapper(
/// Initializes a new instance of the <see cref="VsTestConsoleWrapper"/> class.
/// </summary>
///
/// <remarks>Defined for testing purposes.</remarks>
/// <remarks>
/// The specified dotnet host is used only when <paramref name="vstestConsolePath"/> points to a DLL.
/// When launching an executable, the runner is started directly.
/// </remarks>
///
/// <param name="vstestConsolePath">Path to the test runner <c>vstest.console.exe</c>.</param>
/// <param name="dotnetExePath">Path to dotnet exe, needed for CI builds.</param>
/// <param name="vstestConsolePath">Path to the test runner <c>vstest.console.exe</c> or <c>vstest.console.dll</c>.</param>
/// <param name="dotnetExePath">Path to the dotnet executable used to launch <c>vstest.console.dll</c>.
/// An empty string uses the default dotnet host resolution.</param>
/// <param name="consoleParameters">The parameters to be passed onto the runner process.</param>
internal VsTestConsoleWrapper(
public VsTestConsoleWrapper(
string vstestConsolePath,
string dotnetExePath,
ConsoleParameters consoleParameters)
Expand Down
26 changes: 26 additions & 0 deletions test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -57,6 +58,31 @@ public VsTestConsoleWrapperTests()
_mockRequestSender.Setup(rs => rs.InitializeCommunicationAsync(It.IsAny<int>())).Returns(Task.FromResult(100));
}

[TestMethod]
public void ConstructorWithDotnetHostShouldBePublic()
{
var constructor = typeof(VsTestConsoleWrapper).GetConstructor(
[typeof(string), typeof(string), typeof(ConsoleParameters)]);

Assert.IsNotNull(constructor);
}

[TestMethod]
public void ProcessManagerShouldUseSpecifiedDotnetHostWithoutChangingPath()
{
var dotnetExePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString(), "custom dotnet", "dotnet");
var originalPath = Environment.GetEnvironmentVariable("PATH");
var consoleParameters = new ConsoleParameters();
using var processManager = new VsTestConsoleProcessManager(
typeof(VsTestConsoleWrapper).Assembly.Location,
dotnetExePath);

var exception = Assert.ThrowsExactly<FileNotFoundException>(() => processManager.StartProcess(consoleParameters));

Assert.AreEqual(dotnetExePath, exception.FileName);
Assert.AreEqual(originalPath, Environment.GetEnvironmentVariable("PATH"));
}

[TestMethod]
public void StartSessionShouldStartVsTestConsoleWithCorrectArguments()
{
Expand Down