views:

382

answers:

3

With the many testing framework that is available in the Ruby community namely: unittest, rspec, shoulda, and coulda, what would be the most appropriate testing framework to test my Rails model?

Do they basically have the same functionality, which is to unittest my model? When should I use which? What is the advantage of using one and not the other? Please help me decide.

Thank you very much for your insights.

+2  A: 

The differences mostly come down to personal taste. I recommend starting out with Test::Unit. There's plenty of documentation, and it's the default for Rails. If you want to add Shoulda to the mix later, you can do that very easily.

I also recommend using Factory Girl instead of fixtures. http://github.com/thoughtbot/factory%5Fgirl

Jeremy Weiskotten
+1  A: 

Lots of people seem to love rspec. I had a hard time finding recent (and free) resources (tutorials) online on it. There are supposed to be good screencasts, but there's fee to access them. There are free screencasts, but they're very basic. There's a book coming out, but it's been probably a year since it's announced and due out this December. The beta pdf version is ~$50 if you want it early.

I suggest Test::Unit since you don't know it yet. Good to know since you might read someone else's code and need to know about it.

Jim
So Test::Unit is not out of date heh? :-) Ok I will try it out.
jpartogi
I admit bias in my answer. I'm cheap and haven't had much time/patience to investigate rspec as others have. I WILL look at the rspec book when it comes out.
Jim
A: 

I too would suggest starting with Test::Unit just to get a feel for it. Then take a look a look at some of the other frameworks and see what you like best. Shoulda is probably one of the easier ones to get started with coming from plain Test::Unit so it might be an ideal place to look next. On the other hand if you really like the syntax of RSpec you should definitely go with that.

Wars get waged over this topic, but the thing is it doesn't really matter what you use, as long as your doing some form of testing. Also there is nothing wrong with just sticking with Test::Unit if that suits you :)

Personally I'm a fan of the Shoulda + Factory Girl combo.

Daniel Kristensen
Can you please explain why you prefer shoulda over RSpec? I'm interested to know about your decision choosing shoulda. Many thanks.
jpartogi
Sure :) but there not much to say really. It is just a matter of personal taste from my side. I tried them both and I just like Shoulda's syntax better.
Daniel Kristensen
Okay. You're right. Somehow shoulda is easier to setup and easier to read.
jpartogi