Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:07:48+00:00 2026-06-14T04:07:48+00:00

Having trouble getting unit tests set up for a specific scenario. Here’s what I’m

  • 0

Having trouble getting unit tests set up for a specific scenario. Here’s what I’m trying:

  • In Xcode 4.5, I created a simple OSX “Command Line Tool” application project (Foundation).
    Note that Xcode does not provide the option to add unit tests to a “Command Line Tool” project automatically – so please don’t suggest ticking the ticky-box; it ain’t there :-/

  • In my project, I created a trivial example class that I’d like to test; e.g. “Shape”.

  • I followed instructions in Apple’s Xcode Unit Testing Guide for Setting Up Unit-Testing in a Project:

    • I added a unit test target to my project, and

    • I edited the “Test” scheme to run the tests in the new target.

  • In the test project’s implementation (.m) file, I added an import for Shape.h and code in the setUp() method to instantiate a shape and assign it to an instance variable.

At that point, I decided to see if things would build and if the default test would run still. However, when I selected Product…Test from the menu, the build failed with the following error:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Shape", referenced from:
      objc-class-ref in ExampleTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Interpreting this error is not the issue. I grok that the unit test target isn’t being linked to the binary containing Shape’s implementation. However, I don’t (yet) grok Xcode unit testing & target configuration. So:

What do I need to do in order to get the test target linking against the command line tool’s resulting output? Can I link to a command-line executable from the unit test target? Apple’s documentation looks specific to regular OSX applications (*.app) and iOS applications, and this is neither.

I have business logic classes that I’d like to develop in a command-line tool setting (to begin with), so I’d like to understand what I need to do to get a unit test target running in a “Command Line Tool” type of project. Thank you!

(p.s. Note that I’m not interested in running my unit tests from the command line – Stack Overflow already suggested “similar” questions on how to do that – but rather running unit tests on a “Command Line Tool” type project, and still from within Xcode.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:07:49+00:00Added an answer on June 14, 2026 at 4:07 am

    I’ve determined a workaround I find suitable and which doesn’t appear to have significant drawbacks, other than an added target.

    In a nutshell: the solution involves adding a static library target to take advantage of Xcode’s ability to create & run unit test code around such a target. The command line tool target then delegates to the static library, where an alternate main()-like function is defined and called by the real main() entry point. The command line tool is kept free of non-trivial code, so the unit test target can access everything worth testing.

    Here are the steps:

    • From an empty Xcode, from the menu choose File…New Project.

    • In the resulting dialog, chose OS X…Application…Command Line Tool. For the purpose of this example, I’ll assume it is named SampleCmd.

    After the basic command line tool project has been created:

    • From the menu choose File…New…Target.

    • In the resulting dialog, choose OS X…Framework & Library…Cocoa Library. For the purpose of this example, I’ll assume it is named SampleCmdLogic.

    • Choose type Static, so the command line tool will remain a stand-alone executable.

    • Make sure the Include Unit Tests box is checked.

    After the static library project has been created:

    • Copy the main() function from main.m to SampleCmdLogic.m, replacing the @implementation block. (This file will hold the main entry point only. Other files can be added for Objective-C classes, etc.)  Rename the function to libMain().

    • In SampleCmdLogic.h, add a declaration for the new libMain(), replacing the @interface block:
      int libMain(int argc, const char * argv[]);

    • In the command line tool’s main.m, add an #import "SampleCmdLogic.h" at top.

    • In the command line tool’s main.m, change the entire contents of the real main() function to:
      return libMain(argc, argv);

    The code is now ready, but there are required linking steps:

    • In the project settings for SampleCmd, under Build Phases, expand Target Dependencies and add (+) SampleCmdLogic as a dependency.

    • In the project settings for SampleCmd, under Build Phases, expand Link Binary With Libraries and add (+) libSampleCmdLogic.a

    Everything is now ready. When you change to the SampleCmd target and choose Product..Run from the menu, the build should succeed and output generated as expected. When you change to the SampleCmdLogic target and choose Product…Test from the menu, the build should succeed and the unit tests will run. The single issue reported will be the initial default failing unit test assertion inserted by Xcode, in SampleCmdLogicTests.m. This is expected.

    From this point on, proceed to add all logic and corresponding tests to the SampleCmdLogic target. The SampleCmd target is to remain trivial and providing the command line tool entry point only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on unit tests for my little daemon but I'm having trouble getting
I am having trouble getting unit tests to use resources provided under src\test\resources instead
I am having trouble getting my application to work correctly. I am trying to
I'm having trouble getting OpenGL 3.2 to run on Lion (osx 10.7.4) using Derelict3
Having trouble getting my JQuery POST to be accepted by the WCF Service. Here's
I'm trying to parse SQL search conditions and having trouble getting the parser to
I am having trouble getting the Google Sitemap to automatically generate. Here’s what I
I'm having a lot of trouble getting a simple true/false to evaluate properly in
Having trouble getting a simple validation to work in Rails 3, even though the
I'm having some trouble getting NHV to work with Fluent NHibernate. A unit test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.