By default, you must specify a return value for all requirements; otherwise, a fatal error will be thrown. The reason for this is to aid in the discovery (and thus the verification) of every called function when writing unit tests.
However, it is common to prefer avoiding this strict default behavior in favor of a more relaxed setting, where,
for example, void or optional return values do not need explicit given registration.
Use the MockerPolicyoption set to implicitly mock:
only one kind of return value: .relaxedOptional
construct a custom set of policies: [.relaxedVoid, .relaxedOptional, .relaxedArray]
or opt for a fully relaxed mode: .relaxed.
You have two options to override the default strict behavior of the library:
At mock implementation level you can override the mocker policy for each individual mock implementation in the initializer:
let relaxedMock = MockService(policy: [.relaxedOptional, .relaxedVoid])
At project level you can set a custom default policy to use in every scenario by changing the default property of MockerPolicy:
MockerPolicy.default = .relaxedVoid
⚠️ Relaxed mode will not work with generic functions as the type system is unable to locate the appropriate generic overload.
Relaxed Mode
By default, you must specify a return value for all requirements; otherwise, a fatal error will be thrown. The reason for this is to aid in the discovery (and thus the verification) of every called function when writing unit tests.
However, it is common to prefer avoiding this strict default behavior in favor of a more relaxed setting, where, for example, void or optional return values do not need explicit
given
registration.Use the MockerPolicy option set to implicitly mock:
.relaxedOptional
[.relaxedVoid, .relaxedOptional, .relaxedArray]
.relaxed
.You have two options to override the default strict behavior of the library: