DEV Community

Jonas Brømsø
Jonas Brømsø

Posted on

9 3

TIL: Colorful test output in Go

The standard command line use when testing go:



$ go test


Enter fullscreen mode Exit fullscreen mode

Colors your test output according to your terminal configuration.

@rakyll has implemented a cool tool gotest for coloring your test output, so you have passing tests colored green, failing tests marked red etc.



$ gotest


Enter fullscreen mode Exit fullscreen mode

You can customize the colors for failing tests and passing tests via environment variables using the palette of your terminal.



GOTEST_PALETTE="red,green" gotest


Enter fullscreen mode Exit fullscreen mode

The first color being for failures and the second one being for passes.

Colorful terminal test output

To find the colors in for example iTerm.app open the Preferences, your profile and the color tab.

iTerm preferences

Use the names for the colors in the environment variables

Resources and References

  1. GitHub: rakyll/gotest

This article was lifted from my TIL collection

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (2)

Collapse
 
mjgardner profile image
Mark Gardner

Might want to tag/title these with #GoLang as well as #Go. The latter is too short for search results here.

Collapse
 
jonasbn profile image
Jonas Brømsø

Done, thanks Mark

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay