Package mymathfunc add (,B INT) int {return a + B} func max (,B INT) (Ret INT) {RET=A If B> A {RET=B} return}
Package mymath_testimport ( "Mymath" "testing" ) Type mathtest struct { , B, RET int} var addtest = [] Mathtest { 4, 6, 10 }, Mathtest { 5, 6, 11 }, Mathtest { 2,-6,-4 }, } Var maxtest = [] Mathtest { 3, 5, 5 }, Mathtest {- 3, 5, 5 }, Mathtest {- 3,-5,-3 }, } Func testadd (T * testing. t) {_ , V: = Range addtest {RET: = Mymath. Add (V., 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) {_ , V: = Range maxtest {RET: = Mymath. Max (V., V. B) If RET! = V. Ret {T. errorf ( "The Max number between % d and % d is 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)
Run Go test
Http://blog.csdn.net/m718281962/article/details/8956325