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.

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。