Poorly documented code is a common problem in software development and the limitations of manual testing can lead to critical bugs being released into production. Luckily, test-driven development offers a solution.
Test-driven development (TDD) is an approach where the development team writes exhaustive tests first, and then creates code designed to successfully fulfil those tests. This process results in the tests becoming part of the project documentation and “clean code that works”.
How TDD works
In this example, Mike is backend developer and his current task is to develop the automatic seating of the conference guests based on their interests. To solve the task he first prepares a test to check the suitability of the seating that the system provided:
public function testGetRelationTableName()
$result = TableRelationManager::getRelationTableName(‘TableOne’, ‘TableTwo’);
Mike then develops a solution that designed to pass this test:
public static function getRelationTableName($table1, $table2)
$tables = [$table1, $table2];
return implode(”, $tables) . ‘Rel’;
As a result, the feature he prepared is fully tested, and the code is clean and works as intended.
If you plan to use TDD on a new project, then the first exercise is to train your staff.
We have found that adapting a team of five people usually takes 2-4 weeks, during which time the team’s productivity can be 30-40% below optimal, so it is important to be prepared.
Once a team is up-to-speed, the implementation of TDD in an ongoing project may last six months or more depending on factors such as code quality, documentation quality, test coverage, and project complexity. For example, we implemented TDD for eight months as part of a recent 10-person aerospace project.
Where is it suitable?
- TDD can be very beneficial to some software development projects, but it is not applicable in all cases.
TDD is the most suitable for:
- Projects started from scratch.
- Tasks that easily can be decomposed.
- Backend tasks – implementation of logic etc.
TDD is less suitable for:
- Ongoing and legacy projects.
- Tasks with uncertain results.
- Tasks that cannot be easily and fully checked with automated tests.
- Complex tasks that are difficult to decompose.
- Tasks that are dedicated to interactions with users, databases or external services.
TDD is a powerful and efficient approach to develop cleaner code and higher quality software. If you are looking for more specific help related to the implementation or application of TDD, please contact our expert: