当前位置 主页 > 服务器问题 > Linux/apache问题 >
使用下面的命令, 生成 CPU 的 profile:
go test -v -bench="BenchmarkGenShortID$" --run=none -cpuprofile cpu.out ./util/
当前目录下, 应该会生成 cpu.out 文件和 util.test 文件.
使用下面的命令, 观察耗时操作:
# 进入交互模式 go tool pprof cpu.out top
安装 Graphviz 后可以生成可视化的分析图.
apt install graphviz go tool pprof -http=":" cpu.out
测试覆盖率
root@592402321ce7:/workspace# go test -v -coverprofile=cover.out ./util/ === RUN TestGenShortID --- PASS: TestGenShortID (0.00s) PASS coverage: 9.1% of statements ok tzh.com/web/util 0.005s coverage: 9.1% of statements root@592402321ce7:/workspace# go tool cover -func=cover.out tzh.com/web/util/util.go:12: GenShortID 100.0% tzh.com/web/util/util.go:17: GetReqID 0.0% tzh.com/web/util/util.go:22: TimeToStr 0.0% tzh.com/web/util/util.go:30: GetTag 0.0% total: (statements) 9.1%
使用 -coverprofile=cover.out 选项可以统计测试覆盖率.使用 go tool cover -func=cover.out 可以查看更加详细的测试覆盖率结果,
统计每个函数的测试覆盖率.
总结
测试是开发中非常重要的一个环节, 用于保证软件质量, 切不可偷懒.
当前部分的代码
作为版本 v0.15.0
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持IIS7站长之家。