Skip navigation links
JMockit Home

Package mockit

Provides the classes and annotations used when writing tests with the JMockit APIs.

See: Description

Package mockit Description

Provides the classes and annotations used when writing tests with the JMockit APIs.

The @Tested annotation allows for the instantiation of classes under test, with the injection and/or recursive instantiation of dependencies. It can inject mocked instances when used in combination with the @Injectable mocking annotation, and also inject non-mocked (real) instances when applied as @Tested(fullyInitialized = true). Non-mocked instances are either automatically created or obtained from other @Tested fields.

The Expectations class provides an API for the record-replay model of recording expected invocations which are later replayed and implicitly verified. This API makes use of the @Mocked, @Injectable, and @Capturing mocking annotations. The Verifications class extends the record-replay model to a record-replay-verify model, where expectations that were not recorded can be verified explicitly after exercising the code under test (ie, after the replay phase). The Invocation class and the Delegate interface are also part of this API; they can be used for recording expectations with custom results, and for the implementation of custom argument matchers.

MockUp<T> is a generic base class (where T is the type to be faked) which allows the definition of fake implementations for external classes or interfaces. Methods in a mock-up subclass that take the place of the "real" methods in class T are indicated with the @Mock annotation. Such methods can also (optionally) have an Invocation parameter.

Finally, the Deencapsulation class provides several Reflection-based utility methods, for the occasional cases where a private field needs to be accessed, etc.

For a description with examples of the Expectations API, see the "Mocking" chapter in the Tutorial. For the Mockups API, see the "Faking" chapter.

Skip navigation links
JMockit Home