GH-Unit for unit testing Objective-C code, why am I getting binding errors?

I'm trying to plunge into the completely frankly awful world of unit testing using Xcode (such a confusing process seems.)

I basically have this test class, trying to test the Show.h class

#import <GHUnit/GHUnit.h> #import "Show.h" @interface ShowTest : GHTestCase { } @end @implementation ShowTest - (void)testShowCreate { Show *s = [[Show alloc] init]; GHAssertNotNil(s,@"Was nil."); } @end 

However, when I try to build and run my tests, it groans with this error: -

Undefined characters:

"_ OBJC_CLASS _ $ _ Show" referenced by:

  __objc_classrefs__DATA@0 in ShowTest.o 

ld: character not found

collect2: ld returned 1 exit status

Now I assume that this is a communication error. I tried to follow every step in the instructions located here: -

http://github.com/gabriel/gh-unit/blob/master/README.md

And step 2 of these instructions confused me: -

In the Tasks Tests window, the General tab:

Add the linked library in the Mac OS X 10.5 SDK section, select GHUnit.framework

Add a linked library, select your project.

Add a direct dependency and select your project. (This will lead to the creation of your application or framework before testing.)

How can I add my project to the list of linked libraries when it accepts its .dylib, .framework and .o files?

+5
objective-c unit-testing linker xcode gh-unit
Apr 09 '10 at 20:25
source share
3 answers

If the target you are testing is an application, you need to manually include the Show.h / m files in both your primary target and your target audience.

I also updated README to reflect this:

  • If your main goal is a library: add a linked library and select your main goal; This means that you can associate your test goal with the main goal, and then you do not need to manually include the source files in both goals.
  • If your primary goal is an application, you will need to manually include these source files in the Test project.

Sorry for the mess! Including files for both purposes is not ideal.

+7
Apr 09 '10 at 23:30
source share

You must have @implementation for Show .

Or you can use

 Show* s = [[objc_getClass("Show") alloc] init]; ... 

or

 Show* s = [[NSClassFromString(@"Show") alloc] init]; ... 

to resolve the class at runtime.

0
Apr 09 '10 at 20:29
source share

Somehow, Apple’s example works without duplicating .m files in the target.

Download the sample Apple device test code (iPhoneUnitTests.zip) here:

http://developer.apple.com/IPhone/library/samplecode/iPhoneUnitTests/Introduction/Intro.html

Click on the CalcTests target. For this purpose, only CalcTests.m is located.

Create a goal. It builds without any link errors for CalcAppDelegate or other classes.

What magic makes this work?

0
Apr 10 '10 at 2:52
source share



All Articles