In the last installment, I talked about the need for some level of automated testing. I'll reiterate that the goal is not to automate 100% of all tests. But, you do want to move in that direction. I've yet to encounter a team that has suffered from having too many tests. (I have worked with teams who have had too many poorly written tests.)
I also introduced the tool FitNesse. In this installment, you'll learn more about what FitNesse is. You'll download the tool, install it, start it up, and begin to learn about its editing capabilities. In the next installment, you'll specify a very simple test and build the support for it, both in an incremental fashion.
FitNesse combines two very powerful tools to create a whole greater than the sum of its parts. FitNesse combines the testing tool Fit (Framework For Integrated Tests) with the power of a wiki. Hopefully, you've had the experience of interacting with a wiki; if not, read this page at Wikipedia.org (which is itself a wiki). Simply put, a wiki is an open, collaborative web site.
The Fit tool, devised by Ward Cunningham, is a table-driven testing framework. It reads HTML data tables that it uses to drive interaction with an underlying application. Fit provides support for verifying application results through these tables. Programmers provide small, intermediary bits of code, known as fixtures, to interpret the tables and directly drive the application being tested.
FitNesse provides support for writing these fixtures in various languages. The primary FitNesse distribution supports Java out of the box. However, other developers have added support for coding fixtures in Ruby, C++, Delphi, Python, Smalltalk, Perl, or .NET. From the FitNesse.org home page, click on the link marked FitServers for more information.
You will download and install FitNesse. FitNesse contains a built-in web server, so you will not need to use Apache or any other web server. FitNesse does require you to have an installed version of Java; the latest version of FitNesse requires Java 5.
Even if you are not using Java 5 for production applications, there's usually no reason you can't install Java 5 just to support FitNesse. Ultimately, you will deploy FitNesse to a production server, one that gets backed up regularly and that is under other typical server controls. Depending on how heavy your testing needs end up, you may need to allocate a separate server to run FitNesse.
If you were unfortunately constrained to using older versions of Java, you could use the previous version of FitNesse. This version is dated July 31, 2005, and will run under Java 1.4.
FitNesse will run with no problems under either Windows or Unix(tm). Your walkthrough of the simple example below presumes you're using Windows.
The first step is to download and install FitNesse, a reasonably painless process. Navigate to FitNesse.org and click the Download link.
Select the latest version of the distribution because you're running Java 5. Currently, this version dates to July 2006. Download the file named fitnesse20060719.zip.
Unzip the file onto your machine, into c:. The path information already includes references to the subdirectory fitnesse. Your entire FitNesse distribution thus ends up in c:\fitnesse. You could have chosen any other location into which to install FitNesse.
You now attempt to start the FitNesse server. To do so, create a shortcut on your desktop. When Windows asks you to "Type the location of the item:," enter:
Name this shortcurt FitNesse. Open the new shortcut to start the FitNesse server. (If you installed under Unix(tm), you would start FitNesse simply by executing the corresponding shell script, run.sh.)
Unfortunately, it turns out you already had something running on the same port that FitNesse defaults to, port 80.
C:\fitnesse>java -cp fitnesse.jar fitnesse.FitNesse FitNesse cannot be started... Port 80 is already in use. Use the -p <port#> command line argument to use a different port. C:\fitnesse>pause Press any key to continue . . .
To fix this problem, edit the properties for the shortcut, and change the Target so that it specifies an available port:
C:\fitnesserun.bat -p 8083
Now when we attempt to start the server, we see:
C:\fitnesse>java -cp fitnesse.jar fitnesse.FitNesse -p 8083 FitNesse (20060719) Started... port: 8083 root page: fitnesse.wiki.FileSystemPage at ./FitNesseRoot logger: none authenticator: fitnesse.authentication. PromiscuousAuthenticator html page factory: fitnesse.html.HtmlPageFactory page version expiration set to 14 days.
Success! This console window will stay around until you close it. You could also press ctrl-c to terminate the Java process.
The console window represents the executing FitNesse server. Normally, you won't see any other messages on this console.
The FitNesse wiki
Open up a web browser and navigate to http://localhost:8083. (You could have omitted the port information had you been able to run FitNesse on port 80.) You see the FitNesse welcome page (see Figure 1).
Figure 1: The FitNesse welcome page.
|If you've used other wikis, such as Confluence, you'll note that FitNesse has a number of things in common with them. However, you'll probably notice that FitNesse is fairly bare-boned compared to other wikis. Its primary focus is on the ability of the wiki to support organization and entry of Fit tests, and not on the robustness of the wiki environment itself. Some of the wiki conventions that FitNesse uses may seem familiar to you; others may seem arbitrarily different. That's the downside of the proliferation of various wiki implementations!|
As a wiki, FitNesse allows you to edit any page. You'll edit the first page and add a link to a new page in which you'll store your first test. Click the button marked Edit Locally, located on the left-hand side of the welcome page.
You see an Edit Page. Within the edit box, move to the end of the existing text, press Enter a couple times, and type in the name of your new page, TestSample. Your screen now looks like Figure 2.
Figure 2: Editing the welcome page.
Press Save, and again you see the welcome page. The welcome page now shows your new text, TestSample, followed by a question mark that your browser recognizes as a page link (see Figure 3).
Figure 3: FitNesse found no page for our wiki word.