TDD in Ruby on Rails?
I wonder how TDD is done in Rails.
Here are the steps I have written down:
- Create migrations and models for the database tables
- Add associations to the models
- Write unit tests for the models and run and see them fail
- Add validations to the models
- Run tests and see them pass, if not, edit the code till they pass
- Create routing, controllers and views (that uses the models)
- Write functional tests
- Run tests and see them fail
- Edit code and see them pass
- Write integration tests
I have never done TDD before.
This is what I had in mind, but I wanted to check with you guys first.
Im sure this isn't very "correct" and that I have missed something and have things in incorr开发者_开发问答ect order.
Could you correct the above list if something isn't according to best practice.
Share your experience!
If think there's some misunderstanding (or do I misunderstand it?). TDD doesn't mean "first write all the code, then write all the tests". Just like your application grows, piece by piece, tests grow with it.
This might be a good place to get some practical examples:
http://andrzejonsoftware.blogspot.com/2007/05/15-tdd-steps-to-create-rails.html
on comment
So I should create tests before I create models and migrations?
See the definition: http://en.wikipedia.org/wiki/Test-driven_development
Test-driven development (TDD) is a software development technique that relies on the repetition of a very short development cycle: first the developer writes a failing automated test case that defines a desired improvement or new function, then produces code to pass that test and finally refactors the new code to acceptable standards.
Although, personally I think there's nothing wrong with creating application carcass before first tests. The more important thing is a very short development cycle. You don't code whole day and spend next day testing it. You do both in parallel.
I am learning Rails myself and trying hard to grasp TDD too. I have found this screencast on the topic which I am thinking about buying: https://peepcode.com/products/test-first-development
精彩评论