我正在尝试使用Visual Studio代码来调试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存在同样的问题。
答案 0 :(得分:2)
尝试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
答案 1 :(得分:0)
答案 2 :(得分:0)
尝试并重新加载VS Code,这对我有用。 按Ctrl + Shift + P打开命令面板,然后:
刷新窗口
答案 3 :(得分:0)
构建之前,请记住将其包含在.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]