Checking the results of a Factory in a unit test

前端 未结 5 1223
-上瘾入骨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:11

    if (myNewObject instanceof CorrectClass)
    {
        /* pass test */
    }
    

    update:

    Don't know why this got marked down, so I'll expand it a bit...

    public void doTest()
    {
        MyInterface inst = MyFactory.createAppropriateObject();
        if (! inst instanceof ExpectedConcreteClass)
        {
            /* FAIL */
        }
    }
    

提交回复
热议问题