I\'m running into a strange problem that I haven\'t run into before.
When you do cmd+U to run your Unit Tests (OCUnit for example) does it actually call the main.m,
I found another solution to the problem:
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, ({
![NSProcessInfo processInfo].environment[@"XCTestConfigurationFilePath"] ?
@"AppDelegate" :
nil;
}));
}
}
From here: http://qualitycoding.org/app-delegate-for-tests/#comment-63984
Using xCode 7 and xCtool
xctool is capable of executing unit tests without running the app.
To get this working,
1 . Update target settings to run without a host app.
Select your project --> then test target --> Set the host application to none.
2. Install xctool , if you don't have it.
brew install xctool
3. Run the tests using terminal with xctool.
xctool -workspace yourWorkspace.xcworkspace -scheme yourScheme run-tests -sdk iphonesimulator
You can do that by setting the Host Application to None in your Tests Target.
I use the approach of Tomasz Bak plus some code of dwb answer and come up with the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL runningTests = NSClassFromString(@"XCTestCase") != nil;
if (runningTests) {
self.window.rootViewController = [UIViewController new];
return true;
}
// Your normal code below this
....
}