您实际上从未创建要测试的类的对象.此外,您必须expect
先,然后调用方法:
- (void)testMethodInvoked { // first create an object that you want to test: MyClass *object = [[MyClass alloc] init]; // create a partial mock for that object id mock = [OCMockObject partialMockForObject:object]; // tell the mock object what you expect [[mock expect] method]; // call the actual method on the mock object [mock simpleMethod]; // and finally verify [mock verify]; }