说明
测试基础
文件名: 以_test.go 结尾
依赖包: testing
功能函数名: Test开头后接大写字母(若后接小写字母将无法识别)
测试函数模板:func TestFunc(t *testing.T){}
命令行:
* go test
* go test -v //逐个函数测试
* go test -v -run="pattern"//只测试函数名匹配的函数
实例
1 | //word.go |
1 | //word_test.go |
随机测试
通过测试用例随机化来扩展测试的覆盖范围
1 | func randomPalindrome(rng *rand.Rand) string{ |