Debugging xUnit tests in .NET Core and Visual Studio Code

后端 未结 4 1106
死守一世寂寞
死守一世寂寞 2020-12-05 02:02

I\'m on a Mac, running .NET Core 1.0 and Visual Studio Code.

I have a console project and a test project. I have setup launch.json so that I can debug the console pr

4条回答
  •  甜味超标
    2020-12-05 02:17

    I was able to run the debugger on an entire xUnit project with the following complicated launch config. I inspected the calls the "debug test" link (in @Tyler Long response above) was making through the C# (Omnisharp) VS Code extension to figure this out. Things to note: 1) you must provide the absolute path to the dotnet program 2) you must provide the absolute path (i.e. you cannot use ~/ or $HOME/) to .nuget/packages folders 3) in the example below, the name of my test project namespace is Tests. Once you have this launch config in place, you can place breakpoints(s), launch the debugger using this config and it should hit all the breakpoints.

    {
      "name": "Debug xunit tests",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "/usr/local/share/dotnet/dotnet",
      "args": [
        "exec",
        "--runtimeconfig",
        "${workspaceRoot}/AppNameHere/bin/Debug/netcoreapp1.0/AppNameHere.runtimeconfig.json",
        "--depsfile",
        "${workspaceRoot}/AppNameHere/bin/Debug/netcoreapp1.0/AppNameHere.deps.json",
        "--additionalprobingpath",
        "/Users/jdoe/.nuget/packages",
        "/Users/jdoe/.nuget/packages/dotnet-test-xunit/1.0.0-rc2-build10015/lib/netcoreapp1.0/dotnet-test-xunit.dll",
        "${workspaceRoot}/AppNameHere/bin/Debug/netcoreapp1.0/AppNameHere.dll",
        "-namespace",
        "Tests"
      ],
      "cwd": "${workspaceRoot}",
      "stopAtEntry": false
    }
    

提交回复
热议问题