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