Quite some time ago, I came across a thread on a Ruby on Rails forum. It was a junior developer asking for general advice on app testing. So I asked m

5 Rules of Writing Tests

submited by
Style Pass
2024-11-08 05:00:06

Quite some time ago, I came across a thread on a Ruby on Rails forum. It was a junior developer asking for general advice on app testing. So I asked myself: what would I want to know about writing tests if I was a novice? Here I made a list of 5 rules on application testing I think all developers should be using.

There are two possible tactics when it comes to writing tests. You may start with tests before writing code to avoid copy-pasting in the console, or write proof of concept first and then test it through. What’s more important is to run them on things that you suspect to break or change in the future, because tests are written for confidence that your application is working and for making future refactoring easier. Refactoring is crucial because you should be aware that apps won’t stay in their initial state forever. Your skills improve, tools change, design patterns evolve and tests allow you to adapt code faster.

Test things mostly end-to-end (aka integration tests) in a happy path, but for tricky mechanics add unit tests for every edge case. For end-to-end testing, it doesn’t matter what tool you will use, whether Capybara, VCR cassettes with recorded requests or actual requests to a database. What is important is to test on real data examples and the code that does something.

Leave a Comment