Created
January 19, 2012 23:46
-
-
Save levigroker/1643797 to your computer and use it in GitHub Desktop.
Sample GHUnit Asynchronous Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <GHUnitIOS/GHUnit.h> | |
@interface RemoteDataServiceTest : GHAsyncTestCase { } | |
@end | |
@implementation RemoteDataServiceTest | |
- (BOOL)shouldRunOnMainThread | |
{ | |
// By default NO, but if you have a UI test or test dependent on running on the main thread return YES. | |
// Also an async test that calls back on the main thread, you'll probably want to return YES. | |
return NO; | |
} | |
- (void)testAsynchronousOperation | |
{ | |
// Call prepare to setup the asynchronous action. | |
// This helps in cases where the action is synchronous and the | |
// action occurs before the wait is actually called. | |
[self prepare]; | |
[RemoteDataService doNiftyStuffRemotelyWithCompletedBlock:^(id result){ | |
if (!result) | |
{ | |
GHTestLog(@"result from remote service was unexpectedly nil."); | |
[self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; | |
return; | |
} | |
GHTestLog(@"We got back: %@", result); | |
[self notify:kGHUnitWaitStatusSuccess forSelector:_cmd]; | |
} errorBlock:^(NSError *error){ | |
GHTestLog(@"Error while doing nifty stuff: %@", [error localizedDescription]); | |
[self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; | |
}]; | |
// Wait until notify called for timeout (seconds); If notify is not called with kGHUnitWaitStatusSuccess then | |
// we will throw an error. | |
[self waitForStatus:kGHUnitWaitStatusSuccess timeout:30.0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment