How to mock with static methods?

后端 未结 7 1070
星月不相逢
星月不相逢 2020-12-05 02:31

I\'m new to mock objects, but I understand that I need to have my classes implement interfaces in order to mock them.

The problem I\'m having is that in my data acce

7条回答
  •  暖寄归人
    2020-12-05 02:49

    I found a blog via google with some great examples on how to do this:

    1. Refactor class to be an instance class and implement an interface.

      You have already stated that you don't want to do this.

    2. Use a wrapper instance class with delegates for static classes members

      Doing this you can simulate a static interface via delegates.

    3. Use a wrapper instance class with protected members which call the static class

      This is probably the easiest to mock/manage without refactoring as it can just be inherited from and extended.

提交回复
热议问题