8

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.

hpique
  • 119,096
  • 131
  • 338
  • 476

2 Answers2

6

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.

hpique
  • 119,096
  • 131
  • 338
  • 476
  • 4
    So, is there any way to test using a UIWebView in a static library? I added UIKit to the Build Settings of the static library, but I'm still getting this EXC_BAD_ACCESS any time I try to run the test. – seanoshea Sep 16 '13 at 16:55
2

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

combinatorial
  • 9,132
  • 4
  • 40
  • 58
  • Can you elaborate a little more on this? This seems like a reasonable solution. But did you mean an empty app within the same project or is there a better way to go about setting this up? – poweratom May 20 '14 at 23:47
  • 1
    I added a screenshot that shows where the target is configured. – combinatorial May 21 '14 at 14:47
  • It was the "empty application" part I didn't quite get. But now that I've got it to work, I realized all you meant was a shell application that has no features (empty methods... etc) that just compiles which then allows itself to be "targeted" by our tests to run on. This totally works and is a viable solution. Thanks! – poweratom May 21 '14 at 18:09
  • 1
    Just to follow up here. I got the full test suite to work. Luckily this particular project is open source, and the code/methodology can be found in this repro: https://github.com/BlueKai/bluekai-ios-sdk/tree/master/sdk – poweratom Jun 19 '14 at 22:59
  • Doesn't help me. I receive `GuardMalloc[UnitTestRunner-16080]: could not allocate new zone: (os/kern) no space available` instead of `uardMalloc[xctest-16321]: could not allocate new zone: (os/kern) no space available`. – Alex Cohn Oct 12 '21 at 11:32