Search code examples
iosobjective-cunit-testingwatchkit

Watchkit Extension Test Class - Bad Access Issue


I set up a test target for my Watchkit extension by following the steps mentioned in the 'How can I unit test my WatchKit extension?' section in this link.

Then I imported a controller class from the Extension into my test class and tried to create an object for it. This is throwing a EXC_BAD_ACCESS error.

Import statement:
#import "NotificationController.h"

Creating an object:
NotificationController *controller = [[NotificationController alloc] init];

The controller class i imported is a sub class of WKUserNotificationInterfaceController. Could someone tell me what I am doing wrong?

Thanks!


Solution

  • This post from Pivotal Labs says they hit a similar issue. http://pivotallabs.com/watchkit-test-tools-pivotalcorekit/

    It sounds like using WatchKit classes directly (as you are, even with a subclass) doesn't work. Perhaps try breaking your code out into a separate, testable class and including that in your WKInterfaceController classes.