Project Ramon

A learning journey from a Ruby noob perspective

Taking stock of Ruby’s Minitest: Introduction



I’ve been enjoying my reading of the Refactoring Ruby Edition book. I’ve also found some new learning resources that have been very exciting to participate in. I plan on resuming my reading of the Refactoring Ruby book, but today I wanted to share something that I’ve just started playing with.

One of my pairing friends I met during my time learning at AirPair, Russell Baker, pointed me to Pat Maddox’s RubySteps. I’ve only been a member for a week or so, but the lessons over there have been extremely informative, a perfect mixture of challenge and size, not to mention they’ve been a blast to walk through!

One of the other exercises I’ve just started doing to learn Ruby better is to walk through the Core API with testing. In the past, I’ve used Rspec nearly exclusively for TDD, except during my walk-thru of Ruby Koans. But this time around, I thought it would be neat to try out a new testing framework.

Introducing Minitest

Taken from the seattlerb/minitest Github page, here is an excerpt that I think explains minitest well:

minitest provides a complete suite of testing facilities supporting
TDD, BDD, mocking, and benchmarking.

And another excerpt a few paragraphs below is the reason that impulsed me to minitest a try:

minitest doesn’t reinvent anything that ruby already provides, like:
classes, modules, inheritance, methods. This means you only have to
learn ruby to use minitest and all of your regular OO practices like
extract-method refactorings still apply.

Minitest has been included in the Ruby standard library since 1.9, and is a modern, lightweight replacement for Ruby 1.8’s Test::Unit framework.

Here is a short list of features minitest provides:

  • minitest/autorun – the easy & explicit way to run all your tests
  • minitest/unit – a very fast, simple & clean test system
  • minitest/spec – a very fast, simple & clean spec system
  • minitest/mock – a simple & clean mock/stub system
  • minitest/benchmark – a cool way to assert your algorithm’s performance
  • minitest/pride – show your pride in testing! (adds color to test outputs)

Now that we’re starting to get the lay of the land, lets take minitest out for a spin!

Minitest in Action

So yeah, I’ve started out with Ruby’s Array class. But before we get into that, let me show you how I set up my environment.

Heres a layout of the steps I took:

  1. Create the library testing directory & cd into the new directory
  2. Add sub folders as necessary, I started with Ruby’s Array Class, and then create your test file.
  3. Now that we have that squared away, we can type cd .. (two periods) in order to step up our file tree all the way to root, which in this example is called library_learning.
  4. Install bundler.
  5. In your text editor of choice (mine is currently Sublime Text 2), open your newly created Gemfile and add the following.


  6. Next, we install our gems
  7. And lastly we can run minitest to make sure we’re connected properly



In my next post, I’ll be covering minitest in greater detail. How to pretty up our test output, how write and run test, etc… I also have some pretty neat resources I’ve found on google, like an assertion cheat sheet, and a surprise that reminds me of the shoulda and shoulda-matchers gem I use when testing with Rspec.

Here are a couple of resources for today that I found while digging around.

  1. Simple Testing in Ruby Using Minitest (19 minute youtube video)
  2. If you’re wanting to learn Ruby, TDD, Rails, and OOP in a fun and consistent way, Check out RubySteps
  3. A sneak peak at some things I’ll be covering in future posts on minitest (by: The Ruby Learning Blog and Steve Klabnik)

Stay tuned…


Categories: Newbie, Ruby

Tags: ,

3 replies

  1. Nice introduction about Minitest. I always use RSpec in my projects, and never thought of trying different test library. The readability of RSpec is a key for me. But I know this comes with a price which is many dependencies.

    I’m interested to know about Minittest approach and way of testing, therefor I have to give it a try.
    I look forward for coming posts.

  2. Hello Ahmed! I think MiniTest::Specs (for people like us that find Rspec a more pleasing read) to be the best of both worlds. A small test framework with the descriptiveness of spec descriptions and such. Hope you’ve been well 🙂


  1. Ruby’s MiniTest::Assertions_In_Action! | Project Ramon

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s