[openstack-dev] [nova] Do we have some guidelines for mock, stub, mox when writing unit test?

Rosa, Andrea (HP Cloud Services) andrea.rosa at hp.com
Mon Nov 11 10:27:27 UTC 2013


>Generally mock is supposed to be used over mox now for python 3 support.

That is my understanding too

>As for when to use mock vs stubs, I think you'll get different opinions from
>different people. Stubs are quick and easy and that's what I used early when I
>started contributing to the project, but since then have preferred mox/mock
>since they validate that methods are actually called with specific parameters,
>which can get lost when simply stubbing a method call out. In other words, if
>I'm stubbing a method and doing assertions within it (which you'll usually see),
>if that method is never called (maybe the code changed since the test was
>written), the assertions are lost and the test is essentially broken.
>So I think in general it's best to use mock now unless you have a good reason
>not to.

AFAIK We all agree that for mocking we move to mock but there is no indication about using mock or stub, and that's good to me.
Mocking and stubbing are two different philosophies, I don't think one is better than the other.
I found this article [1] really useful.

[1] http://martinfowler.com/articles/mocksArentStubs.html
Andrea Rosa

More information about the OpenStack-dev mailing list