go test使用记录
Posted weiweng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go test使用记录相关的知识,希望对你有一定的参考价值。
go test测试包
go test {测试文件所在包目录}
当前目录下单测指定测试函数
$ go test -v -test.run {函数名xxx}
cover信息采集用例
go test -coverprofile cp.out
-go tool cover -html=cp.out
其他信息采集
-blockprofilerate n
:goroutine 阻塞时候打点的纳秒数。默认不设置就相当于 -test.blockprofilerate=1,每一纳秒都打点记录一下。-coverprofile cover.out
:在所有测试通过后,将覆盖概要文件写到文件中。设置过 -cover。-cpuprofile cpu.out
:在退出之前,将一个 CPU 概要文件写入指定的文件。-memprofile mem.out
:在所有测试通过后,将内存概要文件写到文件中。-memprofilerate n
:开启更精确的内存配置。如果为 1,将会记录所有内存分配到 profile。
bench测试
-
go test -bench=.
-
go test -bench=ww
:只执行函数名中带ww的性能测试函数
显示测试流程
go test me/food -v
以上是关于go test使用记录的主要内容,如果未能解决你的问题,请参考以下文章
[未解决问题记录]python asyncio+aiohttp出现Exception ignored:RuntimeError('Event loop is closed')(代码片段
[Go] 通过 17 个简短代码片段,切底弄懂 channel 基础
解决go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘(代码片段
[React Testing] Use Generated Data in Tests with tests-data-bot to Improve Test Maintainability(代码片段