Post

Always test your code

Always test your code

I have been working with Rails for over a year now, but I still can’t write tests (or maybe I don’t want to). I think they are a hassle and slow you down, but actually it helps immensly.

A situation:

If there is a bug, you are not going to go into the console and create a model 100 times just so you can debug the issue. You are also not going to click the same button n number of times. It is easier to write a test that does it for you.

In the beginning, it takes a lot of time to write a test, because you don’t know what is going on (me included), so you believe it slows you down. Actually, in the end you will learn how to write tests faster and it will save you time further down the road. Tests also save you from headaches when bugs reach production.

Generally, if a bug makes it to production, we 100% need a test.

Conclusion

Ok, we have written the tests, but we should also always run them.

This post is licensed under CC BY-NC 4.0 by the author.