Skip to Content
Growing Object-Oriented Software, Guided by Tests
book

Growing Object-Oriented Software, Guided by Tests

by Steve Freeman, Nat Pryce
October 2009
Intermediate to advanced
384 pages
8h 54m
English
Addison-Wesley Professional
Content preview from Growing Object-Oriented Software, Guided by Tests

Appendix B. Writing a Hamcrest Matcher

Introduction

Although Hamcrest 1.2 comes with a large library of matchers, sometimes these do not let you specify an assertion or expectation accurately enough to convey what you mean or to keep your tests flexible. In such cases, you can easily define a new matcher that seamlessly extends the JUnit and jMock APIs.

A matcher is an object that implements the org.hamcrest.Matcher interface:

image

A matcher does two things:

• Reports whether a parameter value meets the constraint (the matches() method);

• Generates a readable description to be included in test failure messages (the describeTo() method inherited ...

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.
Start your free trial

You might also like

Test Driven Development: By Example

Test Driven Development: By Example

Kent Beck
Coding with AI: The End of Software Development as We Know It

Coding with AI: The End of Software Development as We Know It

Tim O'Reilly, Addy Osmani, Gergely Orosz, Kent Beck, Camille Fournier, Avi Flombaum, Maxi Ferreira, Harper Reed, Jay Parikh, Birgitta Böckeler, Angie Jones, Craig McLuckie, Patty O’Callaghan, Chip Huyen, swyx, Andrew Stellman, Phillip Carter, Nikola Balic, Brett Smith, Chelsea Troy, Lili Jiang

Publisher Resources

ISBN: 9780321574442Purchase book