猿问

在运行“go test”时,有没有办法获得运行了多少个测试的计数?

我想获取运行测试的数量,作为校验和来检测是否所有测试都在运行。由于 Go 依赖于文件名和方法名称来确定什么是测试,因此很容易键入错误的内容,这意味着测试将被静默地跳过。go test



慕姐8265434
浏览 108回答 1
1回答

侃侃尔雅

我认为gotestsum工具接近您正在寻找的东西。它是一个包装器,用于打印格式化的测试输出和测试运行的摘要。go test违约:go testgo test ./...?&nbsp; &nbsp; &nbsp; &nbsp;github.com/marco-m/timeit/cmd/sleepit&nbsp; &nbsp;[no test files]ok&nbsp; &nbsp; &nbsp; github.com/marco-m/timeit/cmd/timeit&nbsp; &nbsp; 0.601s违约:gotestsumgotestsum&nbsp;∅&nbsp; cmd/sleepit✓&nbsp; cmd/timeit (cached)DONE 11 tests in 0.273s&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <== see here查看文档和内置帮助,它写得很好。根据我的经验,gotestsum(以及同一组织的其他工具)是好的。对我来说,能够使用标准的Go测试包,没有其他“测试框架”也非常重要。gotestsum允许我这样做。另一方面,为了真正满足您的要求(打印声明的测试数量并验证该数量是否实际运行),您需要类似TAP的东西,即Test Anything协议,它适用于任何编程语言:1..4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<== see hereok 1 - Input file openednot ok 2 - First line of the input validok 3 - Read the rest of the filenot ok 4 - Summarized correctly # TODO Not written yetTAP实际上非常好,很简单。我记得有一个Go端口,tap-go,但现在被标记为存档。
随时随地看视频慕课网APP

相关分类

Go
我要回答