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