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

      <tfoot id='WmkXx'></tfoot>

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

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

      1. PowerMock + Mockito VS Mockito 單獨(dú)

        PowerMock + Mockito VS Mockito alone(PowerMock + Mockito VS Mockito 單獨(dú))
        • <bdo id='zd4re'></bdo><ul id='zd4re'></ul>

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

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

                  本文介紹了PowerMock + Mockito VS Mockito 單獨(dú)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  誰能總結(jié)一下,在 Mockito 之上添加 PowerMock 的具體功能是什么?

                  Can anyone please summarize, what exactly features gives you adding PowerMock on top of the Mockito?

                  到目前為止,我已經(jīng)找到了這些:

                  So far I've found these:

                  • 模擬靜態(tài)、最終和私有方法
                  • 移除靜態(tài)初始化器
                  • 允許在沒有依賴注入的情況下進(jìn)行模擬 - 我不清楚這一點(diǎn).你能詳細(xì)說明一下嗎?

                  它是否添加了其他內(nèi)容?你能概括幾行嗎?

                  Does it add anything else? Can you please sum up in several lines?

                  在使用 PowerMock 時(shí)我是否需要犧牲一些東西?

                  And do I need to sacrifice something when using PowerMock?

                  推薦答案

                  我不知道其他好處,但我想解決您的 2 個(gè)子問題(這對(duì)于評(píng)論來說太長了):

                  I don't know of other benefits offhand, but I want to address 2 of your sub-questions (and this is way too long for a comment):

                  允許在沒有依賴注入的情況下進(jìn)行模擬 - 我不清楚這一點(diǎn).能詳細(xì)點(diǎn)嗎?

                  allow mocking without dependency injection - this one isn't clear to me. Can you elaborate?

                  我認(rèn)為這來自 Motivation wiki 頁面,他們?cè)谄渲忻枋隽艘环N將代碼重構(gòu)為不調(diào)用靜態(tài)方法使其可測試.對(duì)于我認(rèn)為他們正在處理的具體示例,假設(shè)您有這段代碼,并且您想測試模擬靜態(tài)方法行為的方法,而不使用 powermock:

                  I think this came from the Motivation wiki page where they describe a way of refactoring code to not invoke static methods to make it testable. For a concrete example of what I think they're getting at, let's say you have this code and you want to test the method mocking the behaviour of the static method, without using powermock:

                  public class MyClass {
                       public void doGetString() {
                           ...
                           OtherClass.getString(); //It's complex and scary and needs mocking!
                           ...
                       }
                  }
                  

                  一種解決方案是將靜態(tài)調(diào)用拉到它自己的對(duì)象中,然后注入一個(gè)可以在測試時(shí)模擬的對(duì)象.例如,在不使用其他框架的情況下,這可能如下所示:

                  One solution, would be to pull the static invocation into its own object, then inject an object that can be mocked come test time. For example, without using other frameworks, this could look like:

                  public class MyClass {
                       public static class StringGetter {
                           public getString() {
                               return OtherClass.getString();                 
                           }
                       }
                  
                       private final StringGetter getter;
                  
                       //Existing Constructor
                       public MyClass() {
                           this(new StringGetter());
                       }
                  
                       //DI Constructor
                       MyClass(StringGetter getter) {
                           this.getter = getter;
                       }
                  
                       public void doGetString() {
                           ...
                           getter.getString();
                           ...
                       }
                  }
                  

                  我已經(jīng)將我的方法的行為與靜態(tài)調(diào)用的行為分開,并且可以在測試時(shí)使用 DI 構(gòu)造函數(shù)輕松地注入模擬.當(dāng)然,使用 powermock 我可以在適當(dāng)?shù)奈恢媚M靜態(tài)方法,然后使用它運(yùn)行.

                  I've seperated the behaviour of my method from the behaviour of the static invocation, and can use the DI constructor to inject mocks easily at test time. Of course with powermock I could just mock the static method in place, and run with it.

                  在使用 PowerMock 時(shí)我是否需要犧牲一些東西?

                  And do I need to sacrifice something when using PowerMock?

                  物理上不,但我會(huì)說哲學(xué)上是:).以下是我的觀點(diǎn),我試圖給出很好的理由,但當(dāng)然它們是觀點(diǎn),所以請(qǐng)持保留態(tài)度:

                  Physically no, but I'd say philosophically yes :). The below are my opinions, and I try to give good reasons behind them, but of course they are opinions so take them with a grain of salt:

                  PowerMock 發(fā)生的潛在可怕的事情是,為了完成模擬私有和靜態(tài)方法的壯舉,它們使用自定義類加載器(在生產(chǎn)運(yùn)行時(shí)不應(yīng)存在)并更改字節(jié)碼你的課.可以說,在大多數(shù)情況下,這對(duì)于絕大多數(shù)類來說都無關(guān)緊要,但如果你考慮一下,如果字節(jié)碼發(fā)生了變化,并且某些副作用不再存在,那么你實(shí)際上是在根據(jù)你的現(xiàn)有的類.是的,這是一個(gè)非常學(xué)術(shù)的論點(diǎn).

                  The potentially scary thing that is happening with PowerMock is that in order to accomplish the feats of mocking private and static methods, they are using a custom class loader (which shouldn't be present at runtime in production) and changing the bytecode of your classes. Arguably, this should not matter with the vast majority of classes most of the time, but if you think about it, if the bytecode has changed, and certain side effects are no longer present, you're effectively testing different Classes albiet based upon your existing Classes. Yes this is a very academic argument.

                  通過不使用 PowerMock 的良好綜合集成和更高級(jí)別的測試,您可以在一定程度上緩解第一個(gè)論點(diǎn).通過這種方式,即使您的單元測試使用的是 PowerMock,您也可以對(duì)對(duì)象的行為更有信心.

                  You can somewhat mitigate this first argument by having good comprehensive integration and higher level tests that don't use PowerMock. In this way you can be more confident in the behaviours of your objects even if your unit tests are using PowerMock.

                  我反對(duì) PowerMock 的另一個(gè)論點(diǎn)是,它幾乎太容易成為拐杖.我同意 PowerMock 可以幫助測試使用遺留代碼和您無法控制的其他代碼的代碼.但是我認(rèn)為,當(dāng)您可以控制需要模擬的類時(shí),您應(yīng)該避免使用它.如果您編寫一個(gè)帶有私有方法或靜態(tài)方法的類,您需要顯式地模擬以測試其他方法,我的直覺會(huì)說這個(gè)方法可能做得太多,應(yīng)該重構(gòu)和分解.PowerMock 已經(jīng)在項(xiàng)目中可用,您可能會(huì)想模擬它并繼續(xù)前進(jìn),這將減輕應(yīng)該鼓勵(lì)您重構(gòu)相同的痛苦.是的,有時(shí)由于各種技術(shù)和非技術(shù)限制,這是不可能的,但解決痛點(diǎn)而不是避免它們是件好事:)

                  The other argument I have against PowerMock, is that it could almost too easily become a crutch. I agree that PowerMock can help with testing code that uses legacy code and other code that you do not have control over. However I would argue that when you have control over the classes that you need to mock, you should avoid its use. If you write a class with a private method or static method that you need to explicitly mock in order to test other methods, my gut instinct would say that this method may be doing too much and should be refactored and broken up. Having PowerMock already available in a project, you may be tempted to just mock it and move on, which would mitigate the pain that should encourage you to refactor the same. Yes there are sometimes due to various technical and non-technical constraints this is not possible, but it's good to solve pain points instead of avoid them :)

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

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

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(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?)
                      <tbody id='qPfap'></tbody>

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

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

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

                          • 主站蜘蛛池模板: 中文日韩字幕 | 精品粉嫩aⅴ一区二区三区四区 | 国产成人福利在线观看 | 玖玖综合在线 | 在线āv视频 | 欧美亚洲综合久久 | 中文日韩在线 | 欧美精品久久久久久久久久 | 国产精品区二区三区日本 | 视频一区二区中文字幕 | 毛片一区二区 | 久久精品国产一区二区三区不卡 | 欧美啪啪 | 超碰成人免费 | 日本三级电影免费观看 | aaa综合国产 | 欧美a级成人淫片免费看 | 久久免费香蕉视频 | 精品久久久久香蕉网 | 国产精品一区二区视频 | 成人在线观看网站 | 久久黄色精品视频 | .国产精品成人自产拍在线观看6 | 手机av在线 | 欧美日韩一区二区在线观看 | 久久综合成人精品亚洲另类欧美 | 成人性生交大免费 | 最新日韩在线 | 日韩精品一区二区三区在线播放 | 一区二区三区av夏目彩春 | 免费能直接在线观看黄的视频 | 久久国产精品一区二区三区 | 欧美自拍另类 | 黄色一级毛片 | 久久久婷 | 精品视频在线观看 | 91一区二区 | 中国美女一级黄色片 | 欧美激情综合色综合啪啪五月 | 精品一区二区三区在线观看 | 91视频一区|