I ran into an interesting problem today while trying to write some unit tests for an SDK we’re helping to build at work. It involved instantiating a third-party library, then running a few tests to be sure that our delegate code was being called as expected.
The problem is that the third party library contained code to instantiate a UIWebView. At first I was puzzled. That couldn’t be causing a crash. I ended up stripping out the actual test and just putting in a line like this:
UIWebView *wv = [[UIWebView alloc] init];
And an exception was thrown.
After Googling around for a while, I came across a Stack Overflow post discussing the behaviour. It looks like when you’re trying to test UIWebView in a static library, it needs an app target set to run. I created an empty app, set it as the target, and boom, we had a working unit test.
It’s the things like this that make me realize that I’ll never be done learning.