我的代码调用了一个 C 库函数:
@implementation Store
...
-(void) doWork {
// this is a C function from a library
int data = getData();
...
}
end
我正在对上述函数进行单元测试,我想getData()
在我的测试中模拟 C 函数,这是我的测试用例:
@interface StoreTests : XCTestCase {
int mData;
Store *store;
}
@end
@implementation StoreTests
-(void) setUp {
[super setUp];
mData = 0;
store = [[Store alloc] init];
}
-(void) testDoWork {
// this call will use the mocked getData(), no problem here.
[store doWork];
}
// mocked getData()
int getData() {
mData = 10; // Use of undeclared identifier 'mData', why?
return mData;
}
...
@end
为什么我得到编译器错误:
Use of undeclared identifier 'mData'
在模拟getData()
函数内部?