Alex Rivera | Logout

Mocks and Stubs

Asked 2011-03-02T06:21:45.317
30

I really don't understand what Mocks and Stubs are. I want to know when, why and how we use Mocks in our test cases. I know that there are good frameworks out there for Mocks and Stubs in Ruby on Rails, but without knowing the purpose, I'm reluctant to use them in my app.

Can you please clarify about Mocks and Stubs? Please help.

Edit
Report

1 Answer

16

According to Fowler's article mocks are not stubs, stubs are fake methods independent from outside calls, while mocks are fake objects with pre-programmed reactions to calls.

Mocking is more specific and object-related: if certain parameters are passed, then the object returns certain results. The behavior of an object is imitated or "mocked".

Stubbing is more general and method-related: a stubbed method usually returns always the same result for all parameters. The behavior of a method is frozen, canned or "stubbed".

answered 2013-01-08T18:04:38.560

Your Answer