Quick list how to create simple Ruby project with minitest:

  • obiously you need to create new directory
  • run bundle init to generate new Gemfile
  • add minitest related gems:
group :test do
  gem 'minitest'
  gem 'minitest-reporters'
  gem 'minitest-focus'
end
  • bundle install
  • create test file and add
require 'minitest/autorun'
require 'minitest/reporters'
require 'minitest/focus'

Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]

Reporters add nice formatting to your output. Personaly, I prefer spec-like output, so I used Minitest::Reporters::SpecReporter.

The DefaultReporter gives you the following output:

The SpecReporter gives you the following output:

Run single test

Nice bonus: focus. You just need to add focus before method or it. Source

require 'minitest/autorun'
require 'minitest/focus'

class MyTest < MiniTest::Unit::TestCase
  def test_unrelated; ...; end       # will NOT run

  focus def test_method2; ...;  end  # will run (direct--preferred)

  focus
  def test_method; ...;  end         # will run (indirect)

  def test_method_edgecase; ...; end # will NOT run
end

# or, with spec-style:

describe 'MyTest2' do
  focus; it 'does something'       do pass end
  focus  it('does something else') {  pass   } # block precedence needs {}
end