Reputation: 442
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?
Upvotes: 1
Views: 271
Reputation: 925
Try to use -failfast
. Following an example.
$ go test -failfast -coverprofile=coverage.out -covermode=count <pkg path>
Upvotes: 1
Reputation: 273536
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.
Upvotes: 2