HTML and CSS Reference
In-Depth Information
12.1.1 Discovering Browser Inconsistencies
Because unit tests are unlikely to accidentally discover all kinds of browser bugs,
some amount of exploration is necessary to uncover the bugs we're abstracting.
However, unit tests can help us make sure we cover the holes by triggering offending
behavior from within tests and making sure that production code copes with these
situations. Incidentally, this is the same way we usually use unit tests to “capture”
bugs in our own logic.
12.1.2 Development Strategy
We will build the Ajax interface bottom up, starting by asserting that we can get a
hold of an XMLHttpRequest object from the browser. From there we will focus
on individual features of the object only. We will not make any server side requests
from within the unit tests themselves, because doing so will make the tests harder
to run (we'll need someone answering those requests) and it makes it harder to
test isolated behavior. Unit tests are there to drive us through development of the
higher level API. They are going to help us develop and test the logic we build on
top of the native transport, not the logic a given browser vendor built into their
XMLHttpRequest implementation.
Testing our own logic is all fine and dandy, but we still need to test that the
implementation really works when sitting on top of an actual XMLHttpRequest
object. To do this, we will write an integration test once the API is usable. This
test will be the real deal; it will use our interface to make requests to the server. By
running it from an HTML file in the browser, we can verify that it either works or
fails gracefully.
12.1.3 The Goal
The decision to write an XMLHttpRequest wrapper without actually using it
inside the tests may sound strange at first, but allow me to remind you yet again of the
goal of test-driven development; TDD uses tests as a design tool whose main purpose
is to guide us through development. In order to truly focus on units in isolation,
we need to eliminate external dependencies as much as practically possible. For
this purpose we will use stubs extensively in this chapter. Remember that our main
focus is to learn test-driven development, meaning that we should concentrate on
the thought process and how tests form requirements. Additionally, we will keep
practicing continuous refactoring to improve the implementation, API, and tests.
Stubbing is a powerful technique that allows true isolation of the system under
test. Stubs (and mocks) have not been discussed in detail thus far, so this chapter
Search WWH ::

Custom Search