我使用"go test -v“来运行一系列单元测试。我想使用delve调试它们。当我尝试运行调试器时,我得到一个“无法调试非主包”错误。那么,如何使用delve调试器来调试单元测试呢?
发布于 2017-04-14 01:06:42
使用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来选择要运行的测试(就像go test -run一样)。
在内部,这与Flimzy的答案相同(它用go test -c编译测试二进制文件),但更简化,不会留下.test文件供您清理。
发布于 2017-04-12 23:29:20
我对delve并不熟悉,但是如果它可以在编译后的二进制文件上工作,只需使用-c标志编译您的测试:
-c
Compile the test binary to pkg.test but do not run it
(where pkg is the last element of the package's import path).
The file name can be changed with the -o flag.然后运行深入研究输出。
https://stackoverflow.com/questions/43380530
复制相似问题