abc123
abc123

Reputation: 8303

In iOS, how can I stub Google Analytics SDK's [GAI sharedInstance] using Kiwi?

I'm using Kiwi for tests and when I try to stub the class method [GAI sharedInstance], it doesn't work. Here is what I'm doing:

NSObject *gaiMock  = [KWMock nullMock];
[GAI stub:@selector(sharedInstance) andReturn:gaiMock];

When I break after these lines of code and compare them in the console, here is what I get:

(lldb) po [GAI sharedInstance]
<GAI: 0x10c42d940>

(lldb) po gaiMock
<KWMock: 0x112926600>

What am I doing wrong?

Upvotes: 0

Views: 209

Answers (2)

meisel
meisel

Reputation: 2455

Try [GAI stub:@selector(sharedInstance)...], as stub methods will work on class objects just like they do on instances.

Upvotes: 0

Gabe
Gabe

Reputation: 737

Have you tried swizzling [GAI sharedInstance]? Swizzling is never an ideal solution, but perhaps it could help in this case. Create a category on GAI at the top of your Kiwi test file, and override the sharedInstance method.

Upvotes: 0

Related Questions