Package mockit
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. Methods in a fake class 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.
For a description with examples of the Mocking API, see the "Mocking" chapter in the Tutorial. For the Faking API, see the "Faking" chapter.
-
ClassDescriptionIndicates a mock field or a mock parameter for which all classes extending/implementing the mocked type will also get mocked.Provides utility methods that enable access to ("de-encapsulate") otherwise non-accessible fields.Delegate<T>An empty interface to be used with the
Expectations.result
field or the Invocations#with(Delegate) method, allowing test code to define varying invocation results or argument matching rules, respectively.Used to record expectations on mocked types and their instances.Same asVerifications
, but checking that all invocations from code under test are explicitly verified, except for those already verified through other means.Indicates that the value of a mock field or mock parameter will be an isolated mocked instance, intended to be passed or injected into the code under test.A context object representing the current invocation to a mocked or faked method/constructor, to be passed as the first parameter of the corresponding delegate/fake method implementation.Used inside a fake class to indicate a fake method whose implementation will temporarily replace the implementation of one or more matching "real" methods or constructors (these are the "faked" methods/constructors).Indicates an instance field of a test class as being a mock field, or a parameter of a test method as a mock parameter; in either case, the declared type of the field/parameter is a mocked type, whose instances are mocked instances.MockUp<T>A base class used in the creation of a fake for an external type, which is usually a class from some library or component used from the internal codebase of the system under test (SUT).Indicates a class to be tested, with optional automatic instantiation and/or automatic injection of dependencies.Used to verify a set of expectations on available mocked types and/or instances, against the invocations which actually occurred during the test.Same asVerifications
, but checking that invocations from code under test occur in the same order as the verified expectations.