···184184}
185185```
186186187187+### Capturing Stdout and Stderr
188188+189189+We've all been there, trying to test a function that prints but doesn't accept an `io.Writer` as a destination 🙄.
190190+191191+That's where `test.CaptureOutput` comes in!
192192+193193+```go
194194+func TestOutput(t *testing.T) {
195195+ // Function that prints to stdout and stderr, but imagine this is defined somewhere else
196196+ // maybe a 3rd party library that you don't control, it just prints and you can't tell it where
197197+ fn := func() error {
198198+ fmt.Fprintln(os.Stdout, "hello stdout")
199199+ fmt.Fprintln(os.Stderr, "hello stderr")
200200+201201+ return nil
202202+ }
203203+204204+ // CaptureOutput to the rescue!
205205+ stdout, stderr := test.CaptureOutput(t, fn)
206206+207207+ test.Equal(t, stdout, "hello stdout\n")
208208+ test.Equal(t, stderr, "hello stderr\n")
209209+}
210210+```
211211+212212+Under the hood `CaptureOutput` temporarily captures both streams, copies the data to a buffer and returns the output back to you, before cleaning everything back up again.
213213+187214### Credits
188215189216This package was created with [copier] and the [FollowTheProcess/go_copier] project template.