Rspec vs. TestUnit
Asked Answered
G

6

42

I'm beginning the planning phase of creating a testing suite for my rails 3.0.8 application. I'm trying to decide on which testing framework/gems to use. Normally I prefer to stick to Rails convention as much as possible. However, this means using TestUnit. There are many competing test frameworks to choose from that were created as an alternative to TestUnit. Has TestUnit gotten better over the years, or is it not a very good contender?

I've also heard of a lot of good things about rspec. Are rspec and TestUnit close in terms of functionality, or does rspec blow TestUnit out of the water?

Whatever framework I choose, I'd prefer it to have a good support base(lots of users and documentation), ease of use/simplicity, and a lasting future.

Gerda answered 17/6, 2011 at 6:53 Comment(2)
As I said in this answer I would suggest you to read this book to learn how to test a Rails app and figure out which tools you want to useEnsphere
Near duplicates: RSpec vs Test::Unit in Rails on SoftwareEngineering.SE and RSpec vs. ShouldaBeeman
G
37

Both Test::Unit and Rspec are very nice solutions. As for me I prefer to use RSpec in my Rails project - because it has many automatic solutions like autotest, highlighting syntax, shortcut commands like rake spec and other stuff that make using test easer. But in my plain ruby scripts I use Test::Unit - it is very lightweight and staightforward when you don't need complex testing (integrational and others)

Gold answered 17/6, 2011 at 8:46 Comment(0)
A
14

The answer is matter of taste, use both in one project and find yourself what do you prefer. (I do Test::Unit, RSpec has to much sugar for me).

Update 2014: As Ruby 2.x has MiniTest built-in I would suggest to check MiniTest::Spec eventually which is simple BDD extension. You can mix "describe" and "it" blocks to nicely structure test contexts with. It also provides "must_be.." matchers if you want to more than assert.

Adaline answered 17/6, 2011 at 7:11 Comment(0)
J
8

I prefer and use these gems for testing

  • Rspec
  • Faker (for creating random and proper data for database)
  • Fabrication (for simple creating instances)

To start with rspec take a look at this presentation. It contains all the necessary examples:

http://kerryb.github.com/iprug-rspec-presentation

Also read through these articles on rspec:

http://relishapp.com/rspec/rspec-rails

Julieannjulien answered 17/6, 2011 at 13:8 Comment(0)
M
6

This Ruby Inside article, especially if you follow the links and read the comments, provides quite a thorough discussion of the relative merits of Test::Unit and RSpec. A key differentiator seems to be that:

  • people who have non-technical clients are more likely to view RSpec and Cucumber more favourably;
  • others are more likely to prefer more direct systems like Test::Unit.

Also see this part of Michael Hartl's Rails Tutorial for a comparison of RSpec and Cucumber.

Managerial answered 6/6, 2012 at 3:33 Comment(0)
R
4

You could use rspec with cucumber and webrat gems which makes a great combination, if you have a large website. It will be cumbersome at first but later on it will be a huge benefit.

You could watch the following railscasts episodes to have more info about those gems:
155 Beginning with Cucumber
156 Webrat
157 RSpec Matchers & Macros
159 More on Cucumber

There are also some other gems like capybara which is relatively new and promising, but honestly I didnt try it.

Rollerskate answered 17/6, 2011 at 9:14 Comment(0)
P
2

If you're beginning your journey with testing Rails application I would recommend you start doing it with TestUnit. You can find very nice course about best testing rails app and best practices on http://www.codeschool.com/courses/rails-testing-for-zombies If you're more experienced when it comes to testing you can try RSpec.

Pate answered 16/4, 2012 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.