How do mock frameworks work?

前端 未结 4 930
再見小時候
再見小時候 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 19:10

    You have the right idea. You will often find that they have a couple of modes of operation. If you're worried about your method not getting called or it not getting called in the right order there is quite often a 'strict' mode that causes the mock framework to throw an exception if the method isn't called by the end of the test, or is called with the wrong parameters etc.

    Most of the frameworks have thought of those sorts of issues so you just need to find out how to configure it for your scenario.

提交回复
热议问题