用delve调试测试 [英] Debugging tests with delve

查看:525
本文介绍了用delve调试测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用go test -v 运行一堆单元测试。我想用delve调试它们。当我尝试运行调试器时,出现无法调试非主包错误。那么,我该如何使用delve调试器来调试单元测试呢?

只要使用 dlv test

  $ dlv test  -  -test.v 
输入'help'获取命令列表。
(dlv)continue
=== RUN TestReadFileError
--- PASS:TestReadFileError(0.00s)
=== RUN TestReadFile
--- PASS:TestReadFile (0.00s)
[..]
PASS
过程8014退出状态0
(dlv)退出
过程8014退出状态0

您也可以传递 -test.run 来选择测试(就像 go test -run )。



在内部,这与Flimzy的答案相同使用 go test -c )编译测试二进制文件,但更简化并且不会留下.test文件供您清理。


I'm using "go test -v" to run bunch of unit tests. I'd like to debug them using delve. When I try to run debugger, I get an "Can not debug non-main package" error. So, how can I debug unit tests using delve debugger ?

解决方案

Just use 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

You can also pass -test.run to select tests to run (just like go test -run).

Internally, this is the same as Flimzy's answer (it compiles the test binary with go test -c), but more streamlined and won't leave .test files for you to clean up.

这篇关于用delve调试测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆