This morning I tried a couple of different approaches:
Using the UIDevice category, which is only related to my test purpose. In this category, I would override currentDevice with a partialMock ( OCMock ) implementation and partialMock required method so that it returns Pad or Phone forcibly to my specifications. It should have work, but it is very difficult to drop it with classes such as UIDevice or UIApplication , the simulator often crashes, which is a bad sign.
#undef UI_INTERFACE_IDIOM() and #define on my .pch test. UI_INTERFACE_IDIOM() specifying UI_INTERFACE_IDIOM() implementation in the test for a single instance of singleton, which I could install on a Pad or Phone, respectively. This worked, but the main problem is that when you run the tests, the simulator also goes up (tests of the applications that are), so if you run tests on the iPad, your test will pass, but other parts of the simulator will fail, because of conflicting of the answers that he receives from UI_INTERFACE_IDIOM() (one of these is loading an iPhone-specific nib if you are in a universal application environment)
I think this is the best approach. Like everything in computer science, just enter another layer in =) Instead of code using UI_INTERFACE_IDIOM() , to evaluate whether it is on a Pad or Phone device, encapsulate this logic into an object that you can make fun of during tests. This way, UI_INTERFACE_IDIOM() will be available to the rest of the simulator. Your production code will actually rely on it, but your tests will rely on a shaded implementation that might respond as expected in your tests.
If you want, I can share some codes on this. And yes, it is exhausted!
How did you get around this?
source share