Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do I execute tests in Debug mode using .Net Core and VSCode?

How do I execute tests in Debug mode using .Net Core and VSCode?

I am currently running the following on the command line:

dotnet Test

However, this is not executing the tests in debug mode.

Do I attach a debugger?

If so... How?

like image 386
Scott Nimrod Avatar asked Aug 05 '17 21:08

Scott Nimrod


People also ask

How do I run a test in debug mode in Visual Studio?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

How do you debug test cases in VS Code?

Once you have your launch configuration set, start your debug session with F5. Alternatively, you can run your configuration through the Command Palette (Ctrl+Shift+P) by filtering on Debug: Select and Start Debugging or typing 'debug ' and selecting the configuration you want to debug.

How do I debug a .NET core code in Visual Studio?

Open the Debug view by selecting the Debugging icon on the left side menu. Select the green arrow at the top of the pane, next to . NET Core Launch (console). Other ways to start the program in debugging mode are by pressing F5 or choosing Run > Start Debugging from the menu.


1 Answers

  1. If necessary, convert the test project to be a console app, instead of a library. For example, use

<TargetFramework>netcoreapp2.0</TargetFramework>

  1. Add a main method or function.

    // C#
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
    // F#
    module Program =
        [&ltEntryPoint&gt]
        let main(args: string[]) = 0
  1. In the main, call the test that you want to debug.

  2. Run the console application in the debugger (usually pressing F5).

This should have no effect on running dotnet test.

like image 51
Wallace Kelly Avatar answered Oct 02 '22 01:10

Wallace Kelly