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

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

  1. <small id='vAr2u'></small><noframes id='vAr2u'>

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

      <tfoot id='vAr2u'></tfoot>

    1. Mockito:doAnswer Vs thenReturn

      Mockito : doAnswer Vs thenReturn(Mockito:doAnswer Vs thenReturn)

        <tbody id='KCveJ'></tbody>

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

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

                本文介紹了Mockito:doAnswer Vs thenReturn的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我正在使用 Mockito 進(jìn)行后期單元測(cè)試.我對(duì)何時(shí)使用 doAnswerthenReturn 感到困惑.

                I am using Mockito for service later unit testing. I am confused when to use doAnswer vs thenReturn.

                誰(shuí)能幫我詳細(xì)介紹一下?到目前為止,我已經(jīng)用 thenReturn 進(jìn)行了嘗試.

                Can anyone help me in detail? So far, I have tried it with thenReturn.

                推薦答案

                當(dāng)你在 mock 一個(gè)方法時(shí)知道返回值時(shí),你應(yīng)該使用 thenReturndoReturn稱呼.調(diào)用模擬方法時(shí)會(huì)返回此定義的值.

                You should use thenReturn or doReturn when you know the return value at the time you mock a method call. This defined value is returned when you invoke the mocked method.

                thenReturn(T value) 設(shè)置調(diào)用方法時(shí)要返回的返回值.

                thenReturn(T value) Sets a return value to be returned when the method is called.

                @Test
                public void test_return() throws Exception {
                    Dummy dummy = mock(Dummy.class);
                    int returnValue = 5;
                
                    // choose your preferred way
                    when(dummy.stringLength("dummy")).thenReturn(returnValue);
                    doReturn(returnValue).when(dummy).stringLength("dummy");
                }
                

                Answer 用于在調(diào)用模擬方法時(shí)需要執(zhí)行其他操作,例如當(dāng)需要根據(jù)該方法調(diào)用的參數(shù)計(jì)算返回值時(shí).

                Answer is used when you need to do additional actions when a mocked method is invoked, e.g. when you need to compute the return value based on the parameters of this method call.

                當(dāng)您想使用通用 Answer 存根 void 方法時(shí),請(qǐng)使用 doAnswer().

                Use doAnswer() when you want to stub a void method with generic Answer.

                Answer 指定了一個(gè)執(zhí)行的動(dòng)作和一個(gè)在你與 mock 交互時(shí)返回的返回值.

                Answer specifies an action that is executed and a return value that is returned when you interact with the mock.

                @Test
                public void test_answer() throws Exception {
                    Dummy dummy = mock(Dummy.class);
                    Answer<Integer> answer = new Answer<Integer>() {
                        public Integer answer(InvocationOnMock invocation) throws Throwable {
                            String string = invocation.getArgumentAt(0, String.class);
                            return string.length() * 2;
                        }
                    };
                
                    // choose your preferred way
                    when(dummy.stringLength("dummy")).thenAnswer(answer);
                    doAnswer(answer).when(dummy).stringLength("dummy");
                }
                

                這篇關(guān)于Mockito:doAnswer Vs thenReturn的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

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

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

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

                  <legend id='eAMan'><style id='eAMan'><dir id='eAMan'><q id='eAMan'></q></dir></style></legend>
                        <bdo id='eAMan'></bdo><ul id='eAMan'></ul>

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

                            <tbody id='eAMan'></tbody>
                        • 主站蜘蛛池模板: 国内自拍第一页 | 国产精品欧美一区二区三区不卡 | 中文字幕在线免费观看 | 欧美亚洲国语精品一区二区 | 日本在线观看视频 | 成人天堂噜噜噜 | 91私密视频 | 黄免费在线 | 精品国产91乱码一区二区三区 | 在线免费观看欧美 | 欧美高清性xxxxhd | 久艹网站 | 日韩最新网站 | 天天天天操 | 免费在线视频一区二区 | av激情在线| 久久精品成人 | 国产精品久久片 | 精品国产第一区二区三区 | 国产成人午夜电影网 | 亚洲综合一区二区三区 | 欧美亚洲国产精品 | 少妇无套高潮一二三区 | 亚洲在线高清 | 日本一二三区在线观看 | 国产视频在线观看一区二区三区 | 精品久久久久久久久久久久 | 国产 日韩 欧美 制服 另类 | 精品av| 激情婷婷 | 国产伦精品一区二区三区视频金莲 | 国产激情一区二区三区 | 欧美1区 | 一级做a毛片 | 亚洲一区二区 | 色婷婷亚洲国产女人的天堂 | 亚洲第1页 | 亚洲精选久久 | 国产一区二区三区视频 | 成人免费视频网站在线观看 | 国产精品毛片 |