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

  • <tfoot id='aBcGt'></tfoot>
    • <bdo id='aBcGt'></bdo><ul id='aBcGt'></ul>

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

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

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

        Java 使用 Mockito 驗(yàn)證 void 方法調(diào)用 n 次

        Java verify void method calls n times with Mockito(Java 使用 Mockito 驗(yàn)證 void 方法調(diào)用 n 次)
          <bdo id='4deil'></bdo><ul id='4deil'></ul>
                <legend id='4deil'><style id='4deil'><dir id='4deil'><q id='4deil'></q></dir></style></legend>

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

                  <small id='4deil'></small><noframes id='4deil'>

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

                  問(wèn)題描述

                  我正在嘗試驗(yàn)證是否在 DAO 內(nèi)部調(diào)用了一個(gè) (void) 方法 - 我正在使用一個(gè)提交點(diǎn),該提交點(diǎn)發(fā)送到該點(diǎn)的結(jié)果列表,重置列表并繼續(xù).假設(shè)我在列表中有 4 件事并且我的提交點(diǎn)為 1,我希望發(fā)送"方法被調(diào)用 4 次.我可以通過(guò)編寫(xiě)驗(yàn)證該方法是否被調(diào)用一次

                  I'm trying to verify that a (void) method is being called inside of a DAO - I'm using a commit point that sends a list of results up to that point, resets the list and continues. Say I have 4 things in the list and I have a commit point of 1, I would expect the "send" method to be called 4 times. I can verify that the method gets called once by writing

                  Mockito.verify(mock).send()

                  它通過(guò)了.. 但我想驗(yàn)證它被調(diào)用的次數(shù).我會(huì)認(rèn)為

                  it passes.. but I want to verify the number of times it was called. I would think that

                  Mockito.verify(mock.send(), times(4))

                  就足夠了,但它說(shuō)參數(shù)不正確,無(wú)法驗(yàn)證.

                  would be sufficient, but it says the parameters are not correct for verify.

                  順便說(shuō)一句,如果我將 Mockito.verify(mock).send() 更改為 Mockito.verify(mock.send())Mockito.verify((mock).send()) 我得到同樣的錯(cuò)誤.對(duì)此有何想法?

                  Incidentally, if I change Mockito.verify(mock).send() to Mockito.verify(mock.send()) or Mockito.verify((mock).send()) I get the same error. Thoughts on this?

                  推薦答案

                  必要的方法是Mockito#verify:

                  public static <T> T verify(T mock,
                                             VerificationMode mode)
                  

                  mock 是您的模擬對(duì)象,mode 是描述應(yīng)該如何驗(yàn)證模擬的 VerificationMode.可能的模式是:

                  mock is your mocked object and mode is the VerificationMode that describes how the mock should be verified. Possible modes are:

                  verify(mock, times(5)).someMethod("was called five times");
                  verify(mock, never()).someMethod("was never called");
                  verify(mock, atLeastOnce()).someMethod("was called at least once");
                  verify(mock, atLeast(2)).someMethod("was called at least twice");
                  verify(mock, atMost(3)).someMethod("was called at most 3 times");
                  verify(mock, atLeast(0)).someMethod("was called any number of times"); // useful with captors
                  verify(mock, only()).someMethod("no other method has been called on the mock");
                  

                  您將需要來(lái)自 的這些靜態(tài)導(dǎo)入Mockito 類,以便使用 verify 方法和這些驗(yàn)證模式:

                  You'll need these static imports from the Mockito class in order to use the verify method and these verification modes:

                  import static org.mockito.Mockito.atLeast;
                  import static org.mockito.Mockito.atLeastOnce;
                  import static org.mockito.Mockito.atMost;
                  import static org.mockito.Mockito.never;
                  import static org.mockito.Mockito.only;
                  import static org.mockito.Mockito.times;
                  import static org.mockito.Mockito.verify;
                  

                  所以在你的情況下,正確的語(yǔ)法是:

                  So in your case the correct syntax will be:

                  Mockito.verify(mock, times(4)).send()
                  

                  這將驗(yàn)證方法 send 在模擬對(duì)象上被調(diào)用 4 次.如果調(diào)用少于或多于 4 次,它將失敗.

                  This verifies that the method send was called 4 times on the mocked object. It will fail if it was called less or more than 4 times.

                  如果你只是想檢查,如果方法被調(diào)用過(guò)一次,那么你不需要傳遞一個(gè)VerificationMode.一個(gè)簡(jiǎn)單的

                  If you just want to check, if the method has been called once, then you don't need to pass a VerificationMode. A simple

                  verify(mock).someMethod("was called once");
                  

                  就夠了.它在內(nèi)部使用 verify(mock, ti??mes(1)).someMethod("was called once");.

                  would be enough. It internally uses verify(mock, times(1)).someMethod("was called once");.

                  可以在同一個(gè) mock 上進(jìn)行多個(gè)驗(yàn)證調(diào)用以實(shí)現(xiàn)介于"驗(yàn)證.Mockito 不支持這樣的 verify(mock, between(4,6)).someMethod("was called between 4 and 6 times");,但我們可以寫(xiě)

                  It is possible to have multiple verification calls on the same mock to achieve a "between" verification. Mockito doesn't support something like this verify(mock, between(4,6)).someMethod("was called between 4 and 6 times");, but we can write

                  verify(mock, atLeast(4)).someMethod("was called at least four times ...");
                  verify(mock, atMost(6)).someMethod("... and not more than six times");
                  

                  相反,獲得相同的行為.邊界被包含,因此當(dāng)方法被調(diào)用 4、5 或 6 次時(shí),測(cè)試用例為綠色.

                  instead, to get the same behaviour. The bounds are included, so the test case is green when the method was called 4, 5 or 6 times.

                  這篇關(guān)于Java 使用 Mockito 驗(yàn)證 void 方法調(diào)用 n 次的文章就介紹到這了,希望我們推薦的答案對(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?)

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

                          <tbody id='dIETF'></tbody>
                            <bdo id='dIETF'></bdo><ul id='dIETF'></ul>

                            主站蜘蛛池模板: 欧美一区二区 | 精品欧美一区二区三区久久久 | 91免费看片| 久久午夜精品福利一区二区 | 日韩av免费看| 国产在线观看不卡一区二区三区 | 久久久久久国产一区二区三区 | 综合九九 | 97视频在线观看网站 | 久久久久久免费看 | 91性高湖久久久久久久久_久久99 | www.888www看片| 全免一级毛片 | 亚洲成人综合社区 | 国产精品99久久久久久久vr | 日韩精品一区二区三区视频播放 | 久久久国产一区 | aaaaaa大片免费看最大的 | 巨大荫蒂视频欧美另类大 | 超碰在线人人 | 一区二区三区欧美 | 精品网站999| 一本一道久久a久久精品综合 | 91视频在线观看免费 | 久久高清 | 国产精品不卡一区二区三区 | 一区二区三区视频在线免费观看 | 涩涩视频在线看 | 一级毛片在线播放 | 国产成人精品在线播放 | 黄免费看 | 日本午夜网站 | 成人超碰在线 | 久久久久久高潮国产精品视 | 欧美videosex性极品hd | 天堂一区二区三区 | 日韩成人在线播放 | 中文字幕97 | 欧美久操网 | 国产精品一区二区三区四区 | 国产乱肥老妇国产一区二 |