Unit testing factory methods which have a concrete class as a return type

前端 未结 5 445
醉梦人生
醉梦人生 2020-12-15 03:35

So I have a factory class and I\'m trying to work out what the unit tests should do. From this question I could verify that the interface returned is of a particular concret

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 03:51

    You can always check stuff with reflection. There is no need to expose something just for unit tests. I find it quite rare that I need to reach in with reflection and it may be a sign of bad design.

    Looking at your sample code, yes the Assert not null seems redundant, depending on the way you designed your factory, some will return null objects from the factory as opposed to exceptioning out.

提交回复
热议问题