我的代码调用C库函数:在我的情况下使用未声明的标识符错误
@implementation Store
...
-(void) doWork {
// this is a C function from a library
int data = getData();
...
}
end
我的单元测试上述功能,我想嘲笑C函数getData()
在我的测试,这里是我的测试案例:
@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()
功能?
' - (INT)的getData(){' – ozgur
不,如果我变成' - (INT)的getData(){',我得到奇怪的编译器错误'期待的功能body',我当前的代码工作得很好,模拟的功能由生产代码调用。只有当我将模拟函数中的mData赋值时才会出现问题。再次,它是一个C函数。 –
我明白你的意思了,我试了一下,然后我写了上面的评论。 –