Search⌘ K
AI Features

Tests As Documentation

Explore how to craft meaningful test names and organize tests in JUnit to document class behavior clearly. Understand the value of test structure and the rhythm of Test-Driven Development cycles to improve code quality and maintainability.

We'll cover the following...

As the final task, let’s revisit the set of test names in ProfileTest:

Test names in ProfileTest

matchesWhenProfileContainsMatchingAnswer

doesNotMatchWhenNoMatchingAnswer

matchesWhenContainsMultipleAnswers

doesNotMatchWhenNoneOfMultipleCriteriaMatch

matchesWhenAnyOfMultipleCriteriaMatch

doesNotMatchWhenAnyMustMeetCriteriaNotMet

matchesWhenCriterionIsDontCare

scoreIsZeroWhenThereAreNoMatches

We want readers to be able to quickly answer questions about the behavior of the Profile class. The more we craft the tests with care, the more the tests can document the behaviors deliberately designed into Profile.

Better test names

When seeking to better understand a test-driven class, start by reading its test names. The comprehensive set of test names should provide a holistic summary of the intended capabilities of the class. The more the test names are clear and consistent with one another, the better they act as the most trustworthy form of ...