문제

I am not sure what i do is correct or not. I want assert times of void method call. My code is below. processor.processInitialDump will invoke service.applyInitialDump. My question is event I give times as 100, Still can pass the test. I want assert the call times. What I can do for this issue?

        Service service = EasyMock.createMock(Service.class);
    service.applyInitialDump(entities);
    EasyMock.expectLastCall().times(100);

    processor.processInitialDump(entities)

BTW: If I the expect is less than call time. expectLastCall work correctly. exception will be throw.

    Service service = EasyMock.createMock(Service.class);
    service.applyInitialDump(entities);
    EasyMock.expectLastCall().times(1);

    processor.processInitialDump(entities)
    processor.processInitialDump(entities)
도움이 되었습니까?

해결책

If I understand correctly, you want your test to fail when you expect the call 100 times, but it only happens once.

From the code you've posted, it looks like you're not calling EasyMock.verify(). This is what makes EasyMock check all the expectations you have set up against what actually happened.

Service service = EasyMock.createMock(Service.class);
service.applyInitialDump(entities);
EasyMock.expectLastCall().times(100);

processor.processInitialDump(entities)
EasyMock.verify(service);

This previously worked because the call had been expected at least once, so the code ran fine. With the verification added, an assertion error will be thrown warning that expected calls didn't happen.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top