01-Go Test笔记
文章目录
Go Test笔记
Go Test
- 一个完整的单测指令可以是
go test -v -cover -gcflags=all=-l -coverprofile=coverage.out -gcflags=all=-l防止编译器内联优化导致单测出现问题
1.1 go test
go test -run=^TestDo -v ./
这里介绍几个常用的参数:
-bench regexp执行相应的 benchmarks,例如 -bench=.;-cover开启测试覆盖率;-trace=copy_trace.out生成 trace.out 文件(go tool trace copy_trace.out)-run regexp只运行 regexp 匹配的函数,例如 -run=Array 那么就执行包含有 Array 开头的函数;-count执行次数。-v显示测试的详细命令。
1.2 go test cover 生成测试覆盖度报告
go tool cover -html=coverage.out
| |
1.3 go test 文件在项目中 layout
文章作者 lucas
上次更新 2021-12-21