Checking the results of a Factory in a unit test

前端 未结 5 1228
-上瘾入骨i
-上瘾入骨i 2020-12-15 05:35

I have developed some classes with similar behavior, they all implement the same interface. I implemented a factory that creates the appropriate object and returns the inte

5条回答
  •  渐次进展
    2020-12-15 06:18

    Since I don't know how your factory method looks like, all I can advise right now is to

    1. Check to see the object is the correct concrete implementation you were looking for:

      IMyInterface fromFactory = factory.create(...);  
      Assert.assertTrue(fromFactory instanceof MyInterfaceImpl1);
      
    2. You can check if the factory setup the concrete instances with valid instance variables.

提交回复
热议问题