Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a consensus about test frameworks for Ruby 1.9.x? [closed]

A two-parter with a quick intro. Intro: I'm coming to Ruby from Perl, and I'm a bit lost among the test framework choices. I understand that there is probably no single, all-around best choice, but I can't even get a clear picture of the playing field.

So, first, MiniTest or Test::Unit? I just realized that 1.9.1 defaults to MiniTest now. I hadn't noticed since all the older Test::Unit tutorials still work fine. If you require test/unit, you actually get MiniTest as a Test::Unit emulator (!). My initial thought was to go with the default choice of MiniTest (once I knew it was there), but even very recent books don't seem interested in teaching it. Ruby Best Practices says "There are significant differences" between the two, but he chooses not to deal with them. He also runs all his tests via Test::Unit (plus some custom add-ons). The new Pickaxe also has very little about MiniTest per se, and in the chapter on testing they also use the Test::Unit emulation version of MiniTest. To clarify my first question then: is MiniTest a poor first option? Should I default to using the Test::Unit emulator?

Second, beyond the built-in options, there are Rspec, Cucumber & company for behavior driven tests. Is the community tilting strongly towards this style and this framework? Should I just start with Rspec?

I will play a bit with all three, but I'm curious to hear what kind of consensus (if any) is forming around testing in Ruby 1.9.

(A quick follow-up, as a reminder to myself and for anyone interested. See this link for a useful overview of the different invocations for Test::Unit and MiniTest in the various Rubies 1.8 to 1.9.1.)

like image 765
Telemachus Avatar asked Jul 28 '09 16:07

Telemachus


1 Answers

I have been using Rspec for a year or so. I switched from Test::Unit specifically because I could print in a human readable way what is being tested.

It reads like prose. Which is big plus for me. But as with everything results will vary.

describe Model do
  it "should do what I want" do
    this.should == that
    it.should be_nil
    that.should_not be_true
  end
end 

Also reguardless of test framework you should also think about a coverage tool like RCov. It integrates with rspec and will tell you where your code lacks testing.

like image 68
John K Avatar answered Nov 16 '22 01:11

John K