Skip to content

Asynchronous Testing

jasperblues edited this page Feb 28, 2012 · 9 revisions

It's very common for iOS applications to have components that collaborate with the main thread via background threads. Towards this end, Kiwi supports asynchronous testing, thus enabling integration tests - testing multiple objects collaborating together - as well as unit tests (testing a single component in isolation using mocks).

An example, using LRResty library:

This will block until the matcher is satisfied or it times out (default: 1s)

    context(@"Fetching service data", ^{
        it(@"should receive data within one second", ^{

            [[LRResty client] get:@"http://www.example.com" withBlock:^(LRRestyResponse* r) {
                NSLog(@"That's it! %@", [r asString]);
                fetchedData = [r asString];
            }];

            [[expectFutureValue(fetchedData) shouldEventually] beNonNil];


        });

    });

Setting the acceptable timeout:

This blocks for two seconds instead of the default one second.

[[expectFutureValue(fetchedData) shouldEventuallyBeforeTimingOutAfter(2.0)] equal:@"expected response data"];