久久久久久久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 始終顯示垂直滾動條?)
主站蜘蛛池模板: 欧美精品福利视频 | 国产精品99久久久久久宅男 | 国产精品久久av | 久久久高清 | av天天澡天天爽天天av | 亚洲一区二区在线视频 | 涩涩视频网站在线观看 | 国产精品99久久久久久久久 | 91短视频网址 | 91在线视频观看免费 | 午夜av在线 | 在线观看av网站 | 成人网在线观看 | 日批免费看| 精品视频一区二区三区 | 99精品网| 日本大片在线播放 | 天堂视频一区 | 精品国产伦一区二区三区观看说明 | 日韩中文字幕一区 | 国产精品1区 | 国产亚洲精品久久久优势 | 美人の美乳で授乳プレイ | 日韩欧美中文在线 | 成人一级片在线观看 | 中文字幕日韩欧美一区二区三区 | 中文精品视频 | 黄色一级大片在线观看 | 色综合九九 | 少妇一级淫片免费播放 | 中文字幕一区二区三区在线观看 | 欧美在线a| 国产精品资源在线观看 | 国产黄色在线观看 | 免费亚洲成人 | 国产高清视频一区 | 91精品国产色综合久久 | 精品国产一区二区在线 | 18gay男同69亚洲网站 | 天天精品在线 | 日本一区二区三区在线观看 |