在 Visual Studio Code 中调试 MSTest 单元测试

PWF*_*ley 6 debugging mstest .net-core visual-studio-code

我正在尝试使用 Visual Studio Code 调试 MSTest 单元测试项目。但测试只是运行,断点从未达到。

这是我的launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Test (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "C:\\Program Files\\dotnet\\dotnet.exe",
            "args": ["test"],
            "cwd": "${workspaceRoot}",
            "console": "internalConsole",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

如何调试单元测试 (MSTest)?XUnit 也存在同样的问题。

Arg*_*a C 9

如果您使用的是最新版本的 VS Code(我使用的是 v1.29.0),调试单元测试是内置功能。

在此处输入图片说明

您需要首先构建dotnet build测试运行和调试选项出现的解决方案。

  • 我正在运行 1.29.1,但没有看到这些选项。 (2认同)

Aru*_*n M 5

尝试https://github.com/Microsoft/vstest-docs/blob/master/docs/diagnose.md#debug-test-platform-components(假设您使用的是 dotnet-cli 工具 1.0.0)

> set VSTEST_HOST_DEBUG=1
> dotnet test
# Process will wait for attach
# Set breakpoint in vscode
# Use the NETCore attach config from vscode and pick the dotnet process
Run Code Online (Sandbox Code Playgroud)