The Source for Java Technology Collaboration
User: Password:



   

Fitnesse Testing for Fast-Paced Agile Web Development Fitnesse Testing for Fast-Paced Agile Web Development

by Robert J. Miller
11/22/2005

Contents
Why Would a Development Team Release
Software Updates Every Day?
Why Fitnesse?
HtmlFixture Asserting Text and
Links Are Correct
HtmlFixture Asserting Form Values Are
Correct Before and After a Form Submission
HtmlFixture with Preprocessing
to Enable Dynamic Assertions
XMLHTTPFixture Asserting
XML Output Is Correct
Test Writing Tips
Conclusion
What Next?
Resources

One of the goals of an agile web software development team is to deliver quality software in a timely fashion. For most web applications the server-side software uses a database and the final products are HTML and/or XML. HTML is rendered by a browser and XML is either processed by a browser (AJAX) or exchanged with a partner web application (business-to-business integration). Fitnesse tests can communicate with the database and can make assertions against HTML and XML. Agile web teams can use Fitnesse to create comprehensive test suites that make system-level assertions. Once these test suites exist, the team can release updates to their production web site as often as every day, confident that all of the system-level requirements (both old and new) are being met.

The purpose of this article is to illustrate the use of Fitnesse by agile web development teams. It first will discuss some of the reasons that agile web development teams would want to adopt a rapid release schedule. Next it will suggest that Fitnesse is a viable testing tool for use with this schedule. Then it will provide a number of examples to demonstrate the simplicity and power of Fitnesse. Finally, it will provide tips regarding Fitnesse test writing.

In this article, the agile term "whole team" refers to the collective group of software developers, DBAs, technical testers, managers, and customers. Agile software development is a discipline. For more information regarding agile software methodologies, see Ron Jeffries's XP web site.

Why Would a Development Team Release Software Updates Every Day?

  • Short answer: Good for the business.
  • The company's product is an e-product. Super-short releases allow the marketing department to obtain rapid customer feedback and to respond to that feedback quickly. They can test modifications to existing products and release new products sooner and more often. The agile concept of rapid feedback works well for the marketing team, too!
  • It's good for search engine optimization. Frequently updated web sites perform better in organic search engine results. This enables the business to attract customers to its web site without paying for sponsored links.
  • To respond to changing customer needs. Businesses that support diverse customer niches demand more agility from their products.
  • For contractual agreements with e-partners. Contractual agreements involving business-to-business web site integration can dictate when the software is released.

The rapid release schedule accommodates a wide range of sizes and types of projects, because each day the whole team has the opportunity to release software updates, regardless of how long the updates took to develop. Although the whole team could probably get by without releasing its software quite as often, once a rapid release schedule is adopted, the team members will wonder how they ever managed without it.

Simple web sites can be managed effectively by a content management system and require little developer, DBA, and technical tester work. However, more complex web sites require software customizations to provide tracking services for their e-products. This tracking can include page impressions, clicked links, dynamic advertising, and links to partner sites, which can then be customized for each e-product. These types of requirements are dynamic enough to keep patterns in the software design from forming, thereby forcing the whole team to release new products more often.

Why Fitnesse?

  • It's easy to use. Web developers, DBAs, technical testers, managers, and customers can all learn how to use wiki markup to make test assertions.
  • It's easy to install and lightweight to run. Get started with Fitnesse by running it on a developer workstation.
  • It performs assertions against HTML, XML, Java, and the database, all from a single tool. The complexity of your requirements will not outgrow Fitnesse's capabilities, because it can be extended to test anything testable with Java. Test writing is limited only by the whole team's imagination.
  • It's open source and well documented.

Agile web developers write Java software to test their Java objects, web pages, databases, and XML documents. JUnit is a popular testing framework for regression testing Java technologies. Fitnesse is analogous to JUnit in that it is a testing engine built using Java technologies. However, Fitnesse is different because its user interface is a web application with test suites created and managed using wiki markup. The key difference is that JUnit is primarily used by developers, whereas Fitnesse's user interface is friendly to non-developers, too. The developer extends Fitnesse's testing engine to expose new assertion methods. Then any team member (technical or not) can use the wiki markup to populate and run these new assertion methods. In the end, the developers use both JUnit and Fitnesse; each for different purposes.

Fitnesse describes itself as a "fully integrated standalone wiki, and acceptance testing framework" that runs test assertions using wiki markup. The wiki markup is used to create test tables whose assertions are run inside of the Java web FitServer. Upon completion of the test table, the FitServer displays a green-colored cell for each correct assertion and a red-colored cell for each failed assertion.

A fixture is a Java class that parses a wiki test table and then connects the test table to methods in the Java class. Fixtures support input parameters and connect a method's output to the wiki's display. For teams that want to quickly get started, there are HTML and database fixtures that can be installed and used without customization. For teams that need more functionality, the complexity of the assertions is limited only by the whole team's time and imagination, because Fitnesse's Java test fixtures are meant to be extended and customized. For instance, the developer team can write Java software that queries a database and then uses that data to assert that a web page is rendering that data correctly in HTML or XML.

HtmlFixture Asserting Text and Links Are Correct

Project requirements:

  • Create a home page with title, meta-keywords, and a meta-description.
  • Create a "Daily News" page with title, meta-keywords, and a meta-description.
  • Create a link from the home page to the "Daily News" page.
  • Use the mock-up in Figure 1 to create the display.

Mock-up of horizontal navigation including the Daily News link
Figure 1. Mock-up of horizontal navigation including the "Daily News" link

The HtmlFixture test table below loads a web page, asserts that the title and meta tags are correct, asserts that the "Daily News" display text and URL are correct, and then clicks on the link to prove that it works. Use Fitnesse markup variables to define the HtmlFixture's URL. This will allow you to quickly toggle the environment (develop, test, production) being tested. The domain markup variable is defined in the root suite so that the test runner can control which environment all of the HTML tests will run against.

!define domain {www.jhound.com}

Also, give each tested HTML element a unique id tag so that the Element Focus command can be used to find and focus on the element.

<a id="rssMenuLink" href="/rss/index.do">Daily News</a>

Here is the example wiki source code. The pipe (|) character starts and ends cells and rows.

!|com.jbergin.HtmlFixture|
|http://${domain}/|
|Element Focus|jhoundTitle|title|
|Text|www.JHound.com JavaHound- Welcome to 
 JavaHound|
|Element Focus|Description|meta|
|Attribute|name|Description|
|Attribute|content|Find Java information: a hub 
 for information regarding Java, Extreme 
  Programming, Web Services, and Java 
  certifications.|
|Element Focus|Keywords|meta|
|Attribute|name|Keywords|
|Attribute|content|java j2ee, java junit, java 
 hibernate, java web services, java extreme 
 programming, java testing, java web applications, 
 java struts, java servlets, java jsp, java xml, 
 java certification, java certification quiz, java 
 object/relational mapping, javaone 2004|
|Element Focus|rssMenuLink|a|
|Attribute|href|/rss/index.do|
|Text|Daily News|
|Click|nowOnDailyNewsPage|
|Element Focus|jhoundTitle|title|
|Text|www.JHound.com JavaHound- JavaHound RSS|
|Element Focus|Description|meta|
|Attribute|name|Description|
|Attribute|content|Read daily news articles|
|Element Focus|Keywords|meta|
|Attribute|name|Keywords|
|Attribute|content|java technology news, sports 
 news, world news, us news, political news, java 
 news, extreme programming news, j2ee news|

Here is the line-by-line description:

  1. Defines the test table's fixture type as HtmlFixture.
  2. HTMLUnit requests a web page and parses its HTML with an XML parser.
  3. Finds and focuses on a HTML title element with an id="jhoundTitle".
  4. Asserts that its text is correct.
  5. Finds and focuses on a HTML meta element with an id="Description".
  6. Asserts that its name attribute is Description.
  7. Asserts that its content attribute's text is correct.
  8. Finds and focuses on a HTML meta element with an id="Keywords".
  9. Asserts that its name attribute is Keywords.
  10. Asserts that its content attribute's text is correct.
  11. Finds and focuses on a HTML anchor element with an id="rssMenuLink".
  12. Asserts that its href attribute is correct.
  13. Asserts that its text is correct.
  14. Clicks on the link; HTMLUnit then parses the response HTML.
  15. (15-22) Proves that clicking the link worked by asserting that the "Daily News" page's title and meta tags are correct.

Figure 2 shows what the HtmlFixture test table looks like after it has finished running with all of its assertions passing.

Figure 2
Figure 2. HtmlFixture asserting display text and links are correct--click image for full-size screen shot

Figure 3 shows what the HtmlFixture test table looks like after it has finished running, with one of its assertions failing.

Figure 3
Figure 3. HtmlFixture asserting display text is incorrect--click image for full-size screen shot

Steps needed to run this example:

  1. Download and install Fitnesse.
  2. Download and install the HtmlFixture into Fitnesse.
  3. Create a Fitnesse test page with the aforementioned wiki source code.

Pages: 1, 2, 3

Next Page » 

View all java.net Articles.

 Feed java.net RSS Feeds