我的測試文件func BenchmarkA(b *testing.B) { res := testing.Benchmark(BenchB) if res.N <= 25{ b.Fatalf("fail!") }func BenchB(b *testing.B) {for i := 0; i <= b.N; i++{ url := "****" contentType := "application/x-www-form-urlencoded" data := strings.NewReader("****") _, err := http.Post(url, contentType, data) if err != nil { b.Fatal("fail ") } }}當我跑步時go test -bench=./router_test.go我得到一個fatal error: all goroutines are asleep - deadlock!如果我使用“package main”和“func main{}”,程序可以成功運行。接下來我該怎么做?(原諒我糟糕的英語)
1 回答

紫衣仙女
TA貢獻1839條經驗 獲得超15個贊
我覺得有一種方法不是特別好
func TestA(t *testing.T) {
res := testing.Benchmark(BenchB)
if res.N <= 25{
t.Fatalf("fail!")
}
基準測試->單元測試
- 1 回答
- 0 關注
- 121 瀏覽
添加回答
舉報
0/150
提交
取消