Testing for Looks

We have a properly connected panel. We can check the widgets'relative locations:

  • label left-of queryField

  • queryField left-of findButton

  • queryField above table

(Would we bother with these tests? Perhaps not, we might just put the panel on-screen and deal with its contents manually. There are times when such tests would definitely be appropriate, such as when we're working against a style guide or when the window format is expected to be stable.)

To make this test run, we need to put our panel in a frame or window. (Components don't have their screen locations set until their containing window is created.)

 public void testRelativePosition() { SearchPanel sp = new SearchPanel(); JFrame display = new JFrame("test"); display.getContentPane().add(sp); ...

Get Extreme Programming Installed 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.