久久久久久久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 單獨

        PowerMock + Mockito VS Mockito alone(PowerMock + Mockito VS Mockito 單獨)
        • <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 單獨的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

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

                  到目前為止,我已經找到了這些:

                  So far I've found these:

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

                  它是否添加了其他內容?你能概括幾行嗎?

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

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

                  And do I need to sacrifice something when using PowerMock?

                  推薦答案

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

                  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):

                  允許在沒有依賴注入的情況下進行模擬 - 我不清楚這一點.能詳細點嗎?

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

                  我認為這來自 Motivation wiki 頁面,他們在其中描述了一種將代碼重構為不調用靜態方法使其可測試.對于我認為他們正在處理的具體示例,假設您有這段代碼,并且您想測試模擬靜態方法行為的方法,而不使用 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!
                           ...
                       }
                  }
                  

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

                  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();
                           ...
                       }
                  }
                  

                  我已經將我的方法的行為與靜態調用的行為分開,并且可以在測試時使用 DI 構造函數輕松地注入模擬.當然,使用 powermock 我可以在適當的位置模擬靜態方法,然后使用它運行.

                  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 時我是否需要犧牲一些東西?

                  And do I need to sacrifice something when using PowerMock?

                  物理上不,但我會說哲學上是:).以下是我的觀點,我試圖給出很好的理由,但當然它們是觀點,所以請持保留態度:

                  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 發生的潛在可怕的事情是,為了完成模擬私有和靜態方法的壯舉,它們使用自定義類加載器(在生產運行時不應存在)并更改字節碼你的課.可以說,在大多數情況下,這對于絕大多數類來說都無關緊要,但如果你考慮一下,如果字節碼發生了變化,并且某些副作用不再存在,那么你實際上是在根據你的現有的類.是的,這是一個非常學術的論點.

                  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 的良好綜合集成和更高級別的測試,您可以在一定程度上緩解第一個論點.通過這種方式,即使您的單元測試使用的是 PowerMock,您也可以對對象的行為更有信心.

                  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.

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

                  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 :)

                  這篇關于PowerMock + Mockito VS Mockito 單獨的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                      <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>

                          • 主站蜘蛛池模板: 亚洲av毛片 | 日韩中文一区二区三区 | 91中文视频| 亚洲国产成人在线观看 | 黄色大片免费观看 | 日本精品裸体写真集在线观看 | 91免费电影 | 精品中文字幕一区二区三区 | www.av7788.com| 亚洲二区视频 | 中文在线а√在线8 | 欧美亚洲另类在线 | 青青草一区 | 国产成人精品综合 | av网站在线免费观看 | 亚洲电影一区二区三区 | 国产精品久久久久久久久 | 免费看一区二区三区 | 91精品在线播放 | 亚洲人久久 | 91精品国产综合久久久久久 | 小视频你懂得 | 福利电影在线 | 久久久精品一区二区三区四季av | 亚洲精品三级 | 免费成人高清在线视频 | 日韩中文在线观看 | 国产成人精品999在线观看 | 国产三级| 日韩精品在线看 | 日韩精品一区二区三区中文在线 | 久久国产视频网站 | 中文字幕在线第一页 | 黄色一级视频 | 国产乱码精品一品二品 | 国产一区二区免费 | 国产成人jvid在线播放 | 国产成人精品综合 | 国产精品国产精品国产专区不片 | www.色五月.com | 午夜影院毛片 |