gotestfmt: go test output for humans


Reading the go test output can be quite tiresome, especially when multiple tests are running in parallel. While IDEs make our lives easier, CI systems don’t have that advantage. Let’s fix that!

The project is available on GitHub.

Have you ever been in a situation where the CI system gave you a test log of a few megabytes and you had to find a but in it? Even worse, the test run was in parallel, so the log had lines from various tests running in parallel in them?

Go somewhat mitigates this problem by providing the t.Log() and t.Logf() functions, which let you interweave the output like this:

=== RUN   TestParallel1
=== PAUSE TestParallel1
=== RUN   TestParallel2
=== PAUSE TestParallel2
=== CONT  TestParallel1
    parallel_test.go:10: Test message 1
=== CONT  TestParallel2
=== CONT  TestParallel1
    parallel_test.go:12: Test message 2
--- PASS: TestParallel1 (5.01s)
=== CONT  TestParallel2
    parallel_test.go:18: Test message 1
    parallel_test.go:20: Test message 2
--- PASS: TestParallel2 (10.02s)
ok    10.048s

While this makes sense, it still doesn’t make it readable. To a human, at least. Development environments can pick these apart, so you’ll have a nicely formatted output, but in CI systems you’ll have to find a tool to take care of that.

There are a great many tools out there that transform the reports in, for example, the JUnit XML format. One such example is gotestsum. However, the resulting XML or JSON file still needs to be transformed to create beautiful, easy to use output in the CI system.

GitHub Actions, for example, lets you use workflow commands to create foldable sections or issue warnings for file lines.

So, we set out to solve this problem: create a simple utility that takes the go test output and transforms it into beautiful, colored, foldable logs with icons on GitHub actions or other CI systems.

A showcase of a classic log and the reformatted log next to each other.

The result is gotestfmt, a tool that you can install into your GitHub Actions pipeline in under 5 minutes, or integrate with other CI systems quickly by creating a custom rendering template.

gotestfmt 2.3.0: Non-zero exit status

Gotestfmt now returns with a non-zero exit status on test failure.

gotestfmt 2.2.0: Output Formatters

Do you want to further format the test case output? Now you can.

gotestfmt 2.1.0: Flag to show test status printed out

Confused by the icons? A contribution by Martin Petkov now adds the option to add a written status text. Also, bugfixes.

gotestfmt 2.0.0: switching to JSON output

Gotestfmt now runs exclusively on JSON output.

gotestfmt 1.1.0: support for other CI systems

Gotestfmt now has support for GitLab CI, CircleCI, and more!