Unit testing with UIWebView

2k Views Asked by At

When creating an UIWebView inside an unit test I get EXC_BAD_ACCESS:

-(void)test1 {
    [[UIWebView alloc] initWithFrame:CGRectZero];  // EXC_BAD_ACCESS
}

Is there a special configuration to run units test that involve UIWebView?

I'm using OCUnit/SenTest on XCode 4.2.

2

There are 2 best solutions below

1
On BEST ANSWER

Apparently this only happens when unit testing a static library directly. Most likely whatever UIWebView needs is not loaded with an empty test host.

When unit testing an app this doest not occur.

5
On

You can create an app target that is just for running your unit tests. Create a new empty application in the same workspace and set this as the Target for the unit test target. I call my app TestRunner.

enter image description here