When I am running my unit test, I don't reach my breakpoint, and I think that the test isn't properly running my code.
I am trying to do an asynchronous test, which is part of my difficulty.
How do I set up the test so that testLookupBook
will be called, as I hope that that will lead to everything else being called properly.
I am guessing that the function to test should be somewhere in the header file, but I did start my test method with test
.
Here is my header file:
@interface jabBookScanTest : SenTestCase {
jabBookScan *instance;
NSArray *searchResult;
}
@end
And the implementation for the test is here:
- (void)MethodNameToCallBack:(jabBookScan *)manager
resultFromServer:(NSArray *)s {
searchResult = s;
}
- (BOOL)waitForCompletion:(NSTimeInterval)timeoutSecs {
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeoutSecs];
BOOL done = false;
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
if([timeoutDate timeIntervalSinceNow] < 0.0)
break;
} while (!done);
return done;
}
- (void)testLookupBook {
NSDate *fiveSecondsFromNow = [NSDate dateWithTimeIntervalSinceNow:5.0];
[instance lookupBook:(NSString *)@"9780262140874"];
[[NSRunLoop currentRunLoop] runUntilDate:fiveSecondsFromNow];
STAssertTrue([self waitForCompletion:90.0], @"Failed to get any results in time");
}