go测试
文章目录
Go测试
gotest文件命名格式:xxx_test.go
gotest文方法命名格式:Testxxx.go
func TestLRU(t *testing.T) {
// 测试内容
}
运行 go test -v 输出测试结果。
查看代码覆盖率
生成文件
go test -coverprofile='c.out'
查看
- 执行
go tool corver -html='c.out'会在浏览器中显示覆盖率 - 执行
go tool corver -func='c.out'打印每个方法的输出覆盖率
性能测试
func BenchAdd(b *testing.B) {
//
}
- 执行
go test -bench .会输出测试结果
生成文件
-
go test -bench . -cpuprofile cpu.out输出cpu.out文件
查看
go tool pprof cpu.out 进入交互命令行help查看帮助
生成图片(先安装graphviz)
> gif 生成一张图片
> web在浏览器中显示

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论