O'Reilly logo

Pragmatic Unit Testing in Java 8 with JUnit by Jeff Langr, Andy Hunt, Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test Smell: Missing Abstractions

A well-structured test distills the interaction with the system to three portions: arranging the data, acting on the system, and asserting on the results (see Keeping Tests Consistent with AAA). Although the test requires detailed code to accomplish each of these steps, we can improve understanding by organizing those details into abstractions—code elements that maximize the essential concepts and hide the unnecessary details.

images/aside-icons/tip.png

A good test is an abstraction of how clients interact with the system.

Our muddled test contains five lines that assert against the list of matches returned by search.getMatches() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required