Search code examples
iphonecocoagh-unit

GH-Unit and "Undefined symbols" error


I'm using GH-Unit for my unit tests. I've set it up according to the instructions, but I'm getting an "Undefined Symbol" error on this line:

#import "GHUnit.h"
#import "ChecklistAppDelegate.h"

@interface TestAppDelegate : GHTestCase {}
@end

@implementation TestAppDelegate

- (void)testStoringProperties {
    ChecklistAppDelegate *appDelegate = [[ChecklistAppDelegate alloc] init];
}

If I add ChecklistAppDelegate to the Tests target, the undefined symbol error goes away, but I get 37+ errors, one for each declaration of a Core Data class in my AppDelegate (there's a lot). Most of them are of the form, expected specifier-qualifier-list before 'NSPersistentStoreCoordinator'

I thought I might solve this by linking my Tests target against the Core Data framework, but that didn't work. I also tried #import <CoreData/CoreData.h> in my AppDelegate file, but that didn't work either.

Any ideas? I've tried removing all traces of GH-Unit and re-adding it a few times and it's still not working.


Here is the error from the build result

Undefined symbols:
  ".objc_class_name_ChecklistAppDelegate", referenced from:
      literal-pointer@__OBJC@__cls_refs@ChecklistAppDelegate in TestAppDelegate.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Solution

  • Fixed it. I added

    #import <CoreData/CoreData.h>
    

    to my Tests_Prefix.pch prefix header file.