首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用delve调试测试

用delve调试测试
EN

Stack Overflow用户
提问于 2017-04-12 22:17:23
回答 2查看 14.7K关注 0票数 23

我使用"go test -v“来运行一系列单元测试。我想使用delve调试它们。当我尝试运行调试器时,我得到一个“无法调试非主包”错误。那么,如何使用delve调试器来调试单元测试呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-14 01:06:42

使用dlv test

代码语言:javascript
复制
$ 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文件供您清理。

票数 32
EN

Stack Overflow用户

发布于 2017-04-12 23:29:20

我对delve并不熟悉,但是如果它可以在编译后的二进制文件上工作,只需使用-c标志编译您的测试:

代码语言:javascript
复制
    -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.

然后运行深入研究输出。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43380530

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档