How do mock frameworks work?

前端 未结 4 957
再見小時候
再見小時候 2021-01-04 18:18

If I was to write a mocking library, how would this work (in other words, how do \"they work?)?

One of the things which I wonder is that you are always setting expec

4条回答
  •  暖寄归人
    2021-01-04 18:53

    Yes, it will always return true. Mock objects should be used when the class under test requires another class implementation that you don't want to involve in the test run. This is most useful when it's a class that uses interfaces with multiple implementations, or there are complex/expensive/external services that you don't want to set up.

    In the above code, you're mocking the class that you're "testing".

    Another way of thinking about it is that the mock behaviours you record are black-box (implementation) assertions, where Assert.* are white-box (api) assertions.

提交回复
热议问题