2

I have written a framework with all the utility(Common) functions in Objective-C. Since it is a framework, it does not have an App delegate file.

I have created an UIApplication class and have few utility methods in it.

@interface TestApplication : UIApplication
{
- (void)initialLockSetUp;
// more...
}

Now from my unit tests file, how can I test this "initialLockSetUp" method?
When I call (TestApplication*)[UIApplication sharedApplication], it is returning nil.

Ajean
  • 5,528
  • 14
  • 46
  • 69
Coder
  • 1,661
  • 4
  • 27
  • 50

1 Answers1

0

If for some reason you need a UIApplication instance for your tests, the test host for your test target should be an application. You can then link your framework to that test target. Now [UIApplication sharedApplication] will return a valid UIApplication instance. The OS creates this instance when the app launches, so you won't be able to subclass it.

Here's a screenshot of the project settings:

enter image description here

Patrick Lynch
  • 2,742
  • 1
  • 16
  • 18