How to unit test abstract classes: extend with stubs?

后端 未结 14 1741
有刺的猬
有刺的猬 2020-11-27 08:37

I was wondering how to unit test abstract classes, and classes that extend abstract classes.

Should I test the abstract class by extending it, stubbing out the abstr

14条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 09:25

    Write a Mock object and use them just for testing. They usually are very very very minimal (inherit from the abstract class) and not more.Then, in your Unit Test you can call the abstract method you want to test.

    You should test abstract class that contain some logic like all other classes you have.

提交回复
热议问题