This is a creation in Article, where the information may have evolved or changed.
Unit Tests for GO
Xxx.go's unit test corresponds to Xxx_test.go, which is the naming convention for Go engineering.
"GO Language Programming" 17 page about unit test part, one point is not very reasonable.
Add_test.go
Package Simplemath
Import"Testing"
FuncTestAdd1 (t*testing. T){
R: = Add(1,2)
     If r != 4 {
t. Errorf("ADD (1,2)failed. Got%d,expected3. " , R)
}
}
Go Test Simplemath
---fail:testadd1 (0.00s)
Add_test.go:9: Add (1, 2) failed. Got 3, expected 3.
FAIL
FAIL Simplemath 0.033s
Add_test.go
Change it, isn't it better.
Package Simplemath
Import"Testing"
FuncTestAdd1 (t*testing. T){
R: =4
     If r != add ( 1 2 ) {
t. Errorf("ADD (1,2)failed. Got%d,expected3. " , R)
}
}
Go test Simplemath
---fail:testadd1 (0.00s)
add_test.go:9: Add ( 1, 2) failed. Got 4, expected 3.
FAIL
fail simplemath 0.037s