英文:
How do I always print a message when using go test regardless of success or failure without using verbose mode in golang?
问题
在使用go test
时,是否有一种方法可以在无论成功与否时打印一条消息,而不使用详细模式?
我正在生成虚拟数据并重复运行测试,希望始终告诉开发人员测试覆盖的案例。
在我查看的所有相关问题中,都只提到了详细模式,并且在godoc中没有找到相关内容。
英文:
Is there any way to print a message when using go test
regardless of success or failure without using verbose mode?
I'm generating dummy data and repeatedly running the test and would like to always tell developers the cases covered by the test.
Looking around all the questions I see about this just point to verbose mode and I don't see anything in the godoc.
答案1
得分: 3
在所有情况下都不行。
测试是由go test
进程编译和执行的。stdout和stderr由父进程捕获,并且只在详细模式下显示。
异常情况在测试代码中有所记录:
// 当命令行上没有给出包(隐式当前目录)或者在进行基准测试时,流式传输测试输出(无缓冲)。
因此,如果你在包目录中或者运行基准测试,stdout和stderr将通过父进程进行流式传输。
英文:
You can't in all cases.
Tests are compiled and executed by the go test
process. The stdout and stderr are captured by the parent process, and only displayed in verbose mode.
The exceptions are documented in the test code:
// stream test output (no buffering) when no package has
// been given on the command line (implicit current directory)
// or when benchmarking.
So if you are in the package directory, or running benchmarks, the stdout and stderr will be streamed through the parent process.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论