39.

GUIs Aren't the Only Liars!

Although Liar Views occur quite often in GUI code, the underlying pattern is actually more general than that. Any time we are displaying data, be it in textual or graphical form, there is the potential for a Liar View.

For example, suppose you are writing a toString() method over a composite data structure and you forget to include the value of one of the fields (or worse, you include another field in its place). If you print these Strings out during, say, debugging, it can send you on a serious wild goose chase. Textual Liar Views can be at least as dangerous as GUI-based Liar Views. Fortunately, they are a lot more straightforward to eliminate through testing.

In fact, toString() test methods are some of the easiest and most fun test methods to write (yes, testing really can be fun). Because String values can be represented literally in Java, test methods on toString() can consist entirely of a series of assertions that check that various calls to toString() match designated String literals.



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