java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage(“title”)

后端 未结 5 1869
礼貌的吻别
礼貌的吻别 2021-02-06 22:54

I\'m using EasyMock(version 2.4) and TestNG for writing UnitTest.

I have a following scenario and I cannot change the way class hierarchy is defined.

I\'m testin

5条回答
  •  耶瑟儿~
    2021-02-06 23:43

    You should put your call to replay after the expect calls, and before you use your mock. In this case you should change your test to something like this:

    @Test
    public void testGetDisplayName()
    { 
    
        EasyMock.expect(mockMessageResourse.getMessage("ClassB.title")).andReturn("someTitle");
        EasyMock.replay(mockMessageResourse);
    
        clientMessages = new ClientMessages(mockMessageResourse);
    
        classToTest = new ClassB();
    
        Assert.assertEquals("someTitle" , classToTest.getDisplayName());
    }
    

提交回复
热议问题