• 测试技术
  • 博客
  • 视频
  • 开源
  • 论坛
  • 沙龙
  • 下载
  • 杂志
  • 招聘

字号: | 推荐给好友 上一篇 | 下一篇

Mock Objects:缺点和用例

发布: 2008-6-13 18:23 | 作者: 不详 | 来源: 领测软件测试网编辑整理 | 查看: 163次 | 进入领测软件测试网论坛讨论

领测软件测试网

jLL6M:a7~ d Z H      /**    * Encapsulates the common pattern followed when using EasyMock.    * <ol>    * <li>Set up expectations on the mock objects</li>    * <li>Set the state of the mock controls to "replay"</li>    * <li>Execute the code to test</li>    * <li>Verify that the expectations were met</li>    * </ol>    * Steps 2 and 4 are considered invariant behavior while steps 1 and 3 should be implemented by subclasses of this template.    */   public final void run() {     setUp();     expectations();     for (Object mock : mocks) replay(mock);     codeToTest();     for (Object mock : mocks) verify(mock);   }     /** Sets the expectations on the mock objects. */   protected abstract void expectations();     /** Executes the code that is under test. */   protected abstract void codeToTest();     /** Sets up the test fixture if necessary. */   protected void setUp() {} } 软件测试技术网)YSFu0R