You are previewing Growing Object-Oriented Software, Guided by Tests.

Growing Object-Oriented Software, Guided by Tests

Cover of Growing Object-Oriented Software, Guided by Tests by Steve Freeman... Published by Addison-Wesley Professional
O'Reilly logo

Appendix A. jMock2 Cheat Sheet

Introduction

We use jMock2 as our mock object framework throughout this book. This chapter summarizes its features and shows some examples of how to use them. We’re using JUnit 4.6 (we assume you’re familiar with it); jMock also supports JUnit3. Full documentation is available at www.jmock.org.

We’ll show the structure of a jMock unit test and describe what its features do. Here’s a whole example:

image

Test Fixture Class

First, we set up the test fixture class by creating its Mockery.

image

For the object under test, a

The best content for your career. Discover unlimited learning on demand for around $1/day.