Skip to main content

DeliciousRaspberryPi/MockFive - A Mocking Framework for Swift Unit Tests

MockFive allows you to make a single mock for a class or protocol. You can then configure instances of this mock with stubbed implementations. For any commonly used class, MockFive can offer a powerful means to satisfy Swift's strict typing system without sacrificing power. Because of Swift's strict typing, you must implement every method you intend to mock with calls to MockFive's stub().

// Optional types will return `nil` by default
func myFunc(arg1: Int, arg2: String) -> String? {
    return stub(identifier: "myFunc", arguments: arg1, arg2)
}

// Non-optional types require a default value
var customItem = MyCustomClass() // This may be changed later. stub will return new value
func myFunc() -> MyCustomClass {
    return stub(identifier: "myFunc") { customItem }
}

MockFive GitHub

Comments