#青训营 x 字节后端训练营#
利用test包对测试集进行测试,可以用于测试覆盖率
package example
import "testing"
func TestAdd(t *testing.T) {
if ans := Add(1, 2); ans != 3 {
t.Errorf("1 + 2 expected be 3, but %d got", ans)
}
if ans := Add(-1, -2); ans != -3 {
t.Errorf("-1 + -2 expected be -3, but %d got", ans)
}
}