<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 劉錚 閱讀(909) 評論(0)  編輯  收藏 所屬分類: Jmock

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導航

    統計

    留言簿(1)

    文章分類(141)

    文章檔案(147)

    搜索

    最新評論

    主站蜘蛛池模板: 国产精品亚洲专区无码WEB| 内射干少妇亚洲69XXX| 亚洲中文字幕无码久久2020 | 亚洲精品mv在线观看| 一级毛片免费毛片一级毛片免费| 亚洲日本va中文字幕久久| 伊人久久大香线蕉免费视频| 亚洲精品国产精品乱码在线观看| 中国一级毛片视频免费看| 国产亚洲人成网站在线观看不卡| 久久午夜夜伦鲁鲁片免费无码| 亚洲av无码一区二区三区不卡| 97精品免费视频| 亚洲xxxx18| 四虎影视精品永久免费网站| 亚洲精品黄色视频在线观看免费资源| 国产亚洲精品高清在线| 国产日韩一区二区三免费高清| 亚洲一区二区在线免费观看| 91精品视频免费| 亚洲爆乳精品无码一区二区| 免费一级毛片不卡在线播放| 久久精品成人免费国产片小草| 久久精品亚洲中文字幕无码网站| h视频在线观看免费网站| 激情内射亚洲一区二区三区爱妻| 啦啦啦www免费视频| 99在线免费观看| 亚洲午夜国产精品| 国产免费卡一卡三卡乱码| 成在人线av无码免费高潮水| 亚洲精品成人久久| 国产在线ts人妖免费视频| 岛国岛国免费V片在线观看 | 2019亚洲午夜无码天堂| 又粗又大又猛又爽免费视频| 日韩精品免费在线视频| 亚洲日韩中文字幕一区| 伊人久久大香线蕉亚洲| 青青视频观看免费99| 亚洲精品狼友在线播放|