<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jmock測試的準備工作

    private Mockery context = new JUnit4Mockery() {
            {
                setImposteriser(ClassImposteriser.INSTANCE);
            }
        };

    注意這里的setImposteriser(ClassImposteriser.INSTANCE);
    因為默認的JUnit4Mockery的Imposteriser是JavaReflectionImposteriser,他是針對接口進行mock的,如果要針對class進行mock,必須setImposteriser(ClassImposteriser.INSTANCE);
    這樣之后context便可以對class進行mock了


    官方的文檔:

    Mocking Classes with jMock and the ClassImposteriser

    Because it uses Java's standard reflection capability, the default configuration of the jMock framework can only mock interfaces, not classes. (Actually, we consider that to be a good thing because it encourages the design to focus on communication between objects rather than static classification or data storage). However, the ClassImposteriser extension class uses the CGLIB 2.11 and Objenesis2 libraries to create mock objects of classes as well as interfaces. This is useful when working with legacy code to tease apart dependencies between tightly coupled classes.

    To use the ClassImposteriser:

    1. Add jmock-legacy-2.1.0-RCn.jar, cglib-nodep-2.1_3.jar and objenesis-1.0.jar to your CLASSPATH.
    2. Plug the ClassImposteriser into the Mockery of your test class:

      Raw

      import org.jmock.Mockery;
      import org.jmock.Expectations;
      import org.jmock.lib.legacy.ClassImposteriser;

      public class ConcreteClassTest extends TestCase {
      private Mockery context = new Mockery() {{
      setImposteriser(ClassImposteriser.INSTANCE);
      }};

      ...
      }

      JUnit 3

      import org.jmock.Expectations;
      import org.jmock.integration.junit3.MockObjectTestCase;
      import org.jmock.lib.legacy.ClassImposteriser;

      public class ConcreteClassTest extends MockObjectTestCase {
      {
      setImposteriser(ClassImposteriser.INSTANCE);
      }

      ...
      }

      JUnit 4

      import org.jmock.Mockery;
      import org.jmock.Expectations;
      import org.jmock.integration.junit4.JUnit4Mockery;
      import org.jmock.lib.legacy.ClassImposteriser;

      @RunWith(JMock.class)
      public class ConcreteClassTest {
      private Mockery context = new JUnit4Mockery() {{
      setImposteriser(ClassImposteriser.INSTANCE);
      }};

      ...
      }
    3. Your tests can now create mocks of abstract or even concrete classes:
      Graphics g = context.mock(java.awt.Graphics.class);

    posted on 2007-12-05 10:54 劉錚 閱讀(905) 評論(0)  編輯  收藏 所屬分類: Jmock

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    留言簿(1)

    文章分類(141)

    文章檔案(147)

    搜索

    最新評論

    主站蜘蛛池模板: 亚洲国产精品久久久天堂| 亚洲午夜电影在线观看| 亚洲一区二区三区免费观看| 免费人成动漫在线播放r18| 视频一区在线免费观看| 国拍在线精品视频免费观看| 2020年亚洲天天爽天天噜| 亚洲精品国产手机| 91亚洲国产成人久久精品网址| 99在线免费视频| 久久亚洲精品无码观看不卡| 黄床大片免费30分钟国产精品| 国产亚洲色视频在线| 久久免费视频99| 免费激情视频网站| 亚洲国产成人a精品不卡在线| 亚洲精品无码久久久久去q| 亚洲AV无码乱码在线观看代蜜桃| 18国产精品白浆在线观看免费| 亚洲精品第一国产综合精品99| 一级毛片在线播放免费| 一个人免费观看视频www| 亚洲色少妇熟女11p| 日本免费人成网ww555在线| 亚洲国产精品日韩在线| 暖暖日本免费中文字幕| 亚洲第一香蕉视频| 手机看片久久国产免费| 色在线亚洲视频www| 国产免费啪嗒啪嗒视频看看| 久久国产乱子伦精品免费午夜| 亚洲成AV人片天堂网无码| 最近中文字幕无吗免费高清| 亚洲精品白色在线发布| 免费看大黄高清网站视频在线| 一级毛片免费播放试看60分钟| 久久精品亚洲视频| 青青草国产免费久久久下载| a级黄色毛片免费播放视频| 亚洲avav天堂av在线网爱情| 亚洲男人av香蕉爽爽爽爽|