去测试./package转储成功测试的Stdout,而不仅仅是失败的测试

While writing a CLI tool that outputs to stdout, I noticed that if one test fails, then whatever the other (successful) tests had also written to stdout gets dumped out as well, which is misleading.

Is this to be expected, or should I set os.Stdout to /dev/null while testing? but then how would the testing package find anything to print out?

The test package doesn't interfere with the standard output of code under test, whether it passes or fails. If it's important for you not to see this output, you can capture stdout while executing your specific test and then decided what to do with it based on the test outcome.

Try to use -failfast. Following an example.

$ go test -failfast -coverprofile=coverage.out -covermode=count <pkg path>