且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何测试 Tcl/Tk 脚本?

更新时间:1970-01-01 07:58:18

您是专门询问 GUI 测试,还是测试可能有也可能没有 GUI 组件的 Tcl 脚本?

Are you asking specifically about GUI testing, or testing of Tcl scripts that may or may not have a GUI component?

Tcl 带有 tcltest,这对于测试 tcl 脚本.它允许您指定预期值、标记测试仅在某些平台上运行等.

Tcl comes with tcltest, which is quite useful for testing tcl scripts. It lets you specify expected values, flag tests to run only on certain platforms, etc.

要测试 GUI,没有明确的答案.tcl'ers wiki 列出了一些选择.但是,由于 Tcl 是一种脚本语言,您可以轻松编写驱动应用程序的脚本,而无需花哨的工具.我过去所做的是创建诸如press_button"之类的命令(例如:press_buttonOpen"),它会查找具有标签Open"的按钮并调用其回调.有了 Tcl 强大的自省能力,这样的事情就变得很容易了.

To test GUIs there's no clear cut answer. The tcl'ers wiki lists a few choices. However, since Tcl is a scripting language, you can easily write scripts that drive your application without the need for a fancy harness. What I've done in the past is create commands like "press_button" (eg: press_button "Open") which looks for a button that has the label "Open" and invokes its callback. With Tcl's powerful introspection capabilities, things like this are quite easy.

唯一真正的问题是在处理 Windows 上的菜单时,因为这些是使用本机控件实现的,因此与它们交互有点困难.

The only real gotcha is when dealing with menus on Windows, since those are implemented with native controls so it's a bit harder to interact with them.