0

I meet this error when I do a unit test on xcode. I try to import "SignIn.h" and test the VerifyEmail class which is defined in SignIn.h/SignIn.m.

My code is as follows:

#import <XCTest/XCTest.h>
#import "SignIn.h"

@interface SignInTests : XCTestCase

@property (nonatomic) VerifyEmail* verifyEmail;

@end

@implementation SignInTests

- (void)testVerifyEmail
{
    _verifyEmail = [[VerifyEmail alloc] init];
}
...

I just follow the usual unit test pipeline. import "SignIn.h" and @property (nonatomic) VerifyEmail* verifyEmail are okay, but when I try to initialize verifyEmail (_verifyEmail = [[VerifyEmail alloc] init];) there is an error as below:

ld: warning: directory not found for option '-Llibs/Debug-iphonesimulator'
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_VerifyEmail", referenced from:
      objc-class-ref in SignInTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have been working on this for a long time and really need someone to help. Thanks!

Ye Tian
  • 11
  • 5
  • You need to include `VerifyEmail.m` in your build target so it gets linked in. – rmaddy Aug 18 '15 at 18:16
  • Thanks rmaddy. VerifyEmail is a method in SignIn.m. I have tried your suggestion. It tends to break down the app target. I guess it's because SignIn.h depends on a lot of other files in the app target (But I don't know the reason to break it down). I also tried this way on another class which does not depend on other files in app target, it works! Do you know why? – Ye Tian Aug 18 '15 at 18:27
  • No, `VerifyEmail` is a class, not a method. It should be in its own .h/.m pair. – rmaddy Aug 18 '15 at 18:28
  • Sorry I made a mistake. It's a class defined in SignIn.h/SignIn.m. – Ye Tian Aug 18 '15 at 18:30
  • @rmaddy Do you know why it will break down the main target when I add SignIn.m to my test target? Thanks! – Ye Tian Aug 18 '15 at 18:51
  • I have no idea since I don't know what is in `SignIn.m`. This is why each class should go in its own source file. It eliminates bringing in all kinds of unnecessary dependencies you don't want. – rmaddy Aug 18 '15 at 18:56
  • @rmaddy Yes, I agree. But what I am trying to test is a quite large and old project and thus there are a lot of unexpected issues... I create another file at the same place as SignIn, which contains 3 classes but they don't depend on other files in main target. I can import and initialize them in my test file. So it must be something wrong with the dependencies... It's really weird. – Ye Tian Aug 18 '15 at 19:17

1 Answers1

1

When trying to add unit test to an existing iOS project, sometimes one need to set "Symbols Hidden by Default" in the build settings in the main app target to No. Check this post: http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/

It still works for xcode 7. Thanks Todd!

Ye Tian
  • 11
  • 5