4

I'm a complete newbie to XCode(4.2). I'm trying to write a simple unit test for a simple class I've written.

I've created an empty application project, I've included unit tests. I have two targets:

  • Calculator
  • UnitTests

I've added a class (Calculations) to the Calculator group, and a corresponding unit test class (CalculationsTest) to the UnitTests group.

The problem comes when I attempt to instantiate a Calculations object in my CalculationsTest and then run it. I end up with a linking error:

"_OBJC_CLASS_$_Calculations", referenced from:
     objc-class-ref in CalculationsTest.o

Now I can solve this by adding Calculations.m to the UnitTests target in the utilities view when looking at the file.

I feel as if I'm missing something, as when my project grows and has many more dependencies between objects, I need to add every class *.m definition to both the Calculator target and the UnitTests target.

Is there some way of introducing a dependency so that UnitTests always knows about the Calculator sources?

I've attempted to use the Build Phases in the target set up, however adding Calculator to the Target Dependencies of UnitTests doesn't appear to solve this.

Stuart Ervine
  • 1,024
  • 13
  • 15
  • possible duplicate of [Link error while building a unit test target](http://stackoverflow.com/questions/5783294/link-error-while-building-a-unit-test-target) – David Ravetti Aug 07 '13 at 21:18
  • 1
    I've flagged this as a duplicate of , but for those who stumble across this one first as I did, just a note that Martin Wickman's answer from that question (not the accepted answer) is the one you'll likely want to start with (this has been acknowledged by the author of the accepted answer as well). – David Ravetti Aug 07 '13 at 21:20

0 Answers0