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

    <bdo id='tjhHZ'></bdo><ul id='tjhHZ'></ul>
<legend id='tjhHZ'><style id='tjhHZ'><dir id='tjhHZ'><q id='tjhHZ'></q></dir></style></legend>
  • <tfoot id='tjhHZ'></tfoot>

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

    1. <i id='tjhHZ'><tr id='tjhHZ'><dt id='tjhHZ'><q id='tjhHZ'><span id='tjhHZ'><b id='tjhHZ'><form id='tjhHZ'><ins id='tjhHZ'></ins><ul id='tjhHZ'></ul><sub id='tjhHZ'></sub></form><legend id='tjhHZ'></legend><bdo id='tjhHZ'><pre id='tjhHZ'><center id='tjhHZ'></center></pre></bdo></b><th id='tjhHZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tjhHZ'><tfoot id='tjhHZ'></tfoot><dl id='tjhHZ'><fieldset id='tjhHZ'></fieldset></dl></div>
      1. 使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原

        Using PowerMockito.whenNew() is not getting mocked and original method is called(使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原始方法)

        <small id='1NiOn'></small><noframes id='1NiOn'>

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

                  <bdo id='1NiOn'></bdo><ul id='1NiOn'></ul>
                    <tbody id='1NiOn'></tbody>

                • <legend id='1NiOn'><style id='1NiOn'><dir id='1NiOn'><q id='1NiOn'></q></dir></style></legend>
                  本文介紹了使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原始方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個類似下面的代碼:

                  I have a code somewhat like this below:

                  Class A {
                    public boolean myMethod(someargs) {
                      MyQueryClass query = new MyQueryClass();
                      Long id = query.getNextId();
                      // some more code
                    }
                  }
                  Class MyQueryClass     {
                    ....
                    public Long getNextId() {
                      //lot of DB code, execute some DB query
                      return id;
                    }
                  }
                  

                  現在我正在為 A.myMethod(someargs) 編寫測試.我想跳過真正的方法 query.getNextId() 而是返回一個存根值.基本上,我想模擬 MyQueryClass.

                  Now I'am writing a test for A.myMethod(someargs). I want to skip the real method query.getNextId() and instead return a stub value. Basically, I want to mock MyQueryClass.

                  所以在我的測試用例中,我使用了:

                  So in my test case, I have used:

                  MyQueryClass query = PowerMockito.mock(MyQueryClass.class);
                  PowerMockito.whenNew(MyQueryClass.class).withNoArguments().thenReturn(query);
                  when(query.getNextId()).thenReturn(1000000L);
                  
                  boolean b = A.getInstance().myMethod(args);
                  
                  //asserts
                  

                  我在測試類的開頭使用了 @RunWith(PowerMockRunner.class)@PrepareForTest({MyQueryClass.class}).

                  I used @RunWith(PowerMockRunner.class) and @PrepareForTest({MyQueryClass.class}) in the beginning of my test class.

                  但是我調試測試的時候,還是調用了MyQueryClass類的真實方法getNextId().

                  But when I debug the test, it is still calling the real method getNextId() of the MyQueryClass class.

                  我在這里缺少什么?任何人都可以提供幫助,因為我是 Mockito 和 PowerMockito 的新手.

                  What am I missing here? Can anyone help as I am new to Mockito and PowerMockito.

                  推薦答案

                  需要將調用構造函數的類放到@PrepareForTest注解中,而不是正在構造的類 - 請參閱 模擬新對象的構造.

                  You need to put the class where the constructor is called into the @PrepareForTest annotation instead of the class which is being constructed - see Mock construction of new objects.

                  在你的情況下:

                  ? @PrepareForTest(MyQueryClass.class)

                  ? @PrepareForTest(A.class)

                  更籠統的:

                  ? @PrepareForTest(NewInstanceClass.class)

                  ? @PrepareForTest(ClassThatCreatesTheNewInstance.class)

                  這篇關于使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原始方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                  <tfoot id='Kwey9'></tfoot>
                      <tbody id='Kwey9'></tbody>

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

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

                            主站蜘蛛池模板: 91高清视频在线观看 | 亚洲高清一区二区三区 | 欧美日韩综合 | 综合另类| 国产精品精品视频一区二区三区 | 伊人精品在线视频 | 欧美日韩专区 | 日韩精品中文字幕一区二区三区 | 精品在线一区二区 | 欧美精品一区二区在线观看 | 一区二区三 | av激情在线 | 国产精品精品视频一区二区三区 | 亚洲一区二区三区在线 | 国产蜜臀97一区二区三区 | 福利视频一区二区 | 日韩中文字幕视频 | 一区二区三区亚洲 | 一区二区三区高清在线观看 | 伊人久久综合影院 | 久久久蜜桃 | 亚洲欧美日韩电影 | 国产精品久久久久久久久 | 国产精品久久久久久福利一牛影视 | 国产精品久久久久婷婷二区次 | 中文字幕视频在线 | 999热视频| 亚洲网站在线 | 在线观看亚洲专区 | 欧美在线视频二区 | 日韩一区二区三区在线视频 | 成人精品视频在线观看 | 男女午夜激情视频 | 国产高清视频在线观看 | 日韩在线国产 | 91精品国产一区二区三区香蕉 | 国产成人免费视频网站视频社区 | 久久99精品久久久 | 国产高清精品一区二区三区 | 91久久精品国产 | 男女视频91|