Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is my "Target" and how do I add a file to it for unit testing?

I'm trying to add my parser.m file to the target of my unit test (or, of my unit test file?), but I have no idea how.

Here's an example of a page that indicates the necessity of using the target:

Undefined symbols for architecture i386 "_OBJC_CLASS_$_Appirater"

...and here's part of an answer from that page:

I think, that you only added files to project, but not to target. Click on Appirater.m file in Project Navigator and set checkbox near to your target name in Target membership of File Inspector.

What I don't get from that answer is, "what checkbox?". Also, how do I know my target name? Where do I find 'Target membership'?

like image 982
annag Avatar asked Jan 03 '13 21:01

annag


People also ask

Where do I put unit test files?

Where to put test files. Unit tests run against specific lines of code. So it makes sense to place them right next to that code.

How do I run a test target in Xcode?

⌘U will build and run all your test cases. It is the most commonly used shortcut when creating unit test cases. It is equivalent to ⌘R (build & run) while doing app development. You can use this shortcut to build your test target and run all the test cases in your test target.


1 Answers

In Xcode, a target is usually an app - the app which you are creating! Occasionally it is a library or framework. (You can create other kinds of targets but don't worry about that.)

You can use the File Inspector to add a file to a target, or remove a file from a target, or just check whether a file is a member of a target. Simply open a .m file or a resource file (like an image or xib) in the editor pane, then select the File Inspector in the right-hand pane of the Xcode window and find the “Target Membership” section of the inspector. Check or uncheck the box next to your target. (You usually do not want to add .h files to targets.) Here's a demonstration:

add MyObject.m to addToTargetDemo target

If you have multiple targets in the project, each target appears in the “Target Membership” section. Each source file can be a member of any combination of the targets, depending on your needs. For example, if you are creating separate iPhone and iPad apps (instead of a universal app) which share most of their code and resources, you can create a project with two targets. One target is the iPhone app and the other target is the iPad app. You add the common source files to both targets. You add the iPhone-specific .m files and resource files to the iPhone app target only. You add the iPad-specific .m files and resource files to the iPad app target only.

like image 125
rob mayoff Avatar answered Sep 27 '22 17:09

rob mayoff