久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='IUsqD'></tfoot>

      • <bdo id='IUsqD'></bdo><ul id='IUsqD'></ul>

        <small id='IUsqD'></small><noframes id='IUsqD'>

      1. <legend id='IUsqD'><style id='IUsqD'><dir id='IUsqD'><q id='IUsqD'></q></dir></style></legend>
        <i id='IUsqD'><tr id='IUsqD'><dt id='IUsqD'><q id='IUsqD'><span id='IUsqD'><b id='IUsqD'><form id='IUsqD'><ins id='IUsqD'></ins><ul id='IUsqD'></ul><sub id='IUsqD'></sub></form><legend id='IUsqD'></legend><bdo id='IUsqD'><pre id='IUsqD'><center id='IUsqD'></center></pre></bdo></b><th id='IUsqD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IUsqD'><tfoot id='IUsqD'></tfoot><dl id='IUsqD'><fieldset id='IUsqD'></fieldset></dl></div>

        Mockito:試圖監視方法正在調用原始方法

        Mockito: Trying to spy on method is calling the original method(Mockito:試圖監視方法正在調用原始方法)
      2. <legend id='DTPdM'><style id='DTPdM'><dir id='DTPdM'><q id='DTPdM'></q></dir></style></legend>
        • <bdo id='DTPdM'></bdo><ul id='DTPdM'></ul>
          <tfoot id='DTPdM'></tfoot>

              <i id='DTPdM'><tr id='DTPdM'><dt id='DTPdM'><q id='DTPdM'><span id='DTPdM'><b id='DTPdM'><form id='DTPdM'><ins id='DTPdM'></ins><ul id='DTPdM'></ul><sub id='DTPdM'></sub></form><legend id='DTPdM'></legend><bdo id='DTPdM'><pre id='DTPdM'><center id='DTPdM'></center></pre></bdo></b><th id='DTPdM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='DTPdM'><tfoot id='DTPdM'></tfoot><dl id='DTPdM'><fieldset id='DTPdM'></fieldset></dl></div>

                <small id='DTPdM'></small><noframes id='DTPdM'>

                    <tbody id='DTPdM'></tbody>

                1. 本文介紹了Mockito:試圖監視方法正在調用原始方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 Mockito 1.9.0.我想在 JUnit 測試中模擬一個類的單個方法的行為,所以我有

                  I'm using Mockito 1.9.0. I want mock the behaviour for a single method of a class in a JUnit test, so I have

                  final MyClass myClassSpy = Mockito.spy(myInstance);
                  Mockito.when(myClassSpy.method1()).thenReturn(myResults);
                  

                  問題是,在第二行中,myClassSpy.method1() 實際上被調用,導致異常.我使用模擬的唯一原因是以后,每當調用 myClassSpy.method1() 時,不會調用真正的方法,而 myResults 對象將是回.

                  The problem is, in the second line, myClassSpy.method1() is actually getting called, resulting in an exception. The only reason I'm using mocks is so that later, whenever myClassSpy.method1() is called, the real method won't be called and the myResults object will be returned.

                  MyClass 是一個接口,而 myInstance 是一個實現,如果這很重要的話.

                  MyClass is an interface and myInstance is an implementation of that, if that matters.

                  我需要做些什么來糾正這種間諜行為?

                  What do I need to do to correct this spying behaviour?

                  推薦答案

                  讓我引用 官方文檔:

                  有時不可能使用 when(Object) 來存根間諜.示例:

                  Important gotcha on spying real objects!

                  Sometimes it's impossible to use when(Object) for stubbing spies. Example:

                  List list = new LinkedList();
                  List spy = spy(list);
                  
                  // Impossible: real method is called so spy.get(0) throws IndexOutOfBoundsException (the list is yet empty)
                  when(spy.get(0)).thenReturn("foo");
                  
                  // You have to use doReturn() for stubbing
                  doReturn("foo").when(spy).get(0);
                  

                  在你的情況下,它是這樣的:

                  In your case it goes something like:

                  doReturn(resultsIWant).when(myClassSpy).method1();
                  

                  這篇關于Mockito:試圖監視方法正在調用原始方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

                    • <bdo id='6WnZ2'></bdo><ul id='6WnZ2'></ul>

                        <legend id='6WnZ2'><style id='6WnZ2'><dir id='6WnZ2'><q id='6WnZ2'></q></dir></style></legend>

                        <small id='6WnZ2'></small><noframes id='6WnZ2'>

                            <tbody id='6WnZ2'></tbody>
                        1. <i id='6WnZ2'><tr id='6WnZ2'><dt id='6WnZ2'><q id='6WnZ2'><span id='6WnZ2'><b id='6WnZ2'><form id='6WnZ2'><ins id='6WnZ2'></ins><ul id='6WnZ2'></ul><sub id='6WnZ2'></sub></form><legend id='6WnZ2'></legend><bdo id='6WnZ2'><pre id='6WnZ2'><center id='6WnZ2'></center></pre></bdo></b><th id='6WnZ2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6WnZ2'><tfoot id='6WnZ2'></tfoot><dl id='6WnZ2'><fieldset id='6WnZ2'></fieldset></dl></div>
                            <tfoot id='6WnZ2'></tfoot>
                            主站蜘蛛池模板: 欧美日韩在线精品 | 自拍偷拍视频网 | 一级黄a| 久久久亚洲一区 | 精品一区二区三区视频在线观看 | 成人a在线| 一区精品国产欧美在线 | 成人在线视频一区 | 一级a性色生活片久久毛片波多野 | 婷婷在线免费 | 一区二区三区av | 视频在线一区二区 | 色爽女 | 伊人啪啪网 | 成人激情视频在线观看 | 欧美福利视频 | 伊人网在线综合 | 激情视频网站 | 精品一区二区三区入口 | 欧美激情精品久久久久久变态 | 99精品欧美一区二区三区综合在线 | 亚洲视频在线观看 | 亚洲一区二区三区在线 | 国产精品伦一区二区三级视频 | 一区二区在线免费观看 | 欧美日韩精品一区二区三区四区 | 国产一区二区三区在线看 | 国产成人99av超碰超爽 | 亚洲一区综合 | 国产一级片在线播放 | 国产日韩精品在线 | 九九国产 | 亚洲精品一区在线观看 | 国产成人精品一区二 | 中国免费黄色片 | 国产精品国产精品国产专区不卡 | 精品久久久网站 | 国产99久久久国产精品下药 | 婷婷中文在线 | 激情欧美一区二区三区 | 精品伦精品一区二区三区视频 |