After all the preparations its time to write some tests. Imagine a sample-application that contains a page per component from a component set. For our nightly build we want to know whether all pages work. So a first test would be to use the browser and click through all pages. Annoying and always the same. Calls for an automated test, doesn’t it?
@Test public void checkCatalog() {
openAndWaitWebAppRoot();
clickAndWait("link=CATALOG");
assertPageTitleEquals("JSF Components Catalog");
clickAndWait("link=CATALOG");
clickAndWait("link=Layout components");
assertPageTitleEquals("Layout components");
clickAndWait("link=Layout");
assertPageTitleEquals("Layout Component");
clickAndWait("link=Container");
assertPageTitleEquals("Container Configurator");
clickAndWait("link=GroupBox");
assertPageTitleEquals("GroupBox Component");
clickAndWait("link=Tabbed Pane");
assertPageTitleEquals("TabbedPane Component");
clickAndWait("link=MessageArea");
assertPageTitleEquals("MessagesArea Component");
};
Looks easy, doesn’t it? Looks and feels just like the instructions for a human tester. And that’s the writing test should be: simple.
Such a test can also survive a revamp of the menu-structure of the application, as long as the texts of the menu-items remain constant, the testcase, just like the human tester, still find the links to click on. Was very usefull when we did such a refactoring of the sample-application. Every now and then someone from teh team would do the “cvs update”-redeploy-”let the testuite run”-cycle and just report which areas needed some massaging.