【问题标题】:Debugging MSTest Unittests in Visual Studio Code在 Visual Studio Code 中调试 MSTest 单元测试
【发布时间】:2017-08-29 20:44:17
【问题描述】:

我正在尝试使用 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}"
        }
    ]
}

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

【问题讨论】:

标签: debugging .net-core visual-studio-code mstest


【解决方案1】:

试试https://github.com/Microsoft/vstest-docs/blob/master/docs/diagnose.md#debug-test-platform-components(假设您使用的是dotnet-cli tools 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

【讨论】:

    【解决方案2】:

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

    您需要先构建解决方案 dotnet build 才能显示测试运行和调试选项。

    【讨论】:

    • 我运行的是 1.29.1,但没有看到这些选项。
    • 首先构建您的解决方案dotnet build 并检查?
    • 如何使用这种方法运行一个项目文件(Test project)中的所有测试?
    【解决方案3】:

    尝试重新加载 VS Code,对我有用。 按 Ctrl+Shift+P 打开命令面板,然后:

    重新加载窗口

    【讨论】:

      【解决方案4】:

      在构建之前,请记住包含在您的 .csproj 文件中

      <GenerateProgramFile>false</GenerateProgramFile>

      否则它将不知道要运行什么...

      Program.cs(160,21): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. [/Users/.../Fraction.csproj]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-09
        • 1970-01-01
        • 2016-10-30
        • 2022-07-11
        • 2017-05-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多