douye9822 2016-09-27 21:46
浏览 297
已采纳

Golang测试在详细模式下运行时给出不一致的结果

I have a single test function in my _test.go file with a bunch of sub tests. It looks like this:

func MyTest(t *testing.T) { 
    t.Run("Subtest1", func(t *testing.T) {
       ...
    })
    t.Run("Subtest2", func(t *testing.T) {
       ...
    })
}

I run the test with go test and get

PASS
ok      package_path    9.137s

However, I would like to see listed all my subtests in the result. Looking at the Run function in $GOROOT/src/testing/testing.go it looks like I need the test to be chatty.

So I tried to run the test via go test -v but I still do not get the desired output. Instead my test is now failing:

=== RUN   MyTest
api.test: error: expected argument for flag '-t', try --help
exit status 1
FAIL    package_path    0.004s

--help does not show anything about -t

  • 写回答

1条回答 默认 最新

  • douji1853 2016-10-13 01:57
    关注

    This turned out to be a problem with the code I was testing which expects its own arguments and contained this line:

    kingpin.MustParse(cli.Parse(os.Args[1:]))
    

    I know disallow parsing of arguments in the test.

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大