【发布时间】:2015-12-11 11:09:50
【问题描述】:
我正在编写一个类的单元测试。这个类(假设是子类)是从其他类(即父类)继承的。在子类的一个方法中,它使用 [super someMethod] 调用其父类的方法。我已经部分模拟了子类并想存根父类方法。因此,当调用 [super someMethod] 而不是转到父类方法时,它将转到我的测试类中的存根方法。任何人都可以帮助我吗?
这是我正在为其编写测试用例的类的公共接口。它是从设备管理器继承的。
@interface BTDeviceManager : DeviceManager<MGBTDeviceDelegate>
+ (id) sharedInstance;
- (void)startConnection;
@property (nonatomic,weak) id <MGBTDeviceDelegate> deviceDelegate;
@end
设备管理器有一个方法叫做:
- (void) startDiscoveryWithServices:(NSArray *)serviceUUIDs
我正在尝试对这个从 BTDeviceManager 调用的方法存根。
我的测试班是这样的:
@implementation BTDeviceManagerTest
- (void)setUp {
[super setUp];
deviceManager = [[BTDeviceManager alloc]init];
deviceManager.deviceManagerDelegate = self;
deviceManagerMock = OCMPartialMock(deviceManager);
}
- (void)testStartConnection
{
NSArray *testShaverServiceUUIDs = @[@"C222"];
//This is how i am trying to stub the superclass method
OCMStub([deviceManagerMock startDiscoveryWithServices:testShaverServiceUUIDs]).andCall(self, @selector(handleStartDiscoveryWithServices:));
[deviceManagerMock startConnection];
}
@end
【问题讨论】:
标签: ios objective-c mocking ocmock stubbing