我是 OCMock 的新手,我需要一些帮助才能开始。我有一个 UIScrollView,它在平移时会触发一个事件处理程序,然后它会做一些事情。我想测试一下。这是我制作对象的方法
id gestureMock = [OCMockObject partialMockForObject:[UIPanGestureRecognizer new]];
现在如何设置平移规范?
初始化平移后,如何“调用”平移?
我是 OCMock 的新手,我需要一些帮助才能开始。我有一个 UIScrollView,它在平移时会触发一个事件处理程序,然后它会做一些事情。我想测试一下。这是我制作对象的方法
id gestureMock = [OCMockObject partialMockForObject:[UIPanGestureRecognizer new]];
现在如何设置平移规范?
初始化平移后,如何“调用”平移?
如果您正在测试您的代码是否正确响应 ,请UIPanGestureRecognizer
围绕手势识别器的目标方法编写测试。
// If you have this...
UIPanGestureRecognizer *pgr = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
[self.scrollView addGestureRecognizer:pgr];
// With this...
- (void)didPan:(UIPanGestureRecognizer *)pgr
{
switch (pgr.state):
{
case UIGestureRecognizerStateEnded:
[self doSomething];
break;
default:
}
}
// Then you could do this
id gestureMock = [OCMockObject mockForClass:[UIPanGestureRecognizer class]];
[[[gestureMock stub] andReturn:UIPanGestureRecognizerStateEnded] state];
id objectUnderTest = [OCMockObject partialMockForObject:[MyClass new]];
[[objectUnderTest expect] doSomething];
// Make the call
[objectUnderTest didPan:gestureMock];
[objectUnderTest verify];