I'm currently foolish enough to try to maintaintain two parallel code bases for a Python desktop application, one using PyGObject introspection for GTK 3 and one using PyGTK for GTK 2. I work mainly on the PyGObject branch and then I port changes over to the PyGTK branch. Due to all the minor differences between these implementations, I often overlook things and cause breakage that I miss and accidentally release, only to be caught by the users.
I'm trying to figure out a good way to design some unittests that would, preferably, be suitable to run on both code bases. It's not an overly complicated program, (it's essentially a library management tool, imagine like iTunes):
- Main Window
|- Toolbar with some buttons (add/edit/remove items, configure the program)
|
|- VPaned
|--- Top HPaned
|------ ListView (listing values by which a library of items can be filtered)
|------ ListView (listing the contents of the library
|--- Bottom HPaned
|------ Image (displaying cover art for the currently selected item in the library)
|------ TextView (displaying formatted text describing the currently selected item)
- Edit dialog
- Configuration dialog
- About dialog
I've tried to separate views from models as much as possible. Each of those items is implemented in its own class (well, in classes which inherit from the GTK classes listed). The ListViews are coupled with other classes which inherit from ListStores. The library itself is handled by a different class. Nonetheless, there are interactions between the widgets that need to be tested. For example, if the user selects a particular item in the filter view, filtering the library, and then selects an item from the filtered results, the text view must display the information for the correct library entry, which is semi-complicated due to translating iters between TreeModelFilter and the original ListStore, etc etc.
So, I ask, what is the recommended way for writing robust unit tests for such a GUI application? I've seen that there are some libraries for this but the main ones for pygtk haven't been updated in years and so they will almost certainly fail with PyGObject introspection. Perhaps I'm not creative enough to figure out a good way to do it using Python's unittest
module, so I'm open to suggestions.
question from:
https://stackoverflow.com/questions/7206807/whats-the-recommended-way-to-unittest-python-gui-applications 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…