範例
在專案根目錄新增 example 資料夾,並新增 math.go 檔:
1  | package example  | 
新增 math_test.go 檔:
1  | package example  | 
執行測試:
1  | go test example/math.go example/math_test.go  | 
套件
下載 stretchr/testify 套件。
1  | go get github.com/stretchr/testify  | 
修改 math_test.go 檔:
1  | package example  | 
執行測試:
1  | go test example/math.go example/math_test.go  | 
指令
單一資料夾執行測試:
1  | go test ./example/...  | 
所有資料夾執行測試:
1  | go test ./...  | 
查看詳細訊息:
1  | go test -v ./...  | 
查看覆蓋率:
1  | go test -cover ./...  |