1、运行文件夹下所有单元测试
go test
2、运行单个文件
go test -v add_test.go add.go
3、运行单个方法
go test -v -test.run Test_Add
1、运行文件夹下所有压力测试
go test -test.bench=”.*”
2、运行单个文件
go test add_bench_test.go add.go -test.bench=”.*”
3、运行单个方法
go test -v -test.run BenchmarkAdd -test.bench=”.*”
package add
func Add(a,b int) int {
return a+b
}
package add
import "testing"
func Test_Add(t *testing.T) {
if Add(1,2) == 3{
t.Log("pass")
}
}
package add
import "testing"
func BenchmarkAdd(b *testing.B) {
for i:=0; i<b.N; i++{
Add(1,2)
}
}