JMockit The Mock Anything Toolkit for Java

Sample tests

The available sample test suites can be found under the "samples" folder in the full distribution zip file. Each test suite is in a separate Maven module, with its own pom.xml file.

In total, there are about 500 sample tests, all using JUnit (except for a few that use TestNG) and most using the JMockit APIs; the ones that don't use JMockit are "pure" unit tests with no mocking at all, or tests using other mocking toolkits for comparison purposes.

The example tests used in the JMockit Tutorial introductory chapter are available online.

Test suites for comparison with other mocking APIs

The following test suites are intended to compare published sample tests for other tools with the equivalent JMockit version:

  1. EasyMock samples <==> JMockit version
  2. jMock samples <==> JMockit version
  3. PowerMock samples <==> JMockit version
  4. Mockito samples <==> JMockit version
  5. Unitils Mock samples <==> JMockit version

Test suites for third-party class libraries

There are two complete JUnit test suites for third-party frameworks. The frameworks, described in the Filthy Rich Clients book, were originally created without any developer tests at all (but great pieces of work nevertheless). These test suites aim to achieve 100% line and branch coverage of the library code:

  1. A complete suite with 160 tests for the Timing Framework. Demonstrates just about every feature of the two main JMockit mocking APIs (JMockit Mockups and JMockit Expectations & Verifications) by providing full coverage for a real-world, professional quality, and well documented Java framework targeted at rich Swing applications.
  2. Full suite of tests for another class library of the same author as the Timing Framework: Animated Transitions.

Miscellaneous test suites

Other sample suites:

  1. A set of tests for a fictitious Order Management web application.
  2. A small TestNG test suite for a single class (LoginService), based on the Login Service Example article series.
  3. A couple of JUnit tests for a servlet class, with versions using EasyMock, jMock, Mockito, Unitils Mock, JMockit, and Spring Test. These tests are based on the Tour de Mock article series.
  4. A sample with two separate test suites, one containing unit tests using the JMockit Expectations & Verifications API, and another containing only integration tests. The second suite can optionally be executed with fake implementations, written with the JMockit Mockups API, for the classes used when accessing a Web site. The code is based on the Modern Mocking Tools and Black Magic article.