1.文件名必须 以_test.go结尾
2.使用go test执行单元测试
创建第一个文件cacl.go
package test func Cacl(a,b int)int{ c := a+b return c }
创建测试文件cacl_test.go
package test import ( "testing" ) func TestAdd(t *testing.T){ //函数名必须是Test开头 result := Cacl(11,20) if result != 30{ t.Fatalf("not right") } t.Logf("right") }