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
9 changes: 9 additions & 0 deletions src/Cli/dotnet/commands/dotnet-test/VSTestForwardingApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public VSTestForwardingApp(IEnumerable<string> argsToForward)

private static string GetVSTestExePath()
{
// Provide custom path to vstest.console.dll or exe to be able to test it against any version of
// vstest.console. This is useful especially for our integration tests.
// This is equivalent to specifying -p:VSTestConsolePath when using dotnet test with csproj.
string vsTestConsolePath = Environment.GetEnvironmentVariable("VSTEST_CONSOLE_PATH");
if (!string.IsNullOrWhiteSpace(vsTestConsolePath))
{
return vsTestConsolePath;
}

return Path.Combine(AppContext.BaseDirectory, VstestAppName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FluentAssertions;
using Xunit;
using System;
using System.IO;

namespace Microsoft.DotNet.Cli.MSBuild.Tests
{
Expand All @@ -16,5 +17,23 @@ public void ItRunsVsTestApp()
new VSTestForwardingApp(new string[0])
.GetProcessStartInfo().Arguments.Should().EndWith("vstest.console.dll");
}

[Fact]
public void ItCanUseEnvironmentVariableToForceCustomPathToVsTestApp()
{
string vsTestConsolePath = "VSTEST_CONSOLE_PATH";
string dummyPath = Path.Join(Path.GetTempPath(), "vstest.custom.console.dll");

try
{
Environment.SetEnvironmentVariable(vsTestConsolePath, dummyPath);
new VSTestForwardingApp(new string[0])
.GetProcessStartInfo().Arguments.Should().EndWith("vstest.custom.console.dll");
}
finally
{
Environment.SetEnvironmentVariable(vsTestConsolePath, null);
}
}
}
}