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

如何對 jquery 插件中的私有方法進行單元測試?

how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
本文介紹了如何對 jquery 插件中的私有方法進行單元測試?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

也許這是一個 JQuery 新手問題,但是:

Perhaps this is a bit of a novice JQuery question but:

  • 適當的 jquery 插件寫在閉包內
  • 因此只有定義插件接口的方法可以從外部訪問
  • 有時(或多次)可能需要輔助方法,將其作為插件接口的一部分公開是沒有意義的(例如,因為它們會改變內部狀態).
  • 如何進行單元測試?

比如看blockUI插件,怎么能方法安裝、刪除、重置是否經過單元測試?

For example, looking at blockUI plugin, how can methods install, remove, reset get unit-tested?

為了畫一個平行線,在 Java 中我會:

To draw a parallel, in Java I would:

  1. 創建一個僅包含公共方法的 BlockUI 接口(根據定義)
  2. 創建一個實現上述接口的 BlockUIImpl 類.此類將包含可能是公共的或(包)受保護的 install()、remove()、reset() 方法

因此,我將對 Impl 進行單元測試,但客戶端程序員將通過 BlockUI 接口與插件進行交互.

So, I would unit-test the Impl but client programmers would interact with the plugin via BlockUI interface.

推薦答案

這同樣適用于任何其他語言和測試私有方法:要測試私有方法,您應該通過公共接口來使用它們.換句話說,通過調用您的公共方法,私有方法在進程中得到測試,因為公共方法依賴于私有方法.

The same applies here as with any other language and testing privates: To test private methods, you should exercise them via the public interface. In other words, by calling your public methods, the private methods get tested in the process because the public methods rely on the privates.

通常私有方法不會與公共接口分開測試 - 重點在于它們是實現細節,測試通常不應該對實現的細節了解太多.

Generally private methods are not tested separately from the public interface - the entire point is that they are implementation details, and tests should generally not know too much about the specifics of the implementation.

這篇關于如何對 jquery 插件中的私有方法進行單元測試?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
Is it possible to force jQuery.jScrollPane to always show a vertical scroll-bar?(是否可以強制 jQuery.jScrollPane 始終顯示垂直滾動條?)
主站蜘蛛池模板: 精品久久精品 | 日韩中文字幕第一页 | 国内精品久久久久 | 精品久久久久一区 | 97av视频| 在线日韩不卡 | 黄色欧美 | 97视频在线看 | 免费在线观看91 | 狠狠的干 | 人人干在线视频 | 国产亚洲欧美在线 | 毛片黄| 欧美日韩专区 | 成人在线观看中文字幕 | 一区二区三区视频在线 | 亚欧性视频 | 欧美日韩国产在线观看 | 涩爱av一区二区三区 | 91视频三区| 欧美日韩一区二区三区不卡视频 | 亚洲男人天堂网 | 欧美亚洲国语精品一区二区 | 日本在线网址 | 亚洲一区不卡在线 | 国产日韩欧美一区二区 | 成年视频在线观看福利资源 | 国产探花在线精品一区二区 | 久久一区二区三区四区五区 | 国产成人jvid在线播放 | 久久成人免费视频 | 亚洲午夜av久久乱码 | 免费在线观看h片 | 国产精品久久久亚洲 | 国产精品第2页 | 欧美二区三区 | 成人福利网站 | 岛国午夜 | 91精品在线看 | av网址在线 | 日本天堂视频在线观看 |