Unit testing with UIWebView
Asked Answered
S

2

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.

Safranine answered 17/10, 2011 at 12:11 Comment(2)
I get occasional EXC_BAD_ACCESS when debugging on the simulator, but never when running on the device. I suspect a bug :/Polypetalous
I have the same exact problem! I thought it was just me. Maybe you can't test UIWebView?Colville
S
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.

Safranine answered 15/12, 2011 at 12:11 Comment(1)
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.Eliciaelicit
G
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

Gambrill answered 26/3, 2014 at 5:15 Comment(5)
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?Paba
I added a screenshot that shows where the target is configured.Gambrill
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!Paba
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: github.com/BlueKai/bluekai-ios-sdk/tree/master/sdkPaba
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.Mcphail

© 2022 - 2024 — McMap. All rights reserved.