在打包测试时输出的差异 [英] Difference in output when calling go test with package

查看:115
本文介绍了在打包测试时输出的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Go项目,我在其中使用 glide 进行包管理。



使用 TestMain go test 的测试套件设置使用 godog c $ c> wrapper,如文档中所述 godoc (格式漂亮)。



自我不想测试我正在推销的软件包,我用

  go test $(glide novendor)

在我的例子中,这个项目非常简单,并且 glide novendor 只是返回一个



现在我的问题是:为什么当运行 go test 时,我得到了很多漂亮的输出,列出了场景和步骤,以及什么,但是当我运行 go test。我只是得到一行

  ok gitlab.knf.local / ngs / gpp 0.015s [没有测试运行] 

(即使我添加虚拟测试)。

解决方案

输出结果不同,因为这是Go工具的编写方式。这是有意的默认行为。



如果您只运行 go test 而不列出软件包,它会测试包在当前目录中:


默认情况下,go test不需要参数。它编译和测试当前目录中的源代码包,包括测试,并运行测试。


如果您将软件包列为 go test (可能只是一个包或者只是一个,没关系),那么 go test 将测试所有列出的软件包。



如果您测试单个软件包,您希望查看每个软件包的详细信息和结果试验。如果你测试多个软件包,通常你对每个单独测试的细节都不感兴趣,因为这会让你的屏幕变得混乱,而且随着信息在屏幕上滚动,你甚至不会注意到测试或软件包是否失败。在测试多个软件包时,通常您只是对每个软件包的最终结果感兴趣。如果您在列出软件包时仍希望看到更详细的输出,只需将 -v flag:

  go test -v $(glide novendor)

有关更多详细信息和选项,请运行 go help test 和/或访问命令行文档页面,具体为测试包测试标志说明


I have a Go project in which I'm using glide for package management.

I have a test suite setup using godog, which I run with go test using a TestMain wrapper as described in the docs of godoc (with format pretty).

Since I don't want to test packages I am vendoring, I call the tests with

go test $(glide novendor)

In my case, the project is very simple, and glide novendor just returns a .

Now my question is: Why is it that when running go test, I get a lot of pretty output, listing scenarios and steps and whatnot, but when I run go test . I just get a one-liner

ok      gitlab.knf.local/ngs/gpp        0.015s [no tests to run]

(This doesn't change even if I add a dummy test).

解决方案

The output is different because this is how the Go tool is written. This is the intentional, default behavior.

If you just run go test without listing packages, it will test the package in the current directory:

By default, go test needs no arguments. It compiles and tests the package with source in the current directory, including tests, and runs the tests.

If you list packages to go test (may it be just a single package or just a ., doesn't matter), then go test will test all listed packages.

If you test a single package, you want to see the details and result of each tests. If you test multiple packages, normally you're not interested in the details of each individual tests, because that would just clutter your screen, and as information scrolls through your screen, you would not even notice if a test or a package fails. When testing multiple packages, normally you're just interested in the final result for each package. One line per package is a nice compromise and gives a clear result.

If you still want to see more verbose output when listing packages, simply pass the -v flag:

go test -v $(glide novendor)

For more details and options, run go help test, and/or visit the Command go documentation page, specifically sections Test packages and Description of testing flags.

这篇关于在打包测试时输出的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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