How do you mock an object in Swift?
The Mirror
protocol sounded promising, but it doesn't do much right now.
So far the only approach I found is to subclass and override all methods of the mocked class. This is of course not a true mock, far from ideal, and a lot of work.
Any other ideas?
Why not OCMock?
From the source:
Can I use OCMock using the language bridge functionality?
Yes, but with limitations. If you are brave. As of now this is highly experimental. There's no guarantee that OCMock will ever fully support Swift.
Known limitations:
- Tests have to be written in Objective-C
- Objects that should be mocked must inherit from NSObject
- No stubbing/expecting/verifying of class methods