square/KIF — Issue #109: Easier setup
Author: letsdev
Created: 2012-01-31 11:03:06+00:00
State: open

Hi,

I found it much easier to create a IntegrationTestAppDelegate that inherits from my apps delegate and add something like this:

#import "IntegrationTestsAppDelegate.h"
#import "MyTestController.h"

@implementation IntegrationTestsAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[super application:application didFinishLaunchingWithOptions:launchOptions];

[[MyTestController sharedInstance] startTestingWithCompletionBlock:^{
// Exit after the tests complete so that CI knows we're done
exit([[MyTestController sharedInstance] failureCount]);
}];

return YES;
}

@end

Doing it this way has the following advantages:
- Clean separation of the actual apps target and the integration tests target
- No need for the additional Preprocessor Macro RUN_KIF_TESTS

Disadvantages:
- You also need to implement a separate main for the Integration Tests that could look like this:
#import
#import
#import "IntegrationTestsAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([IntegrationTestsAppDelegate class]));
}
}

I clearly like this variant better for the sake of the complete separation between tests and production code.

What do you think?