Test-Driven Development: Why and How?
August 28, 2017 - Software Development
Software development using the agile philosophy has become a popular choice for organizations both large and small. Agile’s iterative, incremental, flexible, lightweight and collaborative approach represents a significant departure from traditional development practices yet has proven to be very effective for many development teams.
One of the ideas that has grown out of agile – and the extreme programming methodology in particular – is the concept of test-driven development. Here’s a look at what test-driven development means and represents and how it’s implemented today in organizations like your own.
As the name suggests, test-driven development (TDD) refers to a style of software development in which unit tests are written one-by-one before the code is. The software is then developed just enough to pass this latest test in the sequence. Once the software passes this test case, developers formulate a new test and the coding-testing cycle continues.
Programmers who use TDD often praise it for its ability to detect bugs quickly and to provide insight into the current state and behavior of the program. TDD treats a code base as a set of small, modular, composable units. This means that refactoring a program or adding new features is much easier because the tests will instantly detect any bugs that were introduced during the changes.
However, TDD is time-consuming and only worthwhile if the unit tests are used extensively throughout development. In addition, TDD alone is insufficient for situations where you functional testing is required in order to assess the application’s performance in production.
Just as agile gave birth to TDD, in turn TDD served as the foundation for the idea of behavior-driven development (BDD). In BDD, developers and other stakeholders describe how an application is intended to behave in production and then develop the software with these expectations in mind. These expected behaviors are then converted into validation tests to ensure that the software is performing in accordance with specifications.
Like TDD, BDD emphasizes a progressive, incremental approach to development. Rather than passing “one more test,” however, developers’ task is to build “one more feature.” In BDD, developers’ top priority is always to implement the most important thing that the software doesn’t already do in its current state.
In modern software development companies, TDD is typically implemented using an automated unit test frameworks which are easily integrated into popular IDEs.
Modern TDD also benefits from a variety of tools and techniques in order to make development easier and maintain the integrity of the project. For example, code coverage tools such as JaCoCo, Atlassian Clover and Cobertura are used to make sure that the automated unit test suite properly tests the entire code base. Tools for continuous integration, such as Jenkins and Bamboo, are a necessity in order for developers to verify that their code is up to date and defect free.
Test-driven development is a marked departure from the traditional waterfall model of software development, in which all testing occurs only after development has completed. When used by the right team, however, TDD is not only a viable alternative but can return massive benefits in terms of speed, efficiency and productivity.