I am new to testing in Rails. I have decided to learn Test Driven Development and hence I'm researching on how to go about it in rails.
I started out with Test::Unit and soon came to know that better tools and testing frameworks available. Things I have heard of are
Now I am very confused as to how to go ahead. What is the best combination of these tools I need to learn? Also where can I find resources to learn these?
I am building the app in Rails 3.0
What is the best way to test a rails app?
Test first.
More seriously, you've listed a number of different tools which are designed to do different things.
Of those either Shoulda or Rspec might replace Test::Unit while the others all provide tools for different areas of testing. Which one you need depends on what you think will make writing tests easier and more effective.
For someone used to Test::Unit unit tests and interested in learning additional tools I would suggest the following.
If you have an existing project using Test::Unit consider adding Mocha's mocking and stubbing and see if that allows you to write focused unit tests more easily. If you already have fixtures in place consider using Factory Girl to generate factories instead as you add new model objects and again see if you find that makes your tests easier to manage and maintain. If you have a solid set of unit tests in place already consider using Cucumber to write some higher level functional tests to begin capturing user stories in tests and testing your app end to end.
If you are starting a new project then start with Rspec and Factory Girl. Rspec will introduce you to a very different style of testing than Test::Unit but you'll still be writing fairly familiar unit tests and it provides stubs, mocks, and matchers which will let you dive into testing without an explosion of too many new gems in your project. Factory Girl will give you a convenient way to build domain objects as your tests require them. Between those two you should be able to pick up a bunch of new testing tricks while still working with your usual unit testing workflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With