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

后端 未结 5 1812
礼貌的吻别
礼貌的吻别 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:55

    You need to call EasyMock.replay(mock) before calling the method under test. After calling the method under test you can call EasyMock.verify(mock) to verify the mock is called.

    Next you need to add another expect call with the "title" argument since you call it twice.

    Code:

    EasyMock.expect(mockMessageResourse.getMessage("title")).andReturn("title");    
    EasyMock.expect(mockMessageResourse.getMessage("ClassB.title")).andReturn("someTitle");
    EasyMock.replay(mockMessageResourse);
    clientMessages = new ClientMessages(mockMessageResourse);
    
    classToTest = new ClassB();
    
    Assert.assertEquals("someTitle" , classToTest.getDisplayName());
    EasyMock.verify(mockMessageResourse);
    

提交回复
热议问题