I am trying to use OCMock for testing my app. But I am confused where should we use expect and where to use stub? Can anyone help please?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The basic difference is this: you
expectthings that must happen, andstubthings that might happen.There are 2 ways mock objects fail: either an unexpected/unstubbed method is called, or an expected method is not called.
verifyon your mock (generally at the end of your test), it checks to make sure all of the methods you expected were actually called. If any were not, your test will fail.There are a couple of types of mocks that change this behavior: nice mocks and partial mocks. Nice mocks prevent you having to stub methods–basically they let unexpected invocations occur. Partial mocks are a way of intercepting messages sent to actual objects. Any messages you expect or stub on a partial mock will be sent to the mock object. All other messages are sent to the actual object. For both nice mocks and partial mocks, you won’t get a test failure on unexpected invocations (rule #1 above).