1
+ // Licensed to the .NET Foundation under one or more agreements.
2
+ // The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+ using Microsoft . DotNet . Cli . Commands . Test ;
5
+ using CommandResult = Microsoft . DotNet . Cli . Utils . CommandResult ;
6
+ using ExitCodes = Microsoft . NET . TestFramework . ExitCode ;
7
+
8
+ namespace Microsoft . DotNet . Cli . Test . Tests
9
+ {
10
+ public class GivenDotnetTestRunsConsoleAppWithoutHandshake : SdkTest
11
+ {
12
+ public GivenDotnetTestRunsConsoleAppWithoutHandshake ( ITestOutputHelper log ) : base ( log )
13
+ {
14
+ }
15
+
16
+ [ InlineData ( TestingConstants . Debug ) ]
17
+ [ InlineData ( TestingConstants . Release ) ]
18
+ [ Theory ]
19
+ public void RunConsoleAppDoesNothing_ShouldReturnCorrectExitCode ( string configuration )
20
+ {
21
+ // This test validates the behavior when running `dotnet test` against a console application
22
+ // that does "nothing" and doesn't implement the MTP (Message Transport Protocol) handshake.
23
+ //
24
+ // The issue (#49733) suggests that silently ignoring such applications is not good behavior.
25
+ // This test validates that the improved behavior provides a meaningful error message.
26
+
27
+ TestAsset testInstance = _testAssetsManager . CopyTestAsset ( "ConsoleAppDoesNothing" , Guid . NewGuid ( ) . ToString ( ) )
28
+ . WithSource ( ) ;
29
+
30
+ CommandResult result = new DotnetTestCommand ( Log , disableNewOutput : false )
31
+ . WithWorkingDirectory ( testInstance . Path )
32
+ . Execute ( TestingPlatformOptions . ConfigurationOption . Name , configuration ) ;
33
+
34
+ if ( ! TestContext . IsLocalized ( ) )
35
+ {
36
+ // The new behavior should provide a clear error message indicating that
37
+ // the console app is not a test project and doesn't implement MTP
38
+ result . StdOut . Should ( ) . Contain ( "is not a test project and does not implement the testing platform protocol" ) ;
39
+ result . StdOut . Should ( ) . Contain ( "ConsoleAppDoesNothing.csproj" ) ;
40
+ }
41
+
42
+ // The new behavior should return GenericFailure exit code instead of success
43
+ result . ExitCode . Should ( ) . Be ( ExitCodes . GenericFailure ,
44
+ "dotnet test should fail with a meaningful error when run against console app without MTP handshake" ) ;
45
+ }
46
+ }
47
+ }
0 commit comments