如果你必須使用自繪制控件,那么封裝應用程序的每種特性很可能是你構建框架的最緊迫且繁重的任務。這可以把每個組裝件隱藏到一個函數中。如果要使用一個特性,程序員就調用該特性,而不必考慮組裝件的存在。而如果用戶界面發生改變,則可以在不影響單個腳本的情況下重建組裝件。
b. Define commands or features of the tool’s programming language.
b. 定義工具的程序語言的命令或特性
The automation tool comes with a scripting language. You might find it surprisingly handy to add a layer of indirection by putting a wrapper around each command. A wrapper is a routine that is created around another function. It is very simple, probably doing nothing more than calling the wrapped function. You can modify a wrapper to add or replace functionality, to avoid a bug in the test tool, or to take advantage of an update to the scripting language.
自動化工具都有一個腳本語言。你會發現,通過包裹每個命令來增加一個間接層的做法非常便捷。所謂包裹,就是一個被創建在另一個函數周圍的例程。這非常的簡單,很可能僅僅只需調用打包函數即可。而且,你可以通過修改包裹來增加或替換函數,以避免測試工具中產生bug,或利用更新的腳本語言。
Tom Arnold [9] gives the example of wMenuSelect, a Visual Test function that selects a menu. He writes a wrapper function, SelMenu() that simply calls wMenuSelect. This provides flexibility. For example, you can modify SelMenu() by adding a logging function or an error handler or a call to a memory monitor or whatever you want. When you do this, every script gains this new capability without the need for additional coding. This can be very useful for stress testing, test execution analysis, bug analysis and reporting and debugging purposes.
Tom Arnold給出了wMenuSelect的例子,它是一個選擇菜單的可視化測試函數。他編寫了一個打包函數:可簡單調用wMenuSelect的SelMenu()。這種做法具有靈活性。舉個例子,你可以修改SelMenu(),比如,添加日志功能、添加錯誤處理機制、添加調用內存監視器命令,或其他任何你想添加的東西。當這樣做時,每個腳本都能得到這個新的功能,而并不需要額外編寫代碼。這種做法在強力測試、測試執行分析、bug分析報告與調試目標方面都非常有用。
LAWST participants who had used this approach said that it had repeatedly paid for itself.
用過這種方法的LAWST成員說,該方法已經反復收到成效。
c. Define small, conceptually unified tasks that are done frequently.
c. 定義經常使用的概念統一的小任務
The openfile() function is an example of this type of function. The scriptwriter will write hundreds of scripts that require the opening of a file, but will only consciously care about how the file is being opened in a few of those scripts. For the rest, she just wants the file opened in a fast, reliable way so that she can get on with the real goal of her test. Adding a library function to do this will save the scriptwriter time, and improve the maintainability of the scripts.
openfile()函數是這種類型函數的一個典型例子。腳本編寫者會編寫上百個需要打開文件的腳本,但他只會有意識地關注少數腳本中的文件是怎樣被打開的。至于其它的,他只是想要文件被迅速可靠地打開,這樣,他就能繼續測試他真正要測試的東西。添加一個庫函數來做這些事情將會節省腳本編寫者的時間,并且能改進腳本的可維護性。
文章來源于領測軟件測試網 http://www.kjueaiud.com/