-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed as not planned
Closed as not planned
Copy link
Labels
Milestone
Description
Problem
For large golang codebase running test can produce overwhelming test results. Developers may not care about output of all tests unless test has failed.
Solution
With new option for go test command, flag -vf (verbose when fail), developer would be able to run tests, but with verbose output of tests only if it has failed. This would reduce total test result output only to bare minimum.
Open questions
- For test functions which want to produce additional output it would be helpful to expose
io.Writerintesting.Tstruct which could be used to collect all outputs of tests in order to conditionally print entire test outputs.
// Consider having this test case in which
// output will be always written to stdout regardless
// if test has failed or not.
func TestFoo(t *testing.T) {
fmt.Printf("running test")
...
}
// In order to control outputs of tests, they would have to use
// exposed `t.Writer` which would collect outputs of tests.
// `go test` tool would then be able to decided weather data collected by
// this `t.Writer` would need to be outputted to stdout.
func TestFoo(t *testing.T) {
fmt.Fprintf(t.Writer, "running test")
...
}
// Since most codebases already use loggers, it would be quite trivial to
// create logger with `t.Writer` and pass it where necessary.
func TestFoo(t *testing.T) {
log := logger.New().WithWriter(t.Writer)
log.Debug("running test")
...
}Reactions are currently unavailable