Mocking a class vs. mocking its interface

后端 未结 5 604
南方客
南方客 2020-12-25 10:43

For a unit test, I need to mock several dependencies. One of the dependencies is a class which implements an interface:

public class DataAccessImpl implement         


        
5条回答
  •  甜味超标
    2020-12-25 11:46

    If you only use it through interface and it's not a partial mock, there is no difference other than your inner feeling. Mocking the class will also mock non-used public method if the class has them, but that is not a big deal to consider.

提交回复
热议问题