Rust unit tests are compiled as separate binaries, which means you debug them exactly the same as any other binary. Once compiled, they are located at ./target/debug/$name-$hash
.
Visual Studio Code
Here's modified versions of the VS Code configuration files that allow me to debug a unit test.
tasks.json
{
"type": "shell",
"label": "cargo test build",
"command": "cargo",
"args": [
"test", "--no-run"
],
"problemMatcher": [
"$rustc"
]
}
launch.json
{
"name": "Run Test Debugger",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/buggin-70708b3916187eeb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "cargo test build",
}
Working
Windbg
Build your tests:
cargo test --no-run
Open the built executable in Windbg and open the source file.
Finding the hash is the most annoying aspect. The best solution I know of is to write a small script that builds the tests and then finds the test executable based on which is newest. My Powershell skills are not adequate to the task, nor do I know how to directly integrate this with VS Code or Windbg.
There are open issues for Cargo to help with identifying the file:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…