Frage

I'm trying to get a simple OCMock test for OSX up and running, but can't seem to get the install right. I believe I've followed the instructions, but the test build is failing at the link step.

Within fooTests.m:

#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>

@interface fooTests : XCTestCase

@end

@implementation fooTests

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testOCMockPass {
    id mock = [OCMockObject mockForClass:NSString.class];
    [[[mock stub] andReturn:@"mocktest"] lowercaseString];

    NSString *returnValue = [mock lowercaseString];
    STAssertEqualObjects(@"mocktest", returnValue, @"Should have returned the expected string.");
}

@end

But on build, I get the following warnings/errors:

fooTests.m:56:5: Implicit declaration of function 'STAssertEqualObjects' is invalid in C99

Undefined symbols for architecture x86_64:
  "_STAssertEqualObjects", referenced from:
      -[fooTests testOCMockPass] in fooTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've got "Link Binary with Library" linking with XCTest & OCMock in the test build phase. OCMock.framework is in the base directory, which is also in the search path for frameworks and for headers. Can anyone assist in telling me what I'm doing wrong please?

It looks as though the compiler doesn't know what STAssertEqualObjects() is (i.e. I haven't included something) and hence it doesn't know what to link with, hence the other 2 errors. I just don't know what else I need to include.

War es hilfreich?

Lösung

This is not an OCMock problem. You are using XCUnit (the Xcode 5 unit testing framework), but you are calling STAssertEqualObjects (from OCUnit, the Xcode 4 unit testing framework). Simply change that to XCTAssertEqualObjects.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top