开发者

TDD in Ruby on Rails?

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 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜