Joshua Partogi
Joshua Partogi

Reputation: 16425

What test framework should I use to test my Rails model?

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.

Upvotes: 0

Views: 1111

Answers (3)

Daniel Kristensen
Daniel Kristensen

Reputation: 1364

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.

Upvotes: 0

Jim
Jim

Reputation: 5617

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.

Upvotes: 1

Jeremy Weiskotten
Jeremy Weiskotten

Reputation: 978

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_girl

Upvotes: 2

Related Questions