我用"go test -v"来运行一系列单元测试.我想用delve来调试它们.当我试图运行调试器时,我得到一个"Can not debug non-main package"错误.那么,我如何使用delve调试器来调试单元测试呢?
我用"go test -v"来运行一系列单元测试.我想用delve来调试它们.当我试图运行调试器时,我得到一个"Can not debug non-main package"错误.那么,我如何使用delve调试器来调试单元测试呢?
使用dlv test
:
$ dlv test -- -test.v
Type 'help' for list of commands.
(dlv) continue
=== RUN TestReadFileError
--- PASS: TestReadFileError (0.00s)
=== RUN TestReadFile
--- PASS: TestReadFile (0.00s)
[..]
PASS
Process 8014 has exited with status 0
(dlv) quit
Process 8014 has exited with status 0
您也可以通过-test.run
来 Select 要运行的测试(就像go test -run
一样).
在内部,这与Flimzy的答案相同(它用go test -c
编译测试二进制文件),但更加精简,不会离开.要清理的测试文件.