Mocking a class vs. mocking its interface

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

    You should mock the interface since it will help ensure you are adhering to Liskov Substitution Principal (https://stackoverflow.com/a/56904/3571100).

提交回复
热议问题