Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS UnitTests: Can't link to symbols in my Application target. Whats wrong?
    text
    copied!<p>SETUP:<br> Xcode 4.5.2 (4G2008a)<br> OS X 10.7.5</p> <hr> <p>I have an Xcode project with a normal iOS <code>Application</code> target. I am trying to add an <code>ApplicationTests</code> unit test bundle (NOT a <code>LogicTests</code> bundle) as <a href="http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/UnitTesting/02-Setting_Up_Unit_Tests_in_a_Project/setting_up.html#//apple_ref/doc/uid/TP40002143-CH3-SW1" rel="nofollow">described by Apple's documentation</a>.</p> <p>I have carefully followed the steps provided in the documentation, and re-checked everything a few times. However, I cannot build the ApplicationTests target... it fails with a Linker error when trying to link to one of my Appliation's classes. It seems as if setting the <code>Bundle Loader</code> build setting of the <code>ApplicationTests</code> target didn't work. But AFAICT, I have set this up correctly, as described by Apple's docs.</p> <hr> <p>MY STEPS TO REPRO:</p> <ol> <li>Follow <a href="http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/UnitTesting/02-Setting_Up_Unit_Tests_in_a_Project/setting_up.html#//apple_ref/doc/uid/TP40002143-CH3-SW1" rel="nofollow">Apple's documentation for setting up an ApplicationTests bundle</a>.</li> <li>Write a unit test method in the <code>ApplicationTests</code> target which imports and exercises a class from the <code>Application</code> target (e.g. <code>MyAppClass</code>).</li> <li>Select the Application Target in the Scheme popup, and iPhone 6.0 simulator in the run destination popup</li> <li><code>Product</code> > <code>Test</code></li> </ol> <p>EXPECTED:<br> Simulator should launch and my <code>ApplicationTests</code> should run.</p> <p>ACTUAL:<br> The <code>ApplicationTests</code> target fails to build with following error:</p> <pre><code>Undefined symbols for architecture i386: "_OBJC_CLASS_$_MyAppClass", referenced from: objc-class-ref in ApplicationTests.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) </code></pre> <hr> <p>If I remove references to <code>MyAppClass</code> in the unit test, the <code>ApplicationTests</code> bundle will build and run successfully.</p> <p>Again, it seems like I haven't setup the <code>Bundle Loader</code> build setting properly in my <code>ApplicationTests</code> target, but I've re-checked, and I seem to have followed Apple's instructions correctly.</p> <p>What could I have done wrong to make my <code>ApplicationTests</code> target not be able to link to symbols in my <code>Application</code> target?</p> <hr> <p><strong>Update</strong>: I have also tried to create new dummy projects from scratch with an <code>Application</code> and <code>ApplicationTests</code> targets. In the dummy projects, I add a <code>MyAppClass</code> class to the <code>Application</code> target, and am able to link to it and successfully run unit tests which use the <code>MyAppClass</code> in the dummy <code>ApplicationTests</code> target.</p> <p>So Application Tests in my dummy projects work. But they don't work in my real project. I've compared the Targets in the dummy and real projects and cannot find a significant difference which would cause this problem for my real project only.</p> <p>My real project is quite old (but also very complex, so it would be very difficult to start over). I wonder if the old-ness of the project is preventing this relatively new feature from working?</p> <p>It still seems to me like I have a build settings problem in one of the targets in my real project. But I can't find it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload