How to use mock and verify methods of OCMock in objective-C ? Is there any good tutorial on OCMock i
Posted
by san
on Stack Overflow
See other posts from Stack Overflow
or by san
Published on 2010-03-04T10:47:43Z
Indexed on
2010/05/08
0:28 UTC
Read the original article
Hit count: 532
My problem is I am getting an error:
OCMckObject[NSNumberFormatter]: expected method was not invoked:setAllowsFloats:YES
I have written following Code:
(void) testReturnStringFromNumber
{
id mockFormatter = [OCMockObject mockForClass:[NSNumberFormatter class]];
StringNumber *testObject = [[StringNumber alloc] init];
[[mockFormatter expect] setAllowsFloats:YES];
[testObject returnStringFromNumber:80.23456];
[mockFormatter verify];
}
@implementation StringNumber
- (NSString *) returnStringFromNumber:(float)num
{
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setAllowsFloats:YES];
NSString *str= [formatter stringFromNumber:[NSNumber numberWithFloat:num]];
[formatter release];
return str;
}
@end
© Stack Overflow or respective owner