Recently I was facing the issue of reasoning with people when, what and why to test. For me the answer is relatively simple: myself, as a developer, it is my responsibility to be proud of my work and I should do everything in my power to prove it so. And of course, there are more practical things too, such as why do I even bother unit tests…
If I am thinking out loud, testing is a process that applies as much to hardware as to software.
“Testing is the name given to the process of discovering if something works and if so if it works well. Testing is used in computer hardware and software development to determine whether objectives are being met.”
Long story short for me testing is all about mentality and not about the fact of writing test cases. Whenever I am talking with a PO or any other stakeholder in any setup in any company, I would like to understand the requirements. The easiest way is to start working is to have an end goal, which is represented in a unit test, for every feature request I must ask: “how do I validate this”.
Having so many possibilities like unit, functional, integration, black box, white box, smoke, sanity, system, acceptance, QA testing, and domain-specific testing, not mentioning the non-functional part, it can be hard to choose the best practices. One spends more time refactoring code than writing it, and since a pillar of refactoring are tests, I would say no matter how good one is, tests will prove you are wrong (“No amount of experimentation can ever prove me right; a single experiment can prove me wrong” — Albert Einstein).
Since unit tests are a pillar to refactoring, this whole topic is extremely dear to my heart, every week I am doing one kata style refactoring in a random language (preferably OOP capable). Doing so I had to come up with a definition for a unit and going back and forth for a long time, I’ve stumbled upon the following fact: you have to be able to run the unit test disconnected from the world, perhaps thousands of meters high on Mount Everest or on an airplane going from Copenhagen to Amsterdam. And the unit itself is anything that exyou consider as a unit, literary it can be a single line of code, a class or a functionality, merge request, etc.
Having a healthy mentality towards testing is essential in building responsible software. One shall not reason if tests are necessary since that is one’s responsibility. The whole idea to have separate and dedicated time for writing tests should not exist since this must be an integral part of any developer’s blood. Tests help you to ask good questions and get clear(er) requirements.