Up and Running with Minitest

1 min read

I love minitest. Minitest is simple. There’re a few ways to write tests, and they are so intuitive. I learned it last year, when I got into Ruby, and since then I haven’t really felt the need to dive into the docs that frequently. It just works.

That said, I do find myself doing the minitest setup for my side-projects and quick-off learning projects often. Maybe you’re the same. So here’s a quick guide to rapidly get up and running with minitest in less than 2 minutes.

First, initialize a new project in your project directory:

bundle init

Install minitest using bundler.

bundle add minitest

Add a Rakefile.

require "minitest/test_task"

Minitest::TestTask.create(:test) do |t|
  t.libs << "test"
  t.libs << "lib"
  t.warning = false
  t.test_globs = ["test/**/*_test.rb"]
end

task :default => :test

Create a test directory and add the first test in it.

require 'minitest/autorun'
require 'lib/instance'

class TestSomething < Minitest::Test
  def setup
    @instance = Instance.new
  end

  def test_something
    assert_equal 12, 3*4
  end
end

That’s it. Run the test using the rake command.