TDD Cycle
Explore the three-step Test-Driven Development (TDD) cycle to write effective unit tests in Java. Learn to write failing tests first, then make them pass with incremental code, followed by refactoring. This lesson teaches applying TDD through rebuilding a Profile class demonstrating the principles of small, incremental testing and code improvement.
We'll cover the following...
TDD cycle
TDD is a three-part cycle:
- Write a test that fails.
- Get the test to pass.
- Clean up any code added or changed in the prior two steps.
Our first step is to write a test that defines the behavior we want to build into the system. In general, we seek to write the test that represents the smallest possible useful increment to the code that already exists.
Rebuilding the Profile class
For our exercise, we will rebuild the Profile class. Let’s think about the simplest cases that can occur and write a test that demonstrates what happens when the profile is empty ...