Chapter 5. Unit Testing GUI Applications
Unit tests for ordinary software objects are easy to conceptualize. Objects have behaviors that are represented by methods and attributes. Tests elicit these behaviors to validate them. Unit testing of GUI objects is a different and more complex problem.
GUI objects are the graphical elements that make up the user interface of most software applications. They include windows, buttons, frames, text boxes, menus, and many other types of widgets. Even very simple applications often contain dozens of them. GUI objects usually have many behaviors, such as responding to mouse movements or clicks, displaying values, being shown, hidden, highlighted, disabled, and so forth. You usually build GUI applications from standard toolkits, such as Java’s Swing, wxWindows for C++, or .NET’s WinForms. Most of the GUI object behavior is provided, and you simply assemble the standard objects and write code only to implement the custom behaviors of their application.
Doing test-first development of such GUI code is challenging. It may not be hard to test the process of simply creating and displaying an object, such as a window. As soon as it becomes necessary to test responses to user actions such as keyboard entries or mouse clicks, the tests can become very complicated. It often takes a good deal of messy code to create and test a single GUI element as a standalone unit. Sometimes it is not even possible to design an automated test that verifies a specific ...
Get Unit Test Frameworks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.