-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spy_on NSDate crashes on Xcode 10 #406
Comments
Workaround: replacing Cedar's
|
|
Hello @aaa-abrowne ! Thanks for writing up such a clear issue, you've made it really easy for me to understand at a high-level what's happening. If you're curious, I'm fairly sure this is happening because the core of Cocoa and Foundation is slowly being rewritten in swift. Cedar makes the assumption that anything it spies on is a proper objective-c object, and spying on Swift objects is not supported. The impressive objective-c shim that exists does a good job of hiding the work Apple is surely doing here, but it's inevitable things like this will happen as Apple slowly starts changing the core of Foundation and other frameworks. All that aside, I think this is really unlikely to be fixed. Even knowing that OCMock supports it, I think that's highly undesirable. In terms of best use of mocking frameworks, something you'll hear occasionally is the precept "Don't mock types you don't own", or stated in other words "Only mock interfaces that you have defined yourself in your proper application. Do not mock external interfaces". You can find this discussed in much detail on the internet if you'd like to learn more about this element of using mocks. Additionally, I'd consider an In terms of how to best apply mocks and spies in an Objective-C or Swift codebase, I haven't ever found a lot of materials (I'd love to write a blogpost on this topic) but I did find a great discussion on StackOverflow that is really aligned with the solutions I've found helpful in my codebases in the past. Using solutions where you define the needs of your objects in terms of the domain specific messages and data they need, rather than directly using the built-in classes provided by Apple can help you arrive at solutions that are more flexible, easier to test, easier to understand, although they can be perceived as less idiomatic occasionally (although I don't personally find that to be such a bad thing. Idiomatic does not mean "best solution" in my opinion). All that said, I'd like to try to find a reasonable way to resolve your problem. It looks like in this stack trace, it failed because you have some mocked What are your thoughts on such a solution ? Do you feel such a warning with helpful messaging around what to do here would help you to write better tests ? |
Thanks for the timely response. We're currently supporting legacy code that extensively uses |
Cool thanks for the quick response @aaa-abrowne. There's an outside chance that I may have contributed to some of those spying practices on Foundation and UIKit objects, so if that's true I beg your eternal forgiveness for the sins I have committed against best practices. I will say, while I was writing this up, I was reflecting on some of the challenges we face (as TDD practitioners that practice good OO hygiene) while attempting to use the richness of Cocoa in a codebase with tests. The sheer convenience of methods on classes such as Probably something to think about when working in a codebase with rich usage of Out of curiousity, are there any other Apple frameworks that you are using that would be useful to avoid mocking ? I've used the |
After updating to Xcode 10, we saw our tests crashing when swizzling Foundation methods like
[NSDate date]
.The text was updated successfully, but these errors were encountered: