我正在尝试为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&amp; OCMock处于测试构建阶段。 OCMock.framework位于基本目录中,该目录也位于框架和标头的搜索路径中。谁能协助告诉我我做错了什么?
看起来好像编译器不知道STAssertEqualObjects()是什么(即我没有包含某些东西),因此它不知道要链接什么,因此其他2个错误。我只是不知道还需要包括什么。
答案 0 :(得分:2)
这不是OCMock问题。您正在使用XCUnit(Xcode 5单元测试框架),但您正在调用STAssertEqualObjects
(来自OCUnit,Xcode 4单元测试框架)。只需将其更改为XCTAssertEqualObjects
。