Last Updated: February 25, 2016
· cbess

Easy iOS/Mac Asynchronous Unit Testing

Easy async unit testing, that doesn't require a framework composed of several files, it can be done with one.

The Gist

Sample test case:

// This Test Case class uses CBAsyncTestCase as the base class

@implementation MyTestCase

- (void)testNetworkStuff
    [self beginAsyncOperation]

    NSString *identifier = @"777"
    [_networkManager fetchStuffWithID:identifier completion:^(NSArray *results, NSError *error) {

        STAssertNil(error, @"error occurred: %@", error);
        STAssertTrue(results.count, @"no results");

        [self finishedAsyncOperation];

    // waits for async operation or timeout and fail assertion
    [self assertAsyncOperationTimeout];


CBAsyncTestCase - The Gist