Question

I'm running SenTestKit unit tests in Xcode 5 (actually, they're integration tests with KIF 2, but it amounts to the same thing). These tests take a long time to run. Is there a way to have the entire test suite fail with the first test failure?

Was it helpful?

Solution

You can abort testing on the first SetTestKit test failure by calling [self raiseAfterFailure] at the start of each test case. However, this does not work for KIF 2.

I ended up subclassing SenTestObserver like so:

@interface TestObserver : SenTestObserver
@end

@implementation TestObserver

+ (void)load {
    [[NSUserDefaults standardUserDefaults] setValue:@"SenTestLog,TestObserver"
                                             forKey:SenTestObserverClassKey];
}

+ (void)testCaseDidFail:(NSNotification *)notification {
    // Fail fast
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        exit(1);
    });
}

@end

Edited to add dispatch_after so that there's time to capture test output before terminating the test suite.

OTHER TIPS

You can simply use a flag, but in this case you should carefully look after the UI elements when you are testing with KIF. A good extension to KIF is a method which returns true if a given element exists. If should but it doesn't then set the flag. Then you can simply start all test cases with the check for the flag. If you need help with that method, just ask! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top