The main barrier to implementing unit testing on a project is that, at the very beginning, a programmer spends a lot of time writing tests, and sometimes, it takes time to understand how to test a particular functionality. You can only develop your skills in writing unit tests by writing tests and practicing TDD. Without testing skills, you don’t practice TDD in real life, preventing you from improving your skills to the ideal level. This creates a closed circle. So how do you break it? It is straightforward – start practicing TDD and writing tests. It will be hard at first, but over time, you will understand how to test a specific functionality and start thinking a little differently. Your neural system will train and allow you to find solutions to programming problems from a completely different perspective.
Periodic training in code writing for programmers is called kata. This name was borrowed from karate terminology. In martial arts, a kata is a formalized sequence of movements repeated repeatedly for many days in a row. These movements contain the very essence of the technique of a particular martial art style. In essence, kata is training to fight an imaginary opponent. By repeating the movements many thousands of times, they gradually become subconscious. It’s the same way we learn to ride a bike or drive a car. At first, we carefully control each movement, but then we perform them automatically. Similarly, we will embed TDD software development techniques in our subconscious by performing various code katas. Roughly speaking, we will train our neural network (brain).
To make the process of going through the katas enjoyable, they should be:
- not complicated – you should not spend a lot of “mental” energy on their passage
- short – the time to complete the code should not be long
- focus on the process rather than the result of work – the code written during the execution of the torture will not go to any project, so you are free to do any experiments
Remember, the key to mastering TDD and code katas is consistent practice and self-improvement. It’s not about achieving perfection overnight but about making continuous progress. So, keep training and working on yourself, and the rest will follow.
Enough talk, let’s get our hands dirty. What do we need to start practicing? Let’s dive in and find out.
- the installed php interpreter for our operating system – https://www.php.net/manual/en/install.php
- composer package manager – https://getcomposer.org/download/
- desire to practice in code coding
- an initial template project with the PHPUnit testing framework installed