开发者

RoR: Tests for beginners

I have to preface all my posts about rails: I'm a novice.

Is it necessary to write tests for my app to 开发者_如何学编程work properly or is it strictly for finding breaks?


Testing your app is not necessary for it to work, but it is highly recommended and a very good practice. Testing your application will help you develop a better piece of software and a much more solid application. In the Rails world BDD(Behavior Driven Development) is very used as a testing and development technique.

I recommend you two diferent testing suites:

  • The first one is Rspec that will help you with all your controllers, and models unit testing
  • Cucumber is a testing suite that will test your application as a whole(integration test), this one is great for a more "real life" testing approach

I encourage you to check both Rspec and Cucumber, there are also other great testing suites like Test Unit.

Remember, testing your application will give you great benefits!

NOTE: Rspec and Cucumber are not mutually exclusive, actually they are recommended to use in conjunction


Writing tests is not necessary in the sense that your application won't operate without them, but they are not only for keeping bugs away. If you're a novice, writing the tests should also help you to understand how everything works.

There's no reason not to write tests. Just write good tests, and don't waste time testing things that don't need to be tested (like generated attr_accessors).


It's not necessary at all but its considered by almost every ruby developer I know to be standard procedure.

I did a couple "rails apps" without testing, but as soon as I needed some real backend logic in ruby, testing helped me to understand what I was doing.


No, writing tests is not required for your application to run. It is a good practice, though, so if you are not used to writing tests I'd recommend that you start learning. It's easy and it will save you a lot of headaches on whatever platform you are using.


Just to chime in with everyone else, I'd suggest you find yourself an article about BDD and test first development. And then read up on mocking and stubbing. Wrapping your head around the why and how of it will probably convince you it's worth the time and effort.

When I first dove into the XP & RoR world I live in now I was daunted by what felt to me like test-mania but it really pays off in spades.

The first time someone had me write the test first THEN write the code we were testing I was mind blown. But I've never gone back to my previous evil ways.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜