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

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

    <small id='0WjWz'></small><noframes id='0WjWz'>

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

      2. 如何使用 PowerMockito 模擬構造函數

        How to mock constructor with PowerMockito(如何使用 PowerMockito 模擬構造函數)
      3. <tfoot id='tea1y'></tfoot>
          <tbody id='tea1y'></tbody>
          <bdo id='tea1y'></bdo><ul id='tea1y'></ul>

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

                  <legend id='tea1y'><style id='tea1y'><dir id='tea1y'><q id='tea1y'></q></dir></style></legend>

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

                  本文介紹了如何使用 PowerMockito 模擬構造函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我第一次嘗試使用 PowerMockito 模擬類構造函數,但它不起作用.我當前的代碼是:

                  I'm trying to mock a class constructor with PowerMockito for first time, but it doesn't work. My current code is:

                  public class Bar {
                      public String getText() {
                          return "Fail";
                      }
                  }
                  
                  public class Foo {
                      public String getValue(){
                          Bar bar= new Bar();
                          return bar.getText();
                      }
                  
                  }
                  
                  @RunWith(PowerMockRunner.class)
                  @PrepareForTest(Bar.class)
                  public class FooTest {
                      private Foo foo;
                      @Mock
                      private Bar mockBar;
                  
                      @Before
                      public void setUp() throws Exception {
                          MockitoAnnotations.initMocks(this);
                          PowerMockito.whenNew(Bar.class).withNoArguments().thenReturn(mockBar);
                          foo= new Foo();
                      }
                  
                      @Test
                      public void testGetValue() throws Exception {
                          when(mockBar.getText()).thenReturn("Success");
                          assertEquals("Success",foo.getValue());
                  
                      }
                  }
                  

                  測試失敗,因為返回值為Fail".我的問題在哪里?

                  The test fails because the returned value is "Fail". Where is my problem?

                  推薦答案

                  好的,找到答案了,需要調用

                  Okey, found the answer, you need to call to

                  @PrepareForTest(Foo.class)
                  

                  而不是

                  @PrepareForTest(Bar.class)
                  

                  這篇關于如何使用 PowerMockito 模擬構造函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)

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

                  • <small id='KQYmw'></small><noframes id='KQYmw'>

                        <tbody id='KQYmw'></tbody>

                          <bdo id='KQYmw'></bdo><ul id='KQYmw'></ul>
                        • <legend id='KQYmw'><style id='KQYmw'><dir id='KQYmw'><q id='KQYmw'></q></dir></style></legend>
                            主站蜘蛛池模板: 国产精品综合色区在线观看 | 97视频在线观看网站 | 国产午夜精品一区二区三区嫩草 | 国内精品久久精品 | 国产一区二区精品在线观看 | 亚洲精品日本 | 欧美精品久久久久久 | 亚州中文| 天天干天天草 | 亚洲综合三区 | 中文字幕在线国产 | 国产一区二区自拍 | 91久久 | 免费成人av网站 | 日本久久网 | 国产91在线播放 | 四虎成人在线播放 | 日韩精品免费在线 | 免费久久久 | 久草新在线 | 国产一区二区三区免费 | 精品自拍视频 | 国产夜恋视频在线观看 | 黄a大片 | 日日夜夜精品免费视频 | 超碰最新在线 | 日韩精品av一区二区三区 | 久久精品影视 | 999免费观看视频 | 黄色片av| 亚洲国产精品99久久久久久久久 | japanhdxxxx裸体| 国产一级黄色网 | 久久精品视频免费观看 | 99久久免费精品国产免费高清 | 欧美成人精品一区二区三区 | 免费观看色 | 国产视频一区二区三区四区五区 | 麻豆精品国产免费 | 成人国产精品久久 | 国产99在线 | 欧美 |