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

jmock 模擬靜態(tài)方法

jmock mocking a static method(jmock 模擬靜態(tài)方法)
本文介紹了jmock 模擬靜態(tài)方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我的代碼中有一個靜態(tài)方法,我想以某種方式模擬.

I have a static method in my code that I would like somehow to mock.

我正在使用 jmock.

I am using jmock.

我想我可以做到這一點的一種方法是在靜態(tài)方法周圍設(shè)置包裝類",然后模擬這個,但我希望有更好的解決方案.

One way I suppose I could do this is to have "wrapper class" around the static method and mock this but I was hoping for a better solution.

我想錯了嗎?

反饋:

我將擁有一個接口和類,其中包含一個調(diào)用靜態(tài)方法的方法.它允許我通過模擬對這個包裝類的調(diào)用來模擬邏輯.(說起來我都覺得很臟:))

I was going to have a interface and class that had a method that just called the static method. It would allow me to mock the logic by just mocking the call to this wrapper class. (I feel dirty even talking about it :) )

推薦答案

我們不支持在 jMock 中模擬靜態(tài)方法,因為它不適合我們的設(shè)計方法.對于可能影響系統(tǒng)狀態(tài)的重要功能,我們不喜歡使用靜態(tài)方法.我們傾向于使用它們只是為了支持 OO 代碼并使其更具可讀性.這就是為什么我們將模擬靜態(tài)方法視為存在問題的暗示.一個例外是它位于第三方庫中,但無論如何我們可能會將其包裝在更面向?qū)ο蟮臇|西中.

We don't support mocking static methods in jMock because it doesn't fit our design approach. We prefer not to use static methods for significant features that can affect the state of the system. We tend to use them just to support the OO code and make it more readable. That's why we view mocking a static methods as a hint that there's a problem. One exception is where it's in a third-party library, but we would probably wrap that in something more object-oriented anyway.

這篇關(guān)于jmock 模擬靜態(tài)方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to mock super reference (on super class)?(如何模擬超級參考(在超級類上)?)
Java mock database connection(Java 模擬數(shù)據(jù)庫連接)
Mockito ClassCastException - A mock cannot be cast(Mockito ClassCastException - 無法投射模擬)
Set value to mocked object but get null(將值設(shè)置為模擬對象但獲取 null)
How to mock DriverManager.getConnection(...)?(如何模擬 DriverManager.getConnection(...)?)
Mockito; verify method was called with list, ignore order of elements in list(模擬;使用列表調(diào)用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 国产精品视频一区二区三 | 亚洲精品久久久一区二区三区 | 国产三级在线观看播放 | avhd101在线成人播放 | 国产人久久人人人人爽 | 成人免费一级 | 1区2区视频 | www.国产| 成人看片在线观看 | 日韩精品免费 | 九九热在线免费视频 | 久久久青草婷婷精品综合日韩 | 欧美jizzhd精品欧美巨大免费 | 色吧综合| 国产精品一区二区三区四区五区 | 免费观看av网站 | 精品欧美一区二区中文字幕视频 | 天天爽综合网 | 日韩一区欧美一区 | 精品免费 | 亚洲不卡在线观看 | 久久精品99 | 免费国产一区二区 | 婷婷精品 | 精品无码三级在线观看视频 | aacc678成免费人电影网站 | 一区二区三区网站 | 久久综合久色欧美综合狠狠 | 欧美一级免费看 | 免费在线观看一区二区 | 狠狠爱视频 | 久久久久久国产精品免费免费男同 | 国产精品日日做人人爱 | 欧美在线高清 | 久久躁日日躁aaaaxxxx | 欧美成人精品一区二区三区 | 欧美日韩一区二区三区不卡视频 | 日韩视频精品在线 | 成人av鲁丝片一区二区小说 | 高清一区二区三区 | 欧美www在线观看 |