Skip to content

Asynchronous Testing

MattesGroeger edited this page Mar 18, 2012 · 7 revisions

Specs | Expectations | Mocks and Stubs | Asynchronous Testing

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.

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"];

Clone this wiki locally