GIS Converter - Program App -Failed Test

Dani_S 4,966 Reputation points
2025-12-17T08:15:15.1333333+00:00

Hi Michel,

Thank you very much for your help !!!

I implemented all your remarks from ticket:

https://learn.microsoft.com/en-us/answers/questions/5658212/gis-cli-commands

1.Can you please why this test is failed?

This test failed in ProgramTests.txt ?

Can you please help, to fix it ?

No args prints help

Source: ProgramTests.cs line 86

Duration: 1 ms

Message:

Assert.Equal() Failure: Values differ

Expected: 1

Actual: 0

Stack Trace:

ProgramTests.Run_NoArgs_PrintsHelp() line 96

RuntimeMethodHandle.InvokeMethod(Object target, Void arguments, Signature sig, Boolean isConstructor)**

MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

2.Relavnt Files

Program code:

Program.txt

GitConverter ConsoleApp README.txt

Programs tests:

ProgramTests.txt

GitConverter.TestsApp.ConsoleApp.txt

Thanks in advance,

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Michael Le (WICLOUD CORPORATION) 7,020 Reputation points Microsoft External Staff Moderator
    2025-12-18T02:14:37.3033333+00:00

    Hello @Dani_S ,

    Your test expects the program to return exit code 1 (AppError) when no arguments are provided, but your Program.cs is actually returning 0 (Success). If you look at line 116 in your Program.cs:

    if (args.Length == 0 || args[0] == "help" || args[0] == "--help" || args[0] == "-h")
    {
        ShowHelp();
        return (int)ExitCode.Success;  // Returns 0
    }
    

    The program returns ExitCode.Success when showing help, but your test at line 96 in ProgramTests.cs expects 1:

    Assert.Equal(1, exit);
    

    I'd recommend updating your test to expect 0 instead of 1:

    [Fact(DisplayName = "No args prints help")]
    public void Run_NoArgs_PrintsHelp()
    {
        var exit = InvokeRun(Array.Empty<string>());
        var outText = _outWriter.ToString();
        Assert.Contains("GIS Converter CLI Tool", outText, StringComparison. OrdinalIgnoreCase);
        Assert.Contains("Usage", outText, StringComparison.OrdinalIgnoreCase);
    
        // Help is a successful operation, should return 0
        Assert.Equal(0, exit);
    
    }
    

    You'll also want to remove or update the comment in your test that says // Program.Run returns AppError (1) when showing help / no args since that's not actually what's happening.

    You found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2025-12-17T08:15:31.9966667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The test failure you are experiencing is due to an assertion that checks whether the expected output matches the actual output when no arguments are provided to your program. The test expects the output to be 1, but the actual output is 0. This discrepancy indicates that the program is not functioning as intended when it is run without arguments.

    To troubleshoot this issue, consider the following steps:

    1. Check the Program Logic: Review the logic in your program to ensure that it correctly handles the case when no arguments are provided. The expected behavior should be to print help information or a similar message.
    2. Debugging: Use debugging tools to step through the Run_NoArgs_PrintsHelp() method to see why it is returning 0 instead of 1. Look for conditions that might prevent the expected output from being generated.
    3. Review Test Implementation: Ensure that the test itself is correctly set up to capture the output of your program when no arguments are passed. It might be necessary to adjust how the test captures and evaluates the output.
    4. Check for Changes: If you made recent changes to the program, verify that those changes did not inadvertently affect the output when no arguments are provided.

    By following these steps, you should be able to identify the cause of the test failure and implement a fix accordingly.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.