久久久久久久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>
                            主站蜘蛛池模板: 玖玖在线免费视频 | 夜夜爽99久久国产综合精品女不卡 | 精品一区二区三区在线观看国产 | 国产 日韩 欧美 在线 | 亚洲精品久久久久中文字幕二区 | 日韩精品在线观看免费 | 97超在线视频 | 日韩2020狼一二三 | 国产亚洲精品精品国产亚洲综合 | 久久国产精品一区二区三区 | 亚洲国产精品激情在线观看 | 一区二区三区在线 | 欧美综合久久 | 精品一区二区三区四区五区 | 国产wwwcom | 91国内外精品自在线播放 | 毛片日韩 | 久久伊人精品 | 国产精品一区一区三区 | 国产一在线 | 91麻豆精品国产91久久久久久久久 | 欧美激情精品久久久久久变态 | 日本a在线| 99久久国产 | aaaa日韩| 欧美日韩一二三区 | 久久九| 精品欧美一区二区久久久伦 | 亚州春色| 国产精品日韩一区二区 | 精品久久久久久久久久久久久久 | 日韩欧美在线播放 | 国产精品免费看 | 日本三级在线视频 | 国产成人一区二区 | 国产天天操 | 在线色网站 | 一本一道久久a久久精品蜜桃 | 中文字幕蜜臀 | 久草视频网站 | 国产精品高清在线 |