Other Functions

The following functions are available globally.

At least once static member called

  • 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 : StaticMock

    Parameters

    object

    Mock type

    method

    Method signature with wrapped parameters (Parameter)

    file

    for XCTest print purposes

    line

    for XCTest print purposes

Static member called with explicit count

  • 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 : StaticMock

    Parameters

    object

    Mock type

    count

    Number of invocations

    method

    Static method signature with wrapped parameters (Parameter)

    file

    for XCTest print purposes

    line

    for XCTest print purposes

Given

  • 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:

    1. First check most specific givens (with explicit parameters - .value), then for wildcard parameters (.any)
    2. More recent givens have higher priority than older ones
    3. 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 : StaticMock

    Parameters

    object

    Mock type

    method

    Static method signature with wrapped parameters (Parameter) and return value

    policy

    Stubbing policy - uses mock policy by default (which defaults to .wrap)

Perform

  • 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:

    1. First check most specific performs (with explicit parameters - .value), then for wildcard parameters (.any)
    2. More recent performs have higher priority than older ones
    3. 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 : StaticMock

    Parameters

    object

    Mock type

    method

    Static method signature with wrapped parameters (Parameter) and perform closure