Go语言学习11-测试
Go语言学习11-测试
单元测试
1 | // functions.go |
1 | // functions_test.go |
内置单元测试框架
- Fail, Error: 该测试失败, 该测试继续, 其他测试继续执行
FailNow, Fatal: 该测试失败, 该测试中止, 其他测试继续执行
代码覆盖率
1
go test -v -cover
Benchmark
1 | func BenchmarkConcatStringByAdd(b *testing.B) { |
benchmark命令
1 | go test -bench=. -benchmem |
-bench=\<相关benchmark测试>
Windows下使用go test
命令行时, -bench=.
应写为 -bench="."
Behavior Driven Development
“I believe that the hardest part of software projects, the most common source of project failure, is communication with the customers and users of that software. By providing a clear yet precise language to deal with domains, a DSL can help improve this communication.” – Martin Fowler.
BDD in Go
项目网站
https://github.com/smartystreets/goconvey
安装
1 | go get -u github.com/smartystreets/goconvey/convey |
启动 web ui
1 | $GOPATH/bin/goconvey |
示例
1 | func TestSpec(t *testing.T) { |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 技术匝记簿!
评论