O'Reilly logo

Extreme Programming Installed by Chet Hendrickson, Ann Anderson, Ron Jeffries

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

0, 1, and Many

We'll build tests for the 0, 1, and many cases:

public void test0() {
  SearchPanel sp = new SearchPanel();
  sp.setSearcher (new TestSearcher());
  sp.queryField.setText("0");
  sp.findButton.doClick();
  assert("Empty result", sp.resultTable.getRowCount() == 0);

}

At last, we're using the GUI: setting text fields, clicking buttons, and so on.

We run the test, and it passes! This means we already have a working solution if our searcher always returns zero items.

We move on:

 public void test1() { SearchPanel sp = new SearchPanel(); sp.setSearcher (new TestSearcher()); sp.queryField.setText("1"); sp.findButton.doClick(); assert("1-row result", sp.resultTable.getRowCount() == 1); assertEquals( "a0", sp.resultTable.getValueAt(0,0).toString()); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required