开发者

Cucumber/Rspec: Is there a way to extract tests from existing code?

I'm going to begin learning cucumber/rspec.

I've few application in rails3/mysql and rails3/mongoid which I wrote without any test :-(

Should be wonder if I could have a "cucumber/rspec" generator which could extract scenario and "step definition" for cucumber, just like behaviors for rspec. A kind of reverse engineering code generator, which extract tests from existing controllers/models/views.

D开发者_如何学JAVAo you suggest any other approach for having old buggy code alligned to the future well practice testing ?

I know this completely broke the vantage of outside/in BDD development but, how to sanitize thousand of lines of old code ?

Thanks in advance Luca G. Soave


If tests could be auto-generated, we wouldn't need them in the first place, would we?

Here's how to deal with untested legacy application when your time is limited:

  • Write Cucumber scenarios for the 3 most important stories in your application. E.g. if you're application is a shopping system this would be: browse articles, add item to cart, checkout.
  • When you're adding new features, do it test-driven.
  • When you're changing untested code, add a test for the code you're touching.
  • When you're fixing a bug, add a test for the code you're fixing.

After a while you will have nice enough test coverage for your application.

Good luck.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜