How to unit test abstract classes: extend with stubs?

后端 未结 14 1740
有刺的猬
有刺的猬 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:16

    one way is to write an abstract test case that corresponds to your abstract class, then write concrete test cases that subclass your abstract test case. do this for each concrete subclass of your original abstract class (i.e. your test case hierarchy mirrors your class hierarchy). see Test an interface in the junit recipies book: http://safari.informit.com/9781932394238/ch02lev1sec6.

    also see Testcase Superclass in xUnit patterns: http://xunitpatterns.com/Testcase%20Superclass.html

提交回复
热议问题