一,Go testing 库 testing.T 和 testing.B 简介
testing.T
判定失败接口
Fail 失败继续
FailNow 失败终止
打印信息接口
Log 数据流 (cout 类似)
Logf format (printf 类似)
SkipNow 跳过当前测试
Skiped 检测是否跳过
综合接口产生:
Error / Errorf 报告出错继续 [ Log / Logf + Fail ]
Fatel / Fatelf 报告出错终止 [ Log / Logf + FailNow ]
Skip / Skipf 报告并跳过 [ Log / Logf + SkipNow ]
testing.B
首先 , testing.B 拥有testing.T 的全部接口。
SetBytes( i uint64) 统计内存消耗, 如果你需要的话。
SetParallelism(p int) 制定并行数目。
StartTimer / StopTimer / ResertTimer 操作计时器
testing.PB
Next() 接口 。 判断是否继续循环
二,基准测试——通过基准测试来检查性能
文件名
*_b_test.go也可以和*_test.go同文件
函数名
必须以Benchmark开头,如BenchmarkX..或Benchmark_xxx
函数参数
必须是指向testing.B的指针:b *testing.B
注:
指向testing.B类型的指针很重要。
这个指针提供的机制可以报告每个测试的输出和状态。
测试的输出格式没有标准要求
测试函数中打印信息,b.Log(),b.Logf()
测试所有go文件&#