Sample tests for the JMockit Testing Toolkit
The available sample test suites can all be found under the "samples" folder in the full distribution zip file.
The Ant "build.xml" file contains a target "sampleTests" which will run all sample tests and produce a JUnit test
report in HTML, as well as a code coverage HTML report (produced with the JMockit Coverage tool).
In total, there are more than 500 sample tests, all using JUnit (except for a few that use TestNG) and most also
using JMockit; the ones that don't use JMockit are "pure" unit tests which use no mocks at all, or tests using other
mocking toolkits for comparison purposes.
The example tests used in the JMockit Tutorial introductory chapter can be
found on-line
here.
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:
-
EasyMock comparison sample <==>
JMockit version.
(Additional example test sources can be found in the EasyMock 3.1 distribution zip file.)
-
jMock comparison samples, with the originals found
here and (partially)
here <==>
JMockit version
-
PowerMock comparison samples, with the originals found
here <==>
JMockit version
-
Mockito comparison samples, with the originals found
here
and elsewhere in the Mockito source code repository <==>
JMockit version
-
Unitils Mock comparison samples, with the originals found
here <==>
JMockit version
-
JBoss AOP testing
<==>
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, are both from
the same author, and 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 for the relevant production code:
-
A complete suite with 150+ 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.
==> browse them
here.
-
Full suite of tests for another class library of the same author as the Timing Framework:
Animated Transitions.
==> browse them
here.
Miscellaneous test suites
Other sample suites:
-
A set of tests for a fictitious web application, including integration tests which use the
Hibernate 3 Emulation tool: browse the source code
here.
-
A small TestNG test suite for a single class (
LoginService), based on
this article.
==> JMockit version
-
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
this article.
Complete source code can be browsed
here.
-
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 this article,
and can be browsed online
here.