【问题标题】:OCMock link errorOCMock 链接错误
【发布时间】:2014-02-13 08:00:14
【问题描述】:

我正在尝试启动并运行 OSX 的简单 OCMock 测试,但似乎无法正确安装。我相信我已按照说明进行操作,但在链接步骤中测试构建失败。

在 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

但在构建时,我收到以下警告/错误:

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)

我在测试构建阶段将“Link Binary with Library”与 XCTest 和 OCMock 链接在一起。 OCMock.framework 位于基本目录中,该目录也位于框架和标头的搜索路径中。谁能帮忙告诉我我做错了什么?

看起来编译器不知道 STAssertEqualObjects() 是什么(即我没有包含某些内容),因此它不知道要链接什么,因此还有其他 2 个错误。我只是不知道我还需要包括什么。

【问题讨论】:

    标签: xcode ocmock xctest


    【解决方案1】:

    这不是 OCMock 问题。您正在使用 XCUnit(Xcode 5 单元测试框架),但您正在调用 STAssertEqualObjects(来自 OCUnit,Xcode 4 单元测试框架)。只需将其更改为 XCTAssertEqualObjects。

    【讨论】:

    • 太好了,谢谢,我知道我在深夜做了一些愚蠢的事情!
    猜你喜欢
    • 2014-10-24
    • 2023-03-30
    • 2012-12-24
    • 2014-06-23
    • 2010-12-03
    • 2012-02-07
    • 2017-04-03
    • 2012-09-20
    • 2012-02-04
    相关资源
    最近更新 更多