【go语言学习】测试程序
编写测试程序
- 源码⽂件以 _test 结尾:xxx_test.go
- 测试⽅法名以 Test 开头:func TestXXX(t *testing.T) {…}
例:
package main
import "testing"
func TestNew(t *testing.T) {
a := 33
b := 44
a, b = b, b+a
t.Logf("%d", a)
t.Logf("%d", b)
t.Log(a, "===", b)
}
执行返回
go test -v new_test.go
=== RUN TestNew
--- PASS: TestNew (0.00s)
new_test.go:9: 44
new_test.go:10: 77
new_test.go:11: 44 === 77
PASS
ok command-line-arguments 0.005s