当我想验证一种方法中模拟对象是否正在以特定顺序接收某些消息时,我会执行以下操作:

// 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];

关于ios - OCMock-验证方法调用的顺序。还有其他办法吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16196571/

10-10 16:45