EasyMock 3.0, mocking class throws java.lang.IllegalStateException: no last call on a mock available

前端 未结 3 1827
自闭症患者
自闭症患者 2020-12-09 16:02

Running the following unit test throws the exception: java.lang.IllegalStateException: no last call on a mock available


import org.easymock.*;
import org.ju         


        
3条回答
  •  遥遥无期
    2020-12-09 16:29

    Your test method looks fine, except that you have not prepared the mock object you have created. This has to be done using

    EasyMock.replay(mockObject1, mockObject2, ...);
    

    This will prepare the mocked object so that it is the one which will be used on running your JUnit. No issues with your dependencies as well.

    Also, you don't seem to be calling the actual method which you are unit-testing here. Usually, the way to write a test method would be to write a JUnit method, using mocking libs (such as EasyMock and PowerMock) ONLY when there are external objects beyond the test method context, and then replaying all the mocked objects (which prepares the mocks to substitute for the real business objects in the test). After that, you call the actual method you are trying to test, and validate the functionality using org.junit.Assert.assertXXX() methods.

提交回复
热议问题