/test-bench

A test framework for ruby

Primary LanguageRuby

Test Bench

Test Bench is a test framework for ruby designed to offer the minimum set of features necessary to test well designed code effectively. There are no hooks for test setup, teardown, defining variables, sharing tests, custom reporters, or plugins. There is no mocking library. There is but one output format, inspired by RSpec’s original output. There is no DSL in play that resembles human language. There are no matchers or a large bank of esoteric assertions you will probably never use. In fact, there are only three methods: assert, test, and context.

For more information about why Test Bench was created and the reasoning behind it’s design, see Rationale.

Quick Start Guide

Before getting started, I recommend skimming through the documentation referenced after this guide. Afterwards, to get started with Test Bench, either install the test_bench gem on your local system or add it to a project you’d like to use Test Bench with.

To install the gem locally:

# gem install test_bench

Or, to add it to the project via Bundler:

gem 'test_bench'

Second, write a test loader, e.g. tests/test_helper:

# Begin tests/test_helper.rb

# Load Test Bench and then activate it
require 'test_bench/activate'

# Load the code under test
require_relative '../lib/my/code.rb'

# End tests/test_helper.rb

Then add ruby files to your test directory that require the test loader via require_relative:

# Begin tests/some_test_file.rb

require_relative './test_helper'

context "Some subject" do
  test "Some test" do
    assert true
  end

  context "Some nuance" do
    test "Some other test" do
      assert false # Will fail!
    end
  end
end

# End tests/some_test_file.rb

Now, if you want to run that test file, just load it through the ruby executable, e.g. ruby tests/some_test_file.rb. If you want to run all the tests in the tests/ directory, the bench executable that ships with the test_bench gem can do just that:

# bench tests/

That will get you started, though it’s a good idea to read through all the documentation. Also, that bench executable offers a few useful options, so be sure to check out the help via bench --help. Finally, Test Bench’s test suite itself serves as an example for reference.

  1. Rationale

  2. Basic Usage

  3. Assertions

  4. Controlling Execution

  5. Extending Test Bench (Plugins)

License

Test Bench is licensed under the MIT license.

Copyright © Nathan Ladd