Using test helpers

Besides components, collaborators, data types, and test cases, we occasionally need another category of classes to write our tests efficiently. These utility classes provide any kind of testing related functionality that we want to reuse in several tests. This section explains some of the common practices.

Motivation

While writing tests, we'll inevitably find ourselves in a situation were we'll code the same routine for fixture setup, verification, or the like. If this happens to be in the same test case, we can extract a method for common usage. But sometimes, we could also make use of these methods in other test classes.

Java provides class inheritance, and so it's possible to introduce a common super type supplying these helping ...

Get Testing with JUnit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.