Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to unit test a static library project using XCode's SenTestingKit?

I've created an iOS unit test target for doing logic tests following the steps provided in Apple's documentation.

However my build fails and i get the following error:

Undefined symbols:
"_OBJC_CLASS_$_MyClass", referenced from: objc-class-ref-to-MyClass in LogicTests.o ld: symbol(s) not found collect2: ld returned 1 exit status

Ordinarily, if I wanted to use my static library within an application I would include the library.a file, and the headers(including the MyClass.h file...). Is something additional required to run logic tests on a static library WITHIN that same project if my test cases are utilizing MyClass.h ?

Tjhanks

like image 296
Patrick Avatar asked Dec 16 '10 20:12

Patrick


2 Answers

Due to the nature of static libraries, you can't perform application tests, which by the sound of it is what you are trying to do. However, you can perform logic tests.

You were correct in your observation about unit testing in the client application.

The Xcode template optionally includes unit tests, but if you go to the build settings for that unit test you will see it doesn't specify a test host or bundle loader. This is because of the nature of static libraries. They are not applications, they are libraries - so you can do logic tests, you cannot do application tests.

Application tests you may wish to perform on your static library may include the following scenario:

My library creates an SQLite database at runtime, I wish to perform a unit test to check everything is inserting and/or updating as expected.

In order to test this with unit tests, one must create another application which includes or otherwise is dependant of your library. This application then includes your library and application tests may then be set up there.

like image 79
Daniel Avatar answered Oct 11 '22 09:10

Daniel


Apple has a sample up (UnitTests) that shows how to do this: https://developer.apple.com/library/ios/#samplecode/UnitTests/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011742

like image 32
quellish Avatar answered Oct 11 '22 07:10

quellish