Mocker

A class through which one creates mock objects and manages expectations about calls to their methods.

Members

Functions

allowDefaults
void allowDefaults()

Do not require explicit return values for expectations. If no return value is set, return the default value (null / 0 / nan, in most cases). By default, if no return value, exception, delegate, or passthrough option is set, an exception will be thrown.

allowUnexpectedCalls
void allowUnexpectedCalls(bool allow)

Disables exceptions thrown on unexpected calls while in Replay phase Unexpected methods called will return default value of their type

allowing
ExpectationSetup allowing(T ignored)
ExpectationSetup allowing()

Set up a result for a method, but without any backend accounting for it. Things where you want to allow this method to be called, but you aren't currently testing for it.

expect
ExpectationSetup expect(lazy T methodCall)

Record new expectation that will exactly match method called in methodCall argument

lastCall
ExpectationSetup lastCall()

Returns ExpectationSetup object for most recent call on a method of a mock object.

mock
T mock(CONSTRUCTOR_ARGS args)

Creates a mock object for a given type.

mockFinal
MockedFinal!T mockFinal(CONSTRUCTOR_ARGS args)

Creates a mock object for a given type.

mockFinalPassTo
MockedFinal!T mockFinalPassTo(T to)

Creates a mock object for a given type.

mockStruct
MockedStruct!T mockStruct(CONSTRUCTOR_ARGS args)

Creates a mock object for a given type.

mockStructPassTo
MockedStruct!T mockStructPassTo(T to)

Creates a mock object for a given type.

ordered
void ordered()

By default, all expectations are unordered. If I want to require that one call happen immediately after another, I call Mocker.ordered, make those expectations, and call Mocker.unordered to avoid requiring a particular order afterward.

record
void record()

Start setting up expectations. Method calls on mock object will create (and record) new expectations. You can just call methods directly or use Mocker.expect/lastCall to customize expectations.

replay
void replay()

Stop setting up expectations. Any method calls after this point will be matched against the expectations set up before calling replay and expectations' actions will be executed.

verify
void verify(bool checkUnmatchedExpectations = true, bool checkUnexpectedCalls = true)

Verifies that certain expectation requirements were satisfied during replay phase.

Meta