50.

What We've Learned

In this chapter on the Liar View bug pattern, we've learned the following:

  • Most GUIs are built on the Model-View-Controller architecture (MVC), which decouples the model from the view.

  • In an MVC architecture, the internal state of the program is kept in the controller connects these two components together.

  • The decoupled aspect of the GUI architecture means that program test results may differ from runtime behavior.

  • A key to diagnosing this bug is to realize that part of the bad behavior can be in the test itself.

  • The most common place for a bug to occur in a test on a GUI program is in the last step: checking that the state of the program was modified as intended. It can be difficult to verify that a state change in the model is reflected appropriately in the view. Assertions in the test method may succeed even though the view is not updated because the assertions only check for changes in the model.

  • One way to prevent this bug pattern is to check the model through the view.

  • Another way to check the view directly is to use the Java Robot class to automate the physical manipulation of a GUI with the mouse and keyboard. This class also lets you take snapshots of subsections of the screen, allowing you to build tests based on the actual physical layout of a GUI view. However, I recommend using the Robot class only as a testing tool for mature GUIs whose views won't change very often.

  • Use Recorders to test the model (and the view) in isolation.

  • Beware of methods in view objects that trampoline calls back to the model. Doing so can introduce Liar Views. JTables, in particular, contain many such methods.

  • Any time we are displaying data, be it in textual or graphical form, there is the potential for a Liar View.

  • Perpetual refactoring is only practical when there is a strong network of unit tests in place, to prevent perpetual code breakage along with it.

Bit by bit we're working our way through solutions to the most common (and most frustrating) bugs, but we still have a lot of ground to cover. In Chapter 13, we'll tackle a more subversive bug pattern: Saboteur Data, data that is perfectly benign—until it's accessed!



Bug Patterns in Java
Bug Patterns In Java
ISBN: 1590590619
EAN: 2147483647
Year: N/A
Pages: 95
Authors: Eric Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net