Ruby on Rails testing

Rails / Testing – 4 reasons why you should not write code without tests

Rails / Testing – 4 reasons why you should not write code without tests January 6, 2018Leave a comment
Reasons for doing code tests

When I was starting my programming journey I didn’t care about tests. I had no time for this, I didn’t understand why I should do this. When someone said that I should spend the same amount of time on writing classes and tests, my mind blows. I launched my first startup without tests – yes it was a maintenance nightmare.

Reasons for doing code tests

A few months later I started to learn how to write tests. Now, after many years, I don’t understand how code without tests can even exist. If you need a clue why you should write tests then check reasons presented below.

1. It’s easy to refactor code, modify and add new code

It’s the most obvious reason. Instead of clicking on the whole app or praying that you didn’t break anything with your changes you can simply run tests. Of course, the fact that you have tests does not mean that they are good enough to catch errors. So care about unit tests at least, create acceptance tests if you have time and hands to work on it. However, having full, well written, tests suite reduces the possibility of errors on both backend and frontend side.

2. Tests are kind of documentation

If you ever run rspec with --documentation flag then you probably know about it. There is always not enough time to write documentation but with well-written tests and proper wording, you can automatically create documentation while creating tests.

3. Others can understand

New team members or junior developers would appreciate this. You can have comments on your code but proper tests are the best explanation for your classes and modules.

4. Verify if application meets client and users expectations

In a perfect world client writes testing scenarios but in a real world, you have to do this by yourself. The easiest way is to implement three steps cycle: red, green and refactor. First set expectations and then take care of writing code that would handle them.

I hope now you have fewer doubts about writing tests after reading my reasons for doing code tests. Let me know about other reasons if I missed any.

Having problems with tests for your Ruby on Rails app?

Hit me on twitter or use contact form and let me know how can I help you!

Image source: pexels.com

Download free RSpec & TDD ebook

Do you want to earn more or jump to the next level in your company? Do you know that testing skills are one of the most desired skills? There is only first step: start testing and do it right. My ebook can help you. Subscribe to the newsletter to get a free copy of the book.

Leave a Reply

Your email address will not be published. Required fields are marked *