Mocking C++ classes with dependency injection

后端 未结 3 1790
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 04:20

Say you\'re testing class A and it has a dependency injection of B which has a dependency injection of C.
So you mock B

3条回答
  •  [愿得一人]
    2021-01-15 04:34

    If you change the design so that the classes depend on interfaces instead of concrete classes, you get rid of the constructor problems. Besides improving testability, it may also improve reusability and maintainability, at the cost of more code (interfaces).

提交回复
热议问题