Communication error for unit testing with Xcode 4?

I want to write some logical unit tests for classes in my Xcode application. In Xcode 4, I clicked on the project name in the Project Navigator, and below clicked on Add Target. I selected the “Cocoa Touch Unit Testing Bundle” in the “Other” section to give the new goal “product name” “tests” and finish.

Since the class that I want to test is compiled as part of my existing target application, for my new “tests” task, I immediately go to the “Phase Assembly” tab and add my existing target as the only target dependency.

Then I go to the created test.m file, import the class I want to check (under it ReleasePlanManager ) and call one of its methods. But the linker fails with an error, for example:

 Undefined symbols for architecture i386: "_OBJC_CLASS_$_ReleasePlanManager", referenced from: objc-class-ref in tests.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status 

So the class cannot be found, although (in my opinion) adding the purpose of the application (which is part) should be sufficient?

Any help would be greatly appreciated. Thank!

+23
objective-c unit-testing linker xcode ocunit
Jun 23 2018-11-11T00:
source share
1 answer

The test kit requires additional settings:

  • Set the Bundle Loader to $(BUILT_PRODUCTS_DIR)/AppName.app/AppName (replacing AppName in both places with the name of your application)
  • Set the test host to $(BUNDLE_LOADER)

(If you create a project from scratch and include unit tests, they are configured for you, but if you add the unit test package to an existing project, it is not.)

+33
03 Sep 2018-11-11T00:
source share



All Articles