【问题标题】:What's the best way to set an Eclipse breakpoint on a EasyMock expect call?在 EasyMock 期望调用上设置 Eclipse 断点的最佳方法是什么?
【发布时间】:2010-10-21 17:55:43
【问题描述】:

我有类似的代码

ClockService mockClockService = createMock( ClockService.class );

Long timeFirstNodeCreated = new Date().getTime();
expect( mockClockService.getNow() ).andReturn( timeFirstNodeCreated ) ;        

Long timeFirstNodeDeleted = new Date().getTime();
expect( mockClockService.getNow() ).andReturn( timeFirstNodeDeleted ) ;

我希望 Eclipse 在调用 mockClockService.getNow() 时暂停程序。但是,由于 ClockService 是一个接口,我不能在 ClockService.getNow() 上设置断点,而且由于 mockClockService 是一个 EasyMock 代理,我也不能在期望行上设置断点。

【问题讨论】:

    标签: eclipse debugging expect easymock breakpoints


    【解决方案1】:

    我想您可以使用 andAnswer(或 andDelegateTo)方法来响应 getNow() 调用;您将编写 IAnswer(或 ClockService)的实现并在您的实现中设置断点。如:

    expect( mockClockService.getNow() ).andAnswer( new IAnswer<Long>() {
       public Long answer() throws Throwable {
          return WHATEVER_YOUR_WANT;  // Put your breakpoint on this line
       }
    });
    

    应该这样做。

    但也许您想更多地说明您为什么要这样做?这表明您可能有设计问题...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 2013-05-22
      • 2011-03-01
      相关资源
      最近更新 更多