This is a creation in Article, where the information may have evolved or changed.
Package Mymathfunc Add (a, b int) int { return a + B}func Max (a, b int) (ret int) { =
a if B > a { =
b } return}
Package Mymath_testimport ("MyMath" "Testing") type mathtest struct {aBret Int}var addtest=[]mathtest{mathtest{4, 6, 10},mathtest{5, 6, 11},mathtest{2,-6,-4},}var maxtest=[]mathtest{mathtest{3, 5, 5},mathtest{-3, 5, 5},mathtest{-3,-5,-3},}func testadd (t *testing. T) {for _, V: =range Addtest {ret:= MyMath. ADD (V.A,v.b) if RET!=V.ret {T.errorf ("%d add%d, want%d, but get%d", V.A, V.B, V.ret,ret)} }}func Testmax (t *testing. T) {for _, V: =range Maxtest {ret:= MyMath. Max (V.A,v.b) if RET!=V.ret {T.errorf ("The max number between%d and%d are want%d, but get%d", V.A, V.B, V.ret,ret)} }}
Test file Mymath_test.go (all test files must end with *_test.go)
Execute Go Test
http://blog.csdn.net/m718281962/article/details/8956325