I'd like to be able to access from within python, the complete list of visual
elements in a gui, along with the values of their attributes. The goal is to
use pyUnit to test aspects of the gui as it is being developed. I'm
envisioning unit tests like:
o assert: there is a main application window (might as well start testing
early)
o assert: the main application window's title is "My title"
o assert: the main application window has a menu bar
<snip>
o assert: the vertical centers of the lblLocation, cboLocation and btnOk
widgets on the file dialog are aligned
o assert: the value of the cboLocation widget text on the file dialog is empty
and so on.
There are several approaches to getting at the widget's for this purpose and
I'd like to get some comments on them before I choose one.
First way: keep only python objects needed to access a hierarchy of
wxWindows widgets through wxWindows function calls, letting wxWindows give
access through hierarchies of widgets. For the most part I would just build
the gui the regular way using wxPython and just keep python references to a
few top level widgets.
Second way: Maintain my own hierarchy of python widgets that mirrors the
ones in wx. This seems a bit cumbersome, but it keeps the test code python
based. It also might allow other widget sets to be used with the same test
code.
Third way: Instantiate all widgets as python objects within the application
with methods to access the underlying wxPython or other widget class
attributes. This seems to me to be the most robust way from a development,
coding and testing standpoint, but I'm wondering if performance might suffer.
- Pat Callahan
Acton Ma
"Everything should be as simple as possible, but not simpler" - A Einstein.
P.S. I've read some discussion on a Wiki about GUI's not being unit
testable. I believe that they are testable. What do you think?