Tuesday, October 21, 2008

Automated Acceptance Testing Frame work (FitNesse):

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.

Getting Started

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.

Let's Go!

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:

c:\fitnesse\run.bat

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  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).



Click here for a larger image.

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.



Click here for a larger image.

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.

Your new page name, TestSample, follows the wiki convention of page naming. The basic rule is that a wiki page name starts with an uppercase letter, and at least one other letter in the word is also uppercase. However, the page name cannot contain two consecutive uppercase letters. Wiki page names can contain numbers. There are likely more rules; the easiest way to figure them out is to just try various name combinations. You'll refer to a valid wiki page name as a wiki word.

The question mark next to the text TestSample says two things: First, TestSample is a valid wiki word. Second, FitNesse can't find a page named TestSample. That's because you haven't created it yet.

To create the page, click the question mark next to TestSample. This opens a new page with no content, offering a fresh and clean edit box for typing. Enter some simple text (see Figure 4) and press Save. Your resulting page appears in Figure 5.



Click here for a larger image.

Figure 4: Editing a new page.



Click here for a larger image.

Figure 5: The new page

Note a couple things about your new page. The left-hand buttons now contain a Test button. Also, the address for the page, http://localhost:8083/TestSample, is basically the server plus your page name.

Click the FitNesse gauge icon in the upper-left corner of your new TestSample page. You also might have clicked the link marked .FrontPage at the bottom of the page. Either click takes you back to the FitNesse welcome page, which you'll also refer to as the FrontPage. Your browser now recognizes the TestSample wiki word as an existing page (see Figure 6). You can click on the link to return to the TestSample page.

Figure 6: FitNesse found your new page.

At this point, you have enough information create and edit new pages. You're going to go off now and experiment with FitNesse, adding a few new pages. You're also going to read the FitNesse user's guide because you found a link to it from the FrontPage. In the user's guide, you expect to find information on how to spruce up the look and feel of your pages. You'll make sure you're comfortable with a few basics, such as making text bold or italic.

At this point, if you're not already using a wiki, you now have a tool that can provide your team with great value. You can use the wiki as a very dynamic place to add content. You can post ad hoc project documents to the wiki, use it as a repository for frequently asked questions, add workstation setup procedures, or even list favorite places to eat around the office. The beauty of a wiki is that anyone can easily edit the content without having to deal with the tedium of HTML and deployment issues.

Next, you'll create and test a simple application.

No comments: