views:

54

answers:

2

I wonder how TDD is done in Rails.

Here are the steps I have written down:

  1. Create migrations and models for the database tables
  2. Add associations to the models
  3. Write unit tests for the models and run and see them fail
  4. Add validations to the models
  5. Run tests and see them pass, if not, edit the code till they pass
  6. Create routing, controllers and views (that uses the models)
  7. Write functional tests
  8. Run tests and see them fail
  9. Edit code and see them pass
  10. 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 incorrect order.

Could you correct the above list if something isn't according to best practice.

Share your experience!

+1  A: 

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.

Nikita Rybak
So I should create tests before I create models and migrations? Wouldn't that be weird, cause I get all the models, tables and relationships between first when I have created them. Then I could write the tests. If I start with the tests I have no structure to follow.
never_had_a_name
A: 

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

soulman