I am new to OCUnit and OCMock and would like to learn more about this testing methodology.
I am aware of OCUnit and OCMock's capabilities to create stubs generate mock object etc...
I have a particular use case that I have not been able to crack just yet.
-(bool) isGameCenterAvailable
{
// Check for presence of GKLocalPlayer API.
Class gcClass = (NSClassFromString(@"GKLocalPlayer"));
// The device must be running running iOS 4.1 or later.
bool isIPAD = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
NSString *reqSysVer = (isIPAD) ? @"4.2" : @"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);
return (gcClass && osVersionSupported);
}
Here are my issues with Unit Testing this:
1) NSClassFromString(@"GKLocalPlayer") is a call to foundation.h with no ability to stub this that I know of.
2) [[UIDevice currentDevice] systemVersion] are calls that are local to scope to the function. My method calls methods inside another Class (UIDevice) I would like to override their function call with stub to return a canned answer to exercise every path of this function.
Not sure if Classes can be mocked if they are instantiated within the scope of the function under test.
In addition how does one test Class methods like #1.
Is refactoring the only answer here?