1

My idea is to create a category of UIActionSheet in order to be able to mock the different possible user interactions (select item / cancel) and to check the correct initialization.

I was hoping that by importing the category that I created into my test, all farther usages of UIActionSheet are going to be through that category, but it's not the case. Has anyone had similar experience? What other ways do you suggest to do UI mocking?

@interface UIActionSheet (LMActionSheetMonkey)
    bla bla
@end

Another idea is to import the category in the class using #ifdef TESTAPP, but i'm trying to affect my actual implementation for the sake of testing.

Mabedan
  • 857
  • 8
  • 30

1 Answers1

0

You can certainly do this, especially if you combine it with a bit of swizzling. I have recently done this.

EDIT - the below bit is no longer true.

I used to use OCMock, but it doesn't work properly with ARC and weak references: http://joris.kluivers.nl/blog/2012/03/26/weak-references-to-nsproxy-with-arc/ because of an iOS bug whereby a weak reference to an NSProxy is always nil Why is my object's weak delegate property nil in my unit tests?

Community
  • 1
  • 1
Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75
  • Swizzling is the method that I tried to use, but the swizzled implementation is not picked up in the test*ed* class. – Mabedan Jul 10 '14 at 12:59
  • 1
    Apple fixed the weak reference to NSProxy instances bug a while ago, with iOS 6, I'm pretty sure. It has not been an issue for a while. – Carl Lindberg Jul 10 '14 at 13:09
  • @Carl thanks - I ran a test project just now and it is definitely fixed; implies I have a separate problem with OCMock I need to investigate further. – Airsource Ltd Jul 10 '14 at 13:20