问题描述
I read through TDD: Only mock types you own entry by Mark Needham and would like to know if this is best practice or not?
Please note that he is not against mocking, but against mocking directly - he does say that writing a wrapper and mocking that is fine.
Depends whether you mean mock or mock™…
Given you are just using a mock framework (as eg Mockito) to create stubs, then creating stubs of types you don't own is totally okay and reasonable.
If however, you are using a mock framework (as eg Mockito) to create mock™ objects, then you best literally follow the advice of the mock™ evangelists. Personally I lost touch to that movement, so I cannot tell you whether Mark Needham's advice is to be considered kosher or not.
Irony aside, what Mark writes about mocking of EntityManagers
in Hibernate sounds reasonable by itself. But I doubt that we can generalize a rule like "never mock types you don't own" from that specific case. Sometime it might make sense, sometimes not.
这篇关于你应该只模拟你拥有的类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!