如果你必须使用自绘制控件,那么封装应用程序的每种特性很可能是你构建框架的最紧迫且繁重的任务。这可以把每个组装件隐藏到一个函数中。如果要使用一个特性,程序员就调用该特性,而不必考虑组装件的存在。而如果用户界面发生改变,则可以在不影响单个脚本的情况下重建组装件。
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()函数是这种类型函数的一个典型例子。脚本编写者会编写上百个需要打开文件的脚本,但他只会有意识地关注少数脚本中的文件是怎样被打开的。至于其它的,他只是想要文件被迅速可靠地打开,这样,他就能继续测试他真正要测试的东西。添加一个库函数来做这些事情将会节省脚本编写者的时间,并且能改进脚本的可维护性。
文章来源于领测软件测试网 https://www.ltesting.net/