go test指令

go test 默认执行当前目录下以xxx_test.go的测试文件。
go test -v 可以看到详细的输出信息。
go test -v xxx_test.go 指定测试单个文件,但是该文件中如果调用了其它文件中的模块会报错。

指定某个测试函数运行:
go test -v -test.run Testxxx
注意: 该测试会测试包含该函数名的所有函数,即如果待测试的函数名是TestSyncResourceQuota,那么指令go test -v -test.run TestSyncResourceQuota会测试包含该函数名的所有函数(比如下面的TestSyncResourceQuotaSpecChange、TestSyncResourceQuotaSpecHardChange等函数),详细如下:

root@fstgb014:~/go-work/src/k8s.io/kubernetes/pkg/controller/resourcequota# go test -v -test.run TestSyncResourceQuota
=== RUN   TestSyncResourceQuota
--- PASS: TestSyncResourceQuota (0.00s)
=== RUN   TestSyncResourceQuotaSpecChange
--- PASS: TestSyncResourceQuotaSpecChange (0.00s)
=== RUN   TestSyncResourceQuotaSpecHardChange
--- PASS: TestSyncResourceQuotaSpecHardChange (0.00s)
=== RUN   TestSyncResourceQuotaNoChange
--- PASS: TestSyncResourceQuotaNoChange (0.00s)
PASS
ok      k8s.io/kubernetes/pkg/controller/resourcequota  0.148s
    原文作者:Mark_Zhang
    原文地址: https://www.jianshu.com/p/1a9d9ed6a851
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞