Swift: Support partial mocking
| Originator: | thebuckley | ||
| Number: | rdar://17165464 | Date Originated: | 04-Jun-2014 05:32 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | New Feature | Reproducible: | N/A |
Partial mocking is very, very useful for writing unit tests. Partial mocking is the ability to replace the implementation of a function of a specific instance with a stub that tracks the parameters passed in and returns a convenient value for testing. You can also add expectations on how many times the function is called for a set of parameters. In C++, we accomplish this either by subclassing the class to be mocked, or by creating a proxy class. There are problems with both of these approaches. First, subclassing does more than a simple mock, so the subclassed object does not function 100% identically to the original (aside from the mocked object). Proxy objects need to implement forwarding for every non-mocked function of the original object, except for the mocked functions. This means you have to update the proxy class to keep it in perfect sync with the original. In C++, you sometimes need multiple proxy classes, but I don't think that's needed in Swift, since functions are first-class objects. Neither of these solutions are great, and it would be very helpful if Swift just natively supported partial mocks.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!