Go语言自带一个轻量级测试框架testing和go test命令来实现单元测试(T类型)和性能测试(B类型)。单元测试表格驱动测试main.gopackage main
import (
"math"
)
func triangle(a, b int) int {
c := int(math.Sqrt(float64(a*a + b*b)))
return c
}
func main() {
a, b := 3, 4
c := triangle(a, b)
println(c)
}main_test.gopackage main
import "testing"
func TestTriangle(t *testing.T) {
tests := []struct{ a, b, c int }{
{3, 4, 5},
{5, 12, 13},
{8, 15, 17},
{12, 35, 37},
{30000, 40000, 50000},
}
for _,
三毛