Rails 3: Adding tests to production code
What's the best way to add tests to a code who h开发者_运维技巧as been in production for some time? I imagine that RSpec is not the best solution given that its goal is for TDD.
It's not ideal to write tests after the code has already been written. In fact it can be kind of hard if you do not write tests and code together since "non-tested" code is seldom well designed for testing.
However, writing tests to production code is better than not having tests at all. I recommend that you take the approach of adding tests to every method you want to change, every new method and every bug that is found in the code (before you start fixing it)... and build the test suite that way.
What library you use is less important. Use the one you like best. My personal preference is Test::Unit but RSpec and Shoulda are very popular too.
精彩评论