views:

858

answers:

4

I am writing a number of static libraries for the iPhone and wish also to have suites of unit tests. XCode 3 provides templates for both static libraries and unit tests but I am wondering how they should fit together in a static library project?

In my static library project I have created a target for unit testing but expect to also create an executable to kick off the unit tests than run against the classes in the static library.

What is the procedure for doing this?

+3  A: 

Note that some classes of tests (like anything that would rely on the system calls such as [UIApplication sharedApplication] working require a separate target, while pure logic tests do not.

Create a new project with Unit Test and see what is added - basically you can do the same thing easily, create a new target and select "Unit Test Bundle" as the target type.

Kendall Helmstetter Gelner
Great - I can execute these now when building - but how can I debug said unit tests?
teabot
A: 

Hi teabot, Please look into this thread. We have made tried making a static lib but we are not able to use it in other project. We are getting this error "

.objc_class_name_XMLParser", referenced from:
      literal-pointer@__OBJC@__cls_refs@XMLParser in Minutes2MidnightViewController.o
  ".objc_class_name_TickerViewController", referenced from:
      literal-pointer@__OBJC@__cls_refs@TickerViewController in Minutes2MidnightViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

" XML..and Ticker...are my classes using them static lib is made and "MinutesToMidnight" is the project where I am using this static Lib. I think this is something related to Linker error but how to resolve ? Please Help.

Amit Jain
A: 

In case people still have problems with using static libraries:

I've created an article that explains how to create static libraries and how to use them within projects:

Xcode: The complete explanation on how to use static libraries: http://www.sodeso.nl/?p=822

And for the unit testing part of static libraries, i don't have an explanation on how to set it up but i do have created a static library template that uses Google Toolkit for Map unit testing framework which you can download and add to your Xcode installation:

Xcode: Static library template with Google Toolkit for Mac Testing framework: http://www.sodeso.nl/?p=982

ronaldmathies
A: 

Hi Amit Jain, you have to add all your .m related files in the unit test target. (Just drag and drop!)

Tarek