Mocking a class vs. mocking its interface

后端 未结 5 602
南方客
南方客 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:30

    In most cases technically there is no difference and you may mock as class so an interface. Conceptually it is better to use interfaces because of better abstraction.

提交回复
热议问题