20 Test-driven development with JUnit 5
This chapter covers:
- Moving a non-TDD application to TDD
- Refactoring a TDD application
- Using TDD to implement new functionality
TDD helps you to pay attention to the right issues at the right time so you can make your designs cleaner, you can refine your designs as you learn. TDD enables you to gain confidence in the code over time.
—Kent Beck
In this chapter, we will show how to develop safe, flexible applications using test-driven development (TDD): a technique that can greatly increase development speed and eliminate much of the debugging nightmare—all with the help of JUnit 5 and its features. We will point out the main concepts involved in TDD and apply them in developing a Java application that Tested Data Systems (our example company) will use to implement the business logic for managing flights and passengers and following a set of policies. Our focus will be on clearly explaining TDD and proving its benefits by demonstrating how to put it in practice, step by step.
20.1 TDD main concepts
Test-driven development is a programming practice that uses a short, repeating development cycle in which requirements are converted into test cases, and then the program is modified to make the tests pass:
- Write a failing test before writing new code.
- Write the smallest piece of code that will make the new test pass.