1 文件名

xxx_test.go
image.png

2 函数名

(1) function.go

  1. package fk
  2. func square(op int) int {
  3. return op*op + 1
  4. }

(2) function_test.go

  1. package fk
  2. import "testing"
  3. func Test111(t *testing.T) {
  4. inputs := [...]int{1, 2, 3}
  5. expected := [...]int{1, 4, 9}
  6. for key, val := range inputs {
  7. ret := square(val)
  8. if ret != expected[key] {
  9. t.Errorf("input is %d, expected %d, actual %d", key, expected[key], ret)
  10. }
  11. }
  12. }

image.png