Xcode: how to associate application code with a test target

I am a complete newbie to Xcode (4.2). I am trying to write a simple unit test for a simple class that I wrote.

I created an empty application project, I included unit tests. I have two goals:

  • Calculator
  • UnitTests

I added the class (calculations) to the calculator group and the corresponding unit test (CalculationsTest) class to the UnitTests group.

The problem occurs when I try to instantiate the Calculations object in my CalculationsTest, and then run it. As a result, I get an error message:

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

Now I can solve this problem by adding Calculations.m to the UnitTests target in the utility view when viewing the file.

It seems to me that I'm missing something, because when my project grows and has much more dependencies between objects, I need to add each * .m class definition for both the Calculator target and the UnitTests target.

Is there a way to introduce a dependency so UnitTests always knows about the sources of the calculator?

I tried to use the assembly phases in setting up the goal, however, adding a calculator to the target dependencies of UnitTests does not seem to solve this.

+4
source share

Source: https://habr.com/ru/post/1386311/


All Articles