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.

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

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面