Mock
public protocol Mock: class
Every generated mock implementation adopts Mock protocol. It defines base Mock structure and features.
-
Returns number of invocations of given method (with matching attributes).
Declaration
Swift
func matchingCalls(_ method: Verify) -> Int
Parameters
method
signature, with attributes (any or explicit value). Type
.
for all availableReturn Value
How many times, stub for given signature was called
-
Registers return value for stubbed method, for specified attributes set.
When this method will be called on mock, it will check for first matching given, with following rules:
- First check most specific givens (with explicit parameters - .value), then for wildcard parameters (.any)
- More recent givens have higher priority than older ones
- When two given’s have same level of explicity, like:
Given(mock, .do(with: .value(1), and: .any) Given(mock, .do(with: .any, and: .value(1))
Method stub will return most recent one.
Declaration
Swift
func given(_ method: Given)
Parameters
method
signature, with attributes (any or explicit value). Type
.
for all available -
Registers perform closure, which will be executed upon calling stubbed method, for specified attribtes.
When this method will be called on mock, it will check for first matching closure and execute it with parameters passed. Have in mind following rules:
- First check most specific performs (with explicit parameters - .value), then for wildcard parameters (.any)
- More recent performs have higher priority than older ones
- When two performs have same level of explicity, like:
Perform(mock, .do(with: .value(1), and: .any, perform: { ... })) Perform(mock, .do(with: .any, and: .value(1), perform: { ... }))
Method stub will return most recent one.
Declaration
Swift
func perform(_ method: Perform)
Parameters
method
signature, with attributes (any or explicit value). Type
.
for all available -
Verifies, that given method stub was called exact number of times.
Declaration
Swift
func verify(_ method: Verify, count: UInt, file: StaticString, line: UInt)
Parameters
method
Method signature with wrapped parameters (Parameter
) count
Number of invocations
file
for XCTest print purposes
line
for XCTest print purposes