TDD – is an approach to software development, where tests are written before the code (describing what is needed), and only then the code is created in the way the tests would pass. The unit test cases effectively form the design of the code created.
This TDD process includes the following stages:
- Writing a test that fails because of code absence (red).
- Writing a code after which the test is passed (green).
- Refactoring – checking the code structure and its improvement without changing its external behavior. The expected result of refactoring is obtaining a perfectly written code.
- features available are limited by specific platform & payment plan
- speed & performance of tools might not be ideal, and/or not match highest expectations
- advanced features require paid subscription (payment plan)
Benefits of TDD:
- confidence (less defects): tests give confidence. Without the tests it is hard to tell whether system still functions correctly. As code base is continuously changing, and we need to make sure that other parts are still working, and the change did not break anything anywhere else (e.g. during merge conflicts, 3rd party packages updates, refactoring, breaking changes etc.).
- give structure to the design & development: tests make you think deep before function is implemented, instead of jumping into implementation head-first, without proper prior thought.
- clarity: tests clearly show which parts are working as expected, or which could be broken
- documentation: test names are self-explanatory documentation, describe the intended behavior referencing the initial requirements
- code review: good tests prove that code works as intended, without need to manually verify the functionality & its behavior
- code quality: tests help to follow best practices principles & code quality (SOLID, KISS, DRY).
There are some drawbacks though:
- Requires skill: A novice developer with little experience may be inclined to create a list of “happy path” tests, that would not account for many potential issues in the code.
- might slow down development to some extent: as this introduces some overhead in thinking over and writing actual tests that might not seem to make a difference for the end user.
- Harder to apply to existing projects: It is quite hard to transition from an older method, as you will need to change your processes, and maybe to re-skill your staff as well.
The benefits for the end user/client:
- high quality products (stable & reliable)
- higher end-user satisfaction (less frustration)
- time-efficiency (less time spent on bugs)
Note, that the benefits of the TDD can only be seen in the long run – as they are a supporting measure.