I'm using since recently OCMock for my unit testing. I need to stub the
objectForInfoDictionaryKey:
method from NSBundle
. I've done the following :
self.bundleMock = OCMClassMock([NSBundle class]);
OCMStub([self.bundleMock objectForInfoDictionaryKey:@"GITHash"]).andReturn(@"c424242");
;
Here is the call I wanna stub :
NSString * appHashString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GITHash"];
But nothing seem to be stubbed, at runtime I still have the "correct" value.
What did I do wrong ?
I could be misremembering, but I think you need to use partialMockForObject
to mock the instance returned by [NSBundle mainBundle]
, instead of mocking the class NSBundle
because objectForInfoDictionaryKey
is an instance method, not a class method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With