vstest
vstest copied to clipboard
Debugging tests with a native debugger requires `--InIsolation` flag
With environment variable VSTEST_HOST_NATIVE_DEBUG, we can use a native debugger to debug tests but it requires --InIsolation flag.
When using the argument --tests: to run a specific test, testhost.exe is spawned twice and we must attach twice to properly debug.
When the environment variable VSTEST_RUNNER_DEBUG is set, vstest.console only waits for a managed debugger.
I propose to add new environment variable VSTEST_RUNNER_NATIVE_DEBUG to enable native debugging of vstest.conssole.
This will enable native debugging of tests without the --InIsolation flag.
The proposed code changes
diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs
index 951a4166..a153dd49 100644
--- a/src/vstest.console/CommandLine/Executor.cs
+++ b/src/vstest.console/CommandLine/Executor.cs
@@ -91,6 +91,7 @@ internal class Executor
internal Executor(IOutput output, ITestPlatformEventSource testPlatformEventSource, IProcessHelper processHelper, IEnvironment environment)
{
DebuggerBreakpoint.AttachVisualStudioDebugger(WellKnownDebugEnvironmentVariables.VSTEST_RUNNER_DEBUG_ATTACHVS);
+ DebuggerBreakpoint.WaitForNativeDebugger(WellKnownDebugEnvironmentVariables.VSTEST_RUNNER_NATIVE_DEBUG);
DebuggerBreakpoint.WaitForDebugger(WellKnownDebugEnvironmentVariables.VSTEST_RUNNER_DEBUG);
Output = output;
diff --git a/src/Microsoft.TestPlatform.Execution.Shared/WellKnownDebugEnvironmentVariables.cs b/src/Microsoft.TestPlatform.Execution.Shared/WellKnownDebugEnvironmentVariables.cs
index 83402bce..61fe4fa0 100644
--- a/src/Microsoft.TestPlatform.Execution.Shared/WellKnownDebugEnvironmentVariables.cs
+++ b/src/Microsoft.TestPlatform.Execution.Shared/WellKnownDebugEnvironmentVariables.cs
@@ -13,4 +13,5 @@ internal static class WellKnownDebugEnvironmentVariables
public const string VSTEST_HOST_DEBUG_ATTACHVS = nameof(VSTEST_HOST_DEBUG_ATTACHVS);
public const string VSTEST_RUNNER_DEBUG_ATTACHVS = nameof(VSTEST_RUNNER_DEBUG_ATTACHVS);
public const string VSTEST_HOST_NATIVE_DEBUG = nameof(VSTEST_HOST_NATIVE_DEBUG);
+ public const string VSTEST_RUNNER_NATIVE_DEBUG = nameof(VSTEST_RUNNER_NATIVE_DEBUG);
}
Sure, please go ahead and make a PR.