What are the real-world pros and cons of each of the major mocking frameworks?

前端 未结 7 508
梦如初夏
梦如初夏 2020-12-04 17:20

see also \"What should I consider when choosing a mocking framework for .Net\"

I\'m trying to decide on a mocking framework to use o

7条回答
  •  天涯浪人
    2020-12-04 17:43

    We've used Rhino Mocks for more than a year now. PRO:

    • easy to create the mocks
    • can mock public and internal methods
    • can mock interfaces or classes
    • can create partial mocks (mocking only specific methods from a class)

    AGAINST:

    • methods must be at least internal and virtual (can mess with your architecture)
    • difficult to use for property-by-property asserts, especially for collections of objects that get created inside the test scope - the constraints syntax gets complicated
    • you have to be careful when the recording stops and the playback begins
    • careful about what calls are being mocked (like a property call that you didn't see or a method that wasn't virtual) - the errors you may get are not very helpful

    As a general note, we've found that using the mocking frameworks promotes "white box" testing (especially for unit tests). We ended up with tests that validated HOW things were done, not WHAT they were doing. They were useless for refactorings and we had to rewrite most of them.

提交回复
热议问题