mockito library

Classes

Fake
A stand-in for another object which cannot be used except for specifically overridden methods.
MissingDummyValueError
Mock
Extend or mixin this class to mark the implementation as a Mock.
PostExpectation<T>
SmartFake
A slightly smarter fake to be used for return value on missing stubs. Shows a more descriptive error message to the user that mentions not only a place where a fake was used but also why it was created (i.e. which stub needs to be added).
VerificationResult
Information about a stub call verification.

Properties

any → Null
An argument matcher that matches any argument passed in this argument position.
no setter
captureAny → Null
An argument matcher that matches any argument passed in this argument position, and captures the argument for later access with VerificationResult.captured.
no setter
untilCalled → InvocationLoader
Returns a future Invocation that will complete upon the first occurrence of the given invocation.
no setter
verify → Verification
Verify that a method on a mock object was called with the given arguments.
no setter
verifyInOrder → List<VerificationResult> Function<T>(List<T> recordedInvocations)
Verifies that a list of methods on a mock object have been called with the given arguments. For example:
no setter
verifyNever → Verification
Verify that a method on a mock object was never called with the given arguments.
no setter
when → Expectation
Create a stub method response.
no setter

Functions

anyNamed(String named) → Null
An argument matcher that matches any named argument passed in for the parameter named named.
argThat(Matcher matcher, {String? named}) → Null
An argument matcher that matches an argument (named or positional) that matches matcher. When capturing a named argument, the name of the argument must be passed via named.
captureAnyNamed(String named) → Null
An argument matcher that matches any named argument passed in for the parameter named named, and captures the argument for later access with VerificationResult.captured.
captureThat(Matcher matcher, {String? named}) → Null
An argument matcher that matches an argument (named or positional) that matches matcher, and captures the argument for later access with VerificationResult.captured. When capturing a named argument, the name of the argument must be passed via named.
clearInteractions(Object? mock) → void
Clear the collected interactions with mock.
logInvocations(List<Mock> mocks) → void
Print all collected invocations of any mock methods of mocks.
named<T extends Mock>(T mock, {String? name, int? hashCode}) → T
provideDummy<T>(T dummy) → void
Provide a dummy value for T to be used both while adding expectations and as a default value for unstubbed methods, if using a nice mock.
provideDummyBuilder<T>(DummyBuilder<T> dummyBuilder) → void
Provide a builder for that could create a dummy value of type T. This could be useful for nice mocks, such that information about the specific invocation that caused the creation of a dummy value could be preserved.
reset(Object? mock) → void
Clear stubs of, and collected interactions with mock.
resetMockitoState() → void
Reset the state of Mockito, typically for use between tests.
throwOnMissingStub(Mock mock, {void exceptionBuilder(Invocation)?}) → void
Opt-into Mock throwing NoSuchMethodError for unimplemented methods.
verifyNoMoreInteractions(Object? mock) → void
verifyZeroInteractions(Object? mock) → void

Typedefs

Answering<T> = T Function(Invocation realInvocation)
Expectation = PostExpectation<T> Function<T>(T x)
Verification = VerificationResult Function<T>(T matchingInvocations)

Exceptions / Errors

FakeFunctionUsedError
FakeUsedError
MissingStubError
An error which is thrown when no stub is found which matches the arguments of a real method call on a mock object.