About Me

My photo
Drum & Bass Producer, Software Developer, Love my Cats

How To implement an iOS Integration Tests using GHUnit

I decided to use GHUnit as a unit testing framework, based on the recommendation in this article that compares the available frameworks.

Implementing an integration test for the iOS platform is easy using GHUnit. You simply implement an asynchronous unit test. I used the ASIHttp framework for asynchronous requests, so I used it's success-failure-callbacks mechanism. You can replace the success-failure mechanism with whichever provided by the framework you're using.

Here's the boilerplate:

#import <GHUnitIOS/GHUnit.h>

@interface MyIntegrationTests : GHAsyncTestCase

@end


@implementation MyIntegrationTests

- (void) testAsyncRequest

{

// prepare for async unit test:

[self prepare];

// send your request here

// wait for success callback upto 10 seconds (or whatever you choose)

[self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0];

}

- (void)requestFinished:(ASIHTTPRequest *)request

{

// notify a success

[self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testAsyncRequest)];

}

- (void)requestFailed:(ASIHTTPRequest *)request

{

// notify a failure

[self notify:kGHUnitWaitStatusFailure forSelector:@selector(testAsyncRequest)];

}

@end

Hope this snippet helps you with implementing integration tests with your iOS client and server complex.