Use Delve to Run and Debug a Single Unit Test in Go
Go
If you want to run a single unit test in the Delve debugger for Go, here’s how you do it on the command line:
dlv test github.com/path/to/package/testsuite -- -test.run ^Test_Random$
The command is run from within path/to/package/testsuite
- the start point for the debugger will be the TestRandom
function.
Once the debugger builds the test binary and launches, you can set breakpoints relative to the start of the function. For example:
b TestRandom:5
sets a breakpoint on the 5th line of the function.
I’m fairly new to Go, and debugging from witin the go-vim plugin allows the same functionality using the :GoDebugTestFunc
command with the cursor on the required function.
So far, I prefer multiplexing with Tmux, with my code in Vim in one pane and the debugger in the other.
References
comments powered by Disqus