1

我正在尝试为 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)

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

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

4

1 回答 1

2

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

于 2014-01-23T00:19:37.547 回答