You are creating a mock, but the method you are testing is not using the mock, it's using an instance of the original ACAccountStore class.
If you are willing, the easiest way to make methodToTest
testable is to have it accept an instance of ACAccountStore as an argument.
- (void)methodToTestWithAccountStore:(ACAccountStore *)accountStore;
Then your test looks like this:
[myClassInstance methodToTest:mockAccountStore];
This would follow a dependency injection pattern. If you don't like this pattern, you could mock the alloc
method of ACAccountStore to return your mock object, but I am always wary of possible side-effects from mocking alloc
and instead would suggest creating a factory for ACAccountStore:
@interface ACAccountStore (Factory)
+ (instancetype)accountStore;
@end
@implementation ACAccountStore
+ (instancetype)accountStore { return [[ACAccountStore alloc] init]; }
@end
If you use this pattern, you can mock your factory method.