We're trying to create a unit test (with OCMock although, open to other frameworks) that mocks a class that on class load has a side effect.
We have a tracking class that wraps calls to other tracking libraries like Flurry.
Many of these other tracking libraries (specifically, Flurry) execute code on class initialization.
The unit test fails as the code can't execute in a unit test environment. Ideally, we would like to replace the Flurry class with a mock/stub.
- (void) testConstruction {
[Flurry class];
}
When this code is called it attempts to use SCNetworkReachability
and receives exceptions
...
How can we stub/mock out calls to Flurry that has a static implementation like the following?
[Flurry setAppVersion:@"1.0"];
[Flurry setCrashReportingEnabled:NO];
I would remove Flurry from the build configuration I'm using for test (remove it from the Framework Search path / library search path). I'd create my own dummy Flurry by grabbing the Flurry header file and creating my own implementation with empty methods. Finally, if I care that Flurry is being called, I would use OCMock to mock my fake class.
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