Mocking a class vs. mocking its interface

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

    It depends. If your code depends on the class and not on the interface you must mock the class to write a valid unit test.

提交回复
热议问题