Global methods
-
Setup return value for method stubs in mock instance. 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 the one depending on mock sequencingPolicy. By default it means most recent one.
Declaration
Swift
public func Given<T>(_ object: T, _ method: T.Given, _ policy: StubbingPolicy = .default) where T : MockParameters
objectMock instance
methodMethod signature with wrapped parameters (Parameter
) and return value policyStubbing policy - uses mock policy by default (which defaults to .wrap)
-
Setup return value for static method stubs on mock type. When this static method will be called, 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(T.self, .do(with: .value(1), and: .any) Given(T.self, .do(with: .any, and: .value(1))Method stub will return the one depending on mock sequencingPolicy. By default it means most recent one.
Declaration
Swift
public func Given<T>(_ type: T.Type, _ method: T.StaticGiven, _ policy: StubbingPolicy = .default) where T : StaticMockParameters
objectMock type
methodStatic method signature with wrapped parameters (Parameter
) and return value policyStubbing policy - uses mock policy by default (which defaults to .wrap)
-
Setup perform closure for method stubs in mock instance. 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 the one depending on mock sequencingPolicy. By default it means most recent one.
Declaration
Swift
public func Perform<T>(_ object: T, _ method: T.Perform) where T : MockParameters
objectMock instance
methodMethod signature with wrapped parameters (Parameter
) and perform closure -
Setup perform closure for static method stubs for mock type. When this method will be called on mock type, 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(T.self, .do(with: .value(1), and: .any, perform: { ... })) Perform(T.self, .do(with: .any, and: .value(1), perform: { ... }))Method stub will return the one depending on mock sequencingPolicy. By default it means most recent one.
Declaration
Swift
public func Perform<T>(_ object: T.Type, _ method: T.StaticPerform) where T : StaticMockParameters
objectMock type
methodStatic method signature with wrapped parameters (Parameter
) and perform closure
-
Verify that given method was called on mock object at least once.
Declaration
Swift
public func Verify<T>(_ object: T, _ method: T.Verify, file: StaticString = #file, line: UInt = #line) where T : MockParameters
objectMock instance
methodMethod signature with wrapped parameters (
Parameter)filefor XCTest print purposes
linefor XCTest print purposes
-
Verify that given static method was called on mock type at least once.
Declaration
Swift
public func Verify<T>(_ type: T.Type, _ method: T.StaticVerify, file: StaticString = #file, line: UInt = #line) where T : StaticMockParameters
objectMock type
methodMethod signature with wrapped parameters (
Parameter)filefor XCTest print purposes
linefor XCTest print purposes
-
Verify that given method was called on mock object exact number of times.
Declaration
Parameters
objectMock instance
countNumber of invocations
methodMethod signature with wrapped parameters (
Parameter)filefor XCTest print purposes
linefor XCTest print purposes
-
Verify that given static method was called on mock type exact number of times.
Declaration
Swift
public func Verify<T>(_ type: T.Type, _ count: Count, _ method: T.StaticVerify, file: StaticString = #file, line: UInt = #line) where T : StaticMockParameters
objectMock type
countNumber of invocations
methodStatic method signature with wrapped parameters (
Parameter)filefor XCTest print purposes
linefor XCTest print purposes
View on GitHub
Global methods Reference