Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing with UIWebView

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.

like image 694
hpique Avatar asked Oct 17 '11 12:10

hpique


2 Answers

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.

like image 125
hpique Avatar answered Oct 14 '22 08:10

hpique


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

like image 28
combinatorial Avatar answered Oct 14 '22 09:10

combinatorial