Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do I need to manually add each *.m file to my unit test target when it's needed?

I'm using Unit Testing in XCode 4. I've been adding my application *.m files to the unit test target "compile sources" as I refer to them so the unit test will build/run.

Is there a better way here?

Note - I've just tried adding the application to the unit test target "target dependencies", but this didn't seem to work (still get some build errors).

like image 393
Greg Avatar asked Apr 27 '11 23:04

Greg


2 Answers

Prior to Xcode 4, the approach you describe was necessary: An application test target had to essentially be a copy of your actual application, plus tests.

But with Xcode 4, we no longer need to do this for testing in the simulator. Instead, use a target that is a unit test bundle, and add your tests to the bundle. During testing, the application is launched, and the test bundle will be injected into and linked with the application, all at runtime.

Since it sounds like you tried this approach, let's discuss the actual errors you get.

like image 163
Jon Reid Avatar answered Oct 17 '22 06:10

Jon Reid


Yes, you will need to add each and every .m file you need to your unit test target.

This will include them in the target compile and link phases.

like image 40
Claus Broch Avatar answered Oct 17 '22 07:10

Claus Broch