Starting Simple
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.
Your first step is to write a test that defines the behavior you want to build into the system. In general, you seek to write the test that represents the smallest possible—but useful—increment to the code that already exists.
For our exercise, we’re rebuilding the Profile class. We think about the simplest cases that can occur and decide to write a test that demonstrates what happens when the profile is empty (when no answers have been added to it).
(If you have a Profile class, start this exercise by deleting it and any tests for it. Or start fresh in a new package or project.)
We’ll write our ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access