Example:
If the class under test has init: and an initWithDependency:(Thingy *)
So if the class had an instance variable of myThingy:
- Code: Select all
Thingy *myThingy;
Then the init in the implementation would normally do the following:
- Code: Select all
- (id)init
{
Thingy *newThingy = [[Thingy alloc] init];
myThingy = newThingy;
[newThingy release];
return self;
}
and the initWithDependency would simply do:
- Code: Select all
- initWithDependency:(Thingy *)newThingy
{
myThingy = newThingy;
}
and the dealloc method then tries to release the instance variable
- Code: Select all
- (void)dealloc
{
[myThingy release];
}
This fails when I try and pass in an OCMockObject. As the mockForObject method is a class level method, there is no need to call 'release' on the mockObject as it's in the AutoRelease pool.
So given I'm trying to not amend my original class design too much to allow it to be mock unit-tested, is there any obvious way around this issue, where an instance variable could be set with an object created from an alloc, or a mock object that's being maintained by the autorelease pool?
Cheers,
Jonathan