13

I'm new to Objective-C and XCode and consider me mentally challenged when discussing compiled languages in general. I have no idea how linkers work and the amount of build settings in every IDE I've had the discomfort of working with simply scares me.

I've started learning ObjC a few days ago and of course I started with a Console Application project. Everything is fine so far, but I have a Ruby / Rails background which made me want to immediately understand how to set up even the most basic TDD environment in XCode5.

I used this official dev doc but it's less than thorough. Taking the trial and error path I simply added a XCTest target to the Project and then added a Test Case Class, testing my Fraction class:

#import <XCTest/XCTest.h>
#import "Fraction.h"

@interface FractionTest : XCTestCase
@end

@implementation FractionTest

- (void)setUp
{
    [super setUp];
}

- (void)tearDown
{
    [super tearDown];
}

- (void)testExample
{
    Fraction *fraction = [Fraction new];
}

@end

When running tests the linker can't find referenced symbols:

enter image description here

I've read about setting up Bundle Loaders and Test Host, but nobody truly explains which target they should be set on. They don't work for me and I'm wondering if such a simple, 3-file large "project" even needs tweaking around the Build Settings.

How can I simply add a Test Class that will test another class with simple assertions?

ellmo
  • 906
  • 7
  • 18

1 Answers1

20

Murphy's Law, of course I found the answer 3 minutes after posting a question that bugged me for hours:

The class I want to test needs to be a member of the test target. After checking the appropriate "Target Membership" for the Fraction class file the errors disappeared.

checking Target Membership for Fraction.m

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
ellmo
  • 906
  • 7
  • 18
  • 3
    I found that this answer helped me so that I didn't need to set the target for each of my files. http://stackoverflow.com/questions/18266649/xctest-build-errors-for-test-target-xcode-5/24390619#24390619 – Mr Rogers Jan 23 '15 at 16:18
  • 1
    @MrRogers life saver, of course symbols are not found if it is hidden... – Jakehao Feb 15 '17 at 06:54