How do I always print a message when using go test regardless of success or failure without using verbose mode in golang?

huangapple go评论68阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2017年6月10日 02:14:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/44464351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定