Using any assertion in a callback makes the GH-Unit app crash. Assertions work fine elsewhere.
There is a similar question here: Why does a false assertion in async test in GHUnit crash the app instead of just failing the test?
But I don't understand how I can use this solution in my case.
- (void)testLoadMyProfile {
void(^successCallback)(NSString*);
successCallback = ^(NSString* response) {
NSRange textRange;
textRange =[[response lowercaseString] rangeOfString:[@"syntactically incorrect" lowercaseString]];
if(textRange.location != NSNotFound) {
GHFail(@"the request was syntactically incorrect");
}
NSDictionary *d;
@try {
d = [response JSONValue];
} @catch (NSException *exception) {
GHAssertNotNil(d, @"The response was not a valid JSONValue");
}
GHAssertNotNil([d objectForKey:@"memberId"], @"memberId wasn't in response");
GHAssertNotNil([d objectForKey:@"profile"], @"profile wasn't in response");
GHAssertNotNil([d objectForKey:@"name"], @"profile wasn't in response");
GHAssertNotNil([d objectForKey:@"surnamez"], @"profile wasn't in response");
};
void(^errorCallback)(NSString*);
errorCallback = ^(NSString* response) {
GHFail(@"the error callback was called");
};
// this is using ASIHTTPRequest to retrieve data
[[RestAPIConnector sharedInstance] loadMyProfile:successCallback :errorCallback];
}
I can stop the app from crashing by overwriting this method - I could even log the exception, but the test doesn't display as failed on the front end. Ideally, I'd like it to display on the front end so non technical people can run the test and see that everything is working.
- (void)failWithException:(NSException *)exception {
}