views:

922

answers:

3

I am learning Rails the age old way. By reading Agile Web Development with Rails (3rd Edition) as a starting point. I am currently in the chapter that teaches Testing. I am also aware of other BDD Testing framework such as RSPec. So I was wondering if frameworks such as RSpec, Cucumber, Shoulda replace the need for knowing/using Test::Unit? Are they both relevant in their own right and used for different purposes?

UPDATE: Since I am new to Testing, I would also love to get feedback on what resources are useful to get my feet wet with different frameworks.

Thanks!

+13  A: 

I think Test::Unit is still relevant even though there is a lot of hype surrounding BDD and other testing tools.

That being said, if you are up for it, you could bypass learning Test::Unit and start with something like RSpec and Shoulda right away, but there is something to be said about following through the examples in the Agile Web Development Book to see where the ideas from BDD came from.

I find myself still using Test::Unit for some projects since it comes with Rails and is still a very great testing framework.

So long story short, I don't think it's obsolete but it's not the cutting edge any more. BDD is a testing paradigm shift especially if you start using Cucumber and Webrat, but it's fantastic once you get into it. Shoulda is the easiest to make the transition to, so I would start with Test::Unit, then move to Shoulda, then Give RSpec and Cucumber a try.

You are testing or at least interested in testing! That's the best part. In the end it doesn't matter what you use as long as you are happy with it.

Good luck!

ewakened
Thanks! I think testing is great. It's not that I do not like Test::Unit but it seems that as I am learning it, I can already see how much recoding tests would need with minor changes in code. I can envision having to constantly write fixtures with changes in the model.
tundal45
Try out Factory_Girl from Thoughtbot. It's the best way to manage Fixtures when testing.
ewakened
Even better than Factory Girl is Machinist. http://github.com/notahat/machinist/tree/master
RJHunter
A: 

There are a lot of people who still like Test::Unit, and to some extent, it's a personal preference. However, on balance, you will find far more activity on the RSpec front. The really cool stuff is all being done with RSpec and Cucumber, so if you don't have a personal preference yourself, I'd probably skip Test::Unit. You should, however, be familiar enough with it to read someone else's tests that are written with it, but I wouldn't foresee that ever being a problem.

Bob Aman
A: 

Rspec is an entirely separate testing framework. Shoulda is an enhancement to Rails's built-in framework, Test::Unit. If you're using Shoulda, you're using Test::Unit but with more capabilities and simpler, more readable syntax.

I've tried Rspec and Shoulda and for me, Shoulda wins hands down. I like it way better. But that may be a matter of taste.

Note that you can use Cucumber with Shoulda.

Other resources? I recommend the ZenTest and RedGreen gems. ZenTest provides autotest, which lets you run your tests automatically every time you change a file. It's a big help.

Regarding fixtures vs. factories, if you need to set up a bunch of interrelated objects where you're testing both sides or a parent-child relationship and/or testing many-to-many relationships, fixtures work a lot better. Actually I'm not even sure you can do that with factories. So don't dismiss fixtures -- they have their uses.

Ethan
I disagree, it is easy with Factories and it is so much easier to maintain, fixing fixtures is a nightmare, whereas with your factory you can fix it once and move on.
railsninja