dongshi2588 2017-03-23 10:04
浏览 40
已采纳

用包调用go 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).

  • 写回答

1条回答 默认 最新

  • dsbgltg159136540 2017-03-23 10:19
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 MATLAB四叉树处理长方形tif文件
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了