如何使用.Net Core和VSCode在调试模式下执行测试?
我目前在命令行上运行以下命令:
dotnet Test
Run Code Online (Sandbox Code Playgroud)
但是,这不是在调试模式下执行测试.
我附加调试器吗?
如果是这样......怎么样?
在 VSCode 的 1.17.2 版(安装了 C# 扩展)中,我通过将一个 MSTest 项目添加到解决方案文件夹中,dotnet new mstest并添加了对正在使用dotnet add <project_path>.
鉴于下面的两个 VSCode 任务,我可以成功构建和运行测试;即一切构建,单元测试运行并通过。
{
"version": "2.0.0",
"tasks": [
{
"taskName": "build",
"command": "dotnet build src/tests/tests.csproj",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"taskName": "test",
"command": "dotnet test src/tests/tests.csproj",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法使用集成调试器点击断点或以其他方式单步执行单元测试。我提出的最接近的启动配置将运行测试,但调试器不会命中断点或附加到任何内容。
{
"name": "test",
"type": …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 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 也存在同样的问题。