当我想在一个方法中验证模拟对象是否按特定顺序接收某些消息时,我会执行以下操作:
// sut is an instance of the class I am testing and myMock is a mock object injected in sut. // I want to test that myMock sends messageA and then messageB,in that particular order. [[[myMock expect] andDo:^(NSInvocation *invocation) { [[myMock expect] messageB]; }] messageA]; [sut methodToTest]; [myMock verify];
有没有更干净/更好的方法呢?
提前致谢.
解决方法
您可以使用setExpectationOrderMatters
[myMock setExpectationOrderMatters:YES]; [[myMock expect] messageA]; [[myMock expect] messageB]; [sut methodToTest]; [myMock verify];