As you said, OCMock does not support Swift (or OCMockito), so now the only way I can see is to create a manual layout. In the fast, this is a little less painful, since you can create inner classes inside the method, but still not as convenient as a mocking structure.
Here you have an example. The code itself is explicit, the only thing I needed to do (see EDITING 1 below) to make it work was to declare the classes and methods that I want to use from the test as public (it seems that the test classes do not belong the same application code module - will try to find a solution for this).
EDIT 1 2016/4/27: Declaring classes that you want to check as public is no longer required, as you can use the "@testable import ModuleName" function.
Test:
import XCTest import SwiftMockingPoC class MyClassTests: XCTestCase { func test__myMethod() {
Myclass.swift
public class MyClass { let myService: MyService public init(myService: MyService) { self.myService = myService } public func myMethod() { myService.doSomething() } }
MyService.swift
public class MyService { public init() { } public func doSomething() { } }
e1985
source share