HTML and CSS Reference
In-Depth Information
To test additional pages for well-formedness, you simply add more methods, each of which looks exactly like
testBlogIndex , just with a different URL. Of course, you can also write more complicated tests. You can test for
validity by setting the feature on the parser and attaching an error
handler that throws an exception if a validity error is detected.
You can use DOM, XOM, SAX, or some other API to load the page and inspect its contents. For instance, you
could write a test that checks whether all links on a page are reachable. If you use TagSoup as the parser, you
can even write these sorts of tests for non-well-formed HTML pages.
You can submit forms using the HttpURLConnection class or run JavaScript using the Rhino engine built into
Java 6. This is all pretty low-level stuff, and it's not trivial to do, but it's absolutely possible to do it. You just
have to roll up your sleeves and start coding.
If nondevelopers are making regular changes to your site, you can set up the test suite to run periodically with
cron and to e-mail you if anything unexpectedly breaks. (It's probably not reasonable to expect each author or
designer to run the entire test suite before every check-in.) You can even run the suite continuously using a
product such as Hudson or Cruise Control. However, that may fill your logs with a lot of uncountable test traffic,
so you may wish to run this against the development server instead.
Many similar test frameworks are available for other languages and platforms: PyUnit for Python, CppUnit for
C++, NUnit for .NET, and so forth. Collectively these go under the rubric xUnit. Whichever one you and your
team are comfortable working with is fine for writing web test suites. The web server doesn't care what
language your tests are written in. As long as you have a one-button test harness and enough HTTP client
support to write tests, you can do what needs to be done.
HtmlUnit ( ) is an open source JUnit extension designed to test HTML pages. It
will be most familiar and comfortable to Java programmers already using JUnit for test-driven development.
Search WWH ::

Custom Search