🤖🚫 AI-free content. This post is 100% written by a human, as is everything on my blog. Enjoy!

Improve your code with unit tests

October 16, 2013 in Engineering philosophy

As a way of ensuring buglessness, tests fail miserably.

However, as I realise, writing unit tests has more collateral benefit than direct.

Complicated unit tests indicate complicated code. Instead of spending time on elaborate tests to fit the code, the programmer should refactor the code to be easier to test.

In particular, this means decoupling business logic from user interface or persistence (activerecord cough cough).

You can counter that there’s never time to refactor, but this is the greatest incentive to write tests along the code, instead of “after the code settles down”. And with practice you’ll write better code from the start.

I think tests should not be considered a means of preventing bugs, but of improving application code. Thus, their job cannot be done by a QA engineer and is the sole responsibility of the code’s author.

P.S.: automated acceptance tests without a team of dedicated maintainers? Still a pipe dream.

Buy me a coffee Liked the post? Treat me to a coffee