Skip to content
/ bolt Public

A nicer test runner for golang

License

Notifications You must be signed in to change notification settings

fnando/bolt

Repository files navigation

Bolt: a nicer test runner for golang

A nicer test runner for golang.

Latest release Tests

We've all been there... a bunch of tests failing and you have no idea where to start, because everything looks the same. And that one test failing in the sea of passing tests? So frustrating. Not anymore!

With bolt you'll see a progress output while tests are being executed. Once tests are done, you'll see an output with only the tests that failed. Simple and easy!

Here's the before and after:

A screenshot showing the comparison between the native output versus bolt's

Features:

  • Colored output
  • Dotenv files support
  • Coverage output
  • Slowest tests output
  • Benchmark output

Install

Download the binary for your system from the latest release and place it anywhere on your path (you'll need to make it executable with chmod +x).

Usage

bolt wraps go test. You can run it with:

$ bolt run ./...

Options:

$ bolt -h

bolt is a golang test runner that has a nicer output.

  Usage: bolt [command] [options]

  Commands:

    bolt version                  Show bolt version
    bolt run                      Run tests
    bolt update                   Update to the latest released version
    bolt [command] --help         Display help on [command]


  Further information:
    https://github.com/fnando/bolt

To get the latest download url for your binary, you can use bolt download-url.

Reporters

bolt comes with two different reporters:

JSON

The JSON reporter outputs a nicer JSON format that can be used to do things that require structured data.

$ bolt run ./... --reporter json

Progress

The progress reporter outputs a sequence of characters that represent the test's status (fail, pass, skip). Once all tests have been executed, a summary with the failing and skipped tests, plus a coverage list is printed.

$ bolt run ./... --reporter progress

Overriding colors

You can override the colors by setting the following env vars:

export BOLT_TEXT_COLOR="30"
export BOLT_FAIL_COLOR="31"
export BOLT_PASS_COLOR="32"
export BOLT_SKIP_COLOR="33"
export BOLT_DETAIL_COLOR="34"

To disable color output completely, just set NO_COLOR=1.

Overriding symbols

To override the characters, you can set some env vars. The following example shows how to use emojis instead:

export BOLT_FAIL_SYMBOL=❌
export BOLT_PASS_SYMBOL=⚡️
export BOLT_SKIP_SYMBOL=😴

Post Run Command

You can run any commands after the runner is done by using --post-run-command. The command will receive the following environment variables.

  • BOLT_SUMMARY: a text summarizing the tests
  • BOLT_TITLE: a text that can be used as the title (e.g. Passed!)
  • BOLT_TEST_COUNT: a number representing the total number of tests
  • BOLT_FAIL_COUNT: a number representing the total number of failed tests
  • BOLT_PASS_COUNT: a number representing the total number of passing tests
  • BOLT_SKIP_COUNT: a number representing the total number of skipped tests
  • BOLT_BENCHMARK_COUNT: a number representing the total number of benchmarks
  • BOLT_ELAPSED: a string representing the duration (e.g. 1m20s)
  • BOLT_ELAPSED_NANOSECONDS: an integer string representing the duration in nanoseconds

Code of Conduct

Everyone interacting in the bolt project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Developing

To generate new test replay files, you can use go test -cover -json -tags=reference ./test/reference/package > test/replays/[case].txt.

To generate new benchmark replay files, you can use go test -json -fullpath -tags=reference -bench . ./test/reference/bench &> test/replays/benchmark.txt.

Once files are exported, make sure you replace all paths to use /home/test as the home directory, and /home/test/bolt as the working directory.

You can run tests with ./bin/test.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/bolt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

This project is available as open source under the terms of the MIT License.