kiwi-bdd / Kiwi

Simple BDD for iOS
BSD 3-Clause "New" or "Revised" License
4.14k stars 512 forks source link

Partially mocked UIApplication failing tests because of unrecognized selector #686

Closed limfinity closed 7 years ago

limfinity commented 7 years ago

Precondition: Using Bolts framework and async testing; applicationMock is a partially mocked object of UIApplication

What I do: [UIApplication stub:@selector(sharedApplication) andReturn:applicationMock]; Then I test to open URLs on that mocked object

What I expect: Test runs without errors

What I receive: Test fails because of unrecognized selector sent to instance of my custom UIApplication mock class.

Reason: The selector name is _isClassic testing on iOS 10 with Xcode 8 but I've also seen displayIdentifier when testing on iOS 9 with Xcode 8.

Proposed solution: Maybe adding methods starting with an underscore to the whitelist might help.

I'm glad to hear from anybody having similar problems. :)

orta commented 7 years ago

I think you're just going to have to stub those methods. It would be a bad idea for Kiwi to try and keep track of selectors to avoid, as they change per-OS ( as you've found ) and sometimes you might want to realistically test for an underscore'd method.

One thing you could do - is make a library that generally mocks out classes with the known private internals like this, I've co-done this with a library for OCMock

limfinity commented 7 years ago

Thanks @orta! I stubbed the methods manually as you suggested.