diff --git a/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs b/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs index d84264e6c49e..f2c31689e7fa 100644 --- a/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs +++ b/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs @@ -85,7 +85,13 @@ private int RunInternal(ParseResult parseResult, bool isHelp) actionQueue.EnqueueCompleted(); // Don't inline exitCode variable. We want to always call WaitAllActions first. var exitCode = actionQueue.WaitAllActions(); - exitCode = _output.HasHandshakeFailure ? ExitCode.GenericFailure : exitCode; + + // If all test apps exited with 0 exit code, but we detected that handshake didn't happen correctly, map that to generic failure. + if (exitCode == ExitCode.Success && _output.HasHandshakeFailure) + { + exitCode = ExitCode.GenericFailure; + } + if (exitCode == ExitCode.Success && parseResult.HasOption(MicrosoftTestingPlatformOptions.MinimumExpectedTestsOption) && parseResult.GetValue(MicrosoftTestingPlatformOptions.MinimumExpectedTestsOption) is { } minimumExpectedTests &&