How To: Debugging a C# test step with VS Code using the EditorX Community Edition

Using a current version of VS Code, its pretty easy to setup debugging with the Editor-X “Community Edition” on Windows.

Here are the steps I did:

Setup

  1. Add Editor X to your .csproj. This will install Editor X from the OpenTAP Repository on restore/build of your project. The current version of Editor X is 1.5.0
<Project>
.
.
.
  <ItemGroup>
    <OpenTapPackageRepository Include="https://packages.opentap.io" />
    <PackageReference Include="OpenTAP" Version="$(OpenTapVersion)" />
    <OpenTapPackageReference Include="Editor X" />
  </ItemGroup>
</Project>
  1. Build your project, and ensure that you end up with a bin/Debug/tap.exe in your build folder
    dotnet build

  2. At this point, you will have an Editor X installation installed in your bin/Debug folder, but it needs a little modification to be run in this way with version 1.5.0 (hopefully this gets fixed soon?). You need to copythe Editor X application folder and its subfolders/content to a new location:
    FROM:
    bin\Debug\Packages\Editor X\application\...
    TO:
    bin\Debug\application\...

  3. Add a .vscode folder at the root of your project

  4. Create a tasks.json file in .vscode/tasks.json. This file will hold build instructions, so that your project will build when you start the debug task

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build",
            "group": "build",
            "command": "dotnet",
            "type": "process",
            "args": [ "build", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "Build Release",
            "group": "build",
            "command": "dotnet",
            "type": "process",
            "args": [ "build", "-c", "Release", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ],
            "problemMatcher": "$msCompile"
        }
    ]
}
  1. Add a launch.json file in .vscode/launch.json to hold your debug launch configuration.
{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "configurations": [
        {
            "name": "Debug .NET Framework with Editor X (Windows)",
            "type": "clr",
            "request": "launch",
            "preLaunchTask": "Build",
            "program": "bin/Debug/tap",
            "args": ["editorx", "--address=*", "--port=0", "--open=", "--session-url=", "--session-id=", "--run", "-v"],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            "console": "integratedTerminal",
			"internalConsoleOptions": "neverOpen"
        }
    ]
}

To break this down a bit, here is what its doing: its going to launch tap.exe specified in the program setting, using the cwd folder as the root of your project (so it picks up your plugin), and its going to pass the args to the tap process.

I scraped the args from a running editorx session, so its doing essentially the same thing as starting Editor X from the Windows Start menu.

And thats it for setup!

Debugging

Now, set a breakpoint on the first line of your test step’s Run() method:

image

From the Debugging sidebar, click the Start Debugging button with Debug .NET Framework with Editor X (Windows) selected.

image

The debugger will start and launch Editor X. Next add your test step to the plan (and do any necessary configuration for the step), then click Run!

If everything works as expected you’ll see VS Code break on your Breakpoint, and you can see the current state in the watch window, or step through the code, using the standard debug controls in VS Code.

And thats it! Adding the VS Code debugger to your toolkit is a powerful aid and can massively speedup your development process. Let us know if you have questions/comments/problems on using this process.

Happy testing :slight_smile:

3 Likes

Python plugin debugging also works with VS Code, and the Community License!

Use the launch.json described in the OpenTAP Python documentation (really just read all the instructions on that page): Debugging Your Code | OpenTAP Python Integration

You’ll have to launch Editor X from a separate Command Prompt, wait till its up, then attach to that process.

1 Like