How to test a Tcl/Tk script?

扶醉桌前 提交于 2020-01-11 03:13:19

问题


We have a few Tcl/Tk scripts (because a GUI we use can incorporate macros only in Tcl). I have just modified one of these, and want to test it.

We make use of Test::More for testing Perl modules, and have made a little use of Selenium for web pages, but we have never had any kind of automatic test rig for our Tcl/Tk scripts.

I've tried searching, but because Tcl's original purpose was for testing, I've found it difficult to sort out if there are any hits about testing Tcl/Tk itself.

Does anybody know of a program which will let me run a Tcl/Tk script, and test its user interaction as well as its eventual operation?


回答1:


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

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.

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.

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.



来源:https://stackoverflow.com/questions/3771683/how-to-test-a-tcl-tk-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!