Reputation: 1753
I'm writing test cases using XCTest framework provided by apple. I come up with situation where i want to mock local variables allocated inside the function like this below
-(void)myFunction{
A* a = [[A alloc] init];
}
from my testcase class i want to mock class A inside my function testMyFunction
. Is there any way to do it without using OCMock.
Upvotes: 1
Views: 412
Reputation: 20980
If it's okay to create the instance first, then inject it using normal Dependency Injection techniques.
But if you need to ensure that the instance won't be created until it's needed, you have a few choices:
Upvotes: 1
Reputation: 14063
You could inject the class to be used in the method into the system unter test. In the test you can use a different class.
Upvotes: 0