EasyMock: Void Methods

后端 未结 5 714
北荒
北荒 2020-12-04 08:58

I have a method that returns void in a class that is a dependency of the class I want to test.

This class is huge and I\'m only using this single method from it. I n

5条回答
  •  萌比男神i
    2020-12-04 09:55

    If you just call the void method for each time you're expecting it to be invoked and then invoke EasyMock.expectLastCall() prior to calling replay(), Easymock will “remember” each invocation.

    So I don’t think you need to explicitly call expect() (other than lastCall) since you’re not expecting anything from a void method, except its invocation.

    Thanks Chris!

    “Fun With EasyMock” by fellow StackOverflow user Burt Beckwith is a good blog post that provides more detail. Notable excerpt:

    Basically the flow that I tend to use is:

    1. Create a mock
    2. call expect(mock.[method call]).andReturn([result]) for each expected call
    3. call mock.[method call], then EasyMock.expectLastCall() for each expected void call
    4. call replay(mock) to switch from “record” mode to “playback” mode
    5. inject the mock as needed
    6. call the test method
    7. call verify(mock) to assure that all expected calls happened

提交回复
热议问题