Hamcrest

As described in Chapter 2, Tools, Frameworks, and Environment, Hamcrest improves our test's readability. It makes assertions more semantic and comprehensive when complexity is reduced by using matchers. When a test fails, the error shown becomes more expressive by interpreting the matchers used in the assertion. A message could also be added by the developer.

The Hamcrest library is full of different matchers for different object types and collections. Let's start coding and get a taste of it.

Get Test-Driven Java Development - Second Edition 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.