Chapter 8. Test-driving Swing
Design is not just what it looks like and feels like.
Design is how it works.
Steve Jobs
I have spent most of my programming career developing backend systems. That is, things without a face—a user interface. Such systems are easy to write automated tests for because there’s always some kind of a technical interface to automate. Things aren’t as straightforward when there’s a graphical user interface (GUI) involved, however. With GUIs, it’s not just about the behavior of the widgets laid out on the screen. It’s also about the GUI being easy to learn and use by a human being. It’s also about the GUI looking good.
In this chapter, we will explore test-driven development in the context of Java Swing development. We’ll begin by asking ourselves what to test in a Swing user interface. We’re asking because there are aspects of a GUI that don’t make sense to try to verify with automated tests—and similarly don’t make sense to test-drive into the code base. After we’ve created an understanding of what kind of things we’d like to test for in a GUI, we’ll introduce a couple of design patterns for the presentation layer that help us test-drive our GUI code.