HTML and CSS Reference
In-Depth Information
Additionally, it is common practice for JavaScript to be served minified—i.e.,
with unneeded white-space and comments stripped out, and optionally local identi-
fiers munged to occupy fewer bytes—to preserve bytes over the wire. Both minifying
code too aggressively or merging files incorrectly can introduce bugs. A continuous
integration server can help out with these kinds of problems by running all tests
on the full source as well as building concatenated and minified release files and
re-running the test suite for them.
3.1.3 Asynchronous Tests
Due to the asynchronous nature of many JavaScript programming tasks such as
working with XMLHttpRequest , animations and other deferred actions (i.e., any
code using setTimeout or setInterval ), and the fact that browsers do not
offer a sleep function (because it would freeze the user interface), many testing
frameworks provide a means to execute asynchronous tests. Whether or not asyn-
chronous unit tests is a good idea is up for discussion. Chapter 12, Abstracting
Browser Differences: Ajax, offers a more thorough discussion on the subject as well
as an example.
3.1.4 Features of xUnit Test Frameworks
Chapter 1, Automated Testing , already introduced us to the basic features of the
xUnit test frameworks: Given a set of test methods, the framework provides a test
runner that can run them and report back the results. To ease the creation of shared
test fixtures, test cases can employ the setUp and tearDown functions, which are
run before and after (respectively) each individual test in a test case. Additionally,
the test framework provides a set of assertions that can be used to verify the state of
the system being tested. So far we have only used the assert method which accepts
any value and throws an exception when the value is falsy. Most frameworks provide
more assertions that help make tests more expressive. Perhaps the most common
assertion is a version of assertEqual , used to compare actual results against
expected values.
When evaluating test frameworks, we should assess the framework's test runner,
its assertions, and its dependencies.
3.1.4.1 The Test Runner
The test runner is the most important part of the testing framework because it
basically dictates the workflow. For example, most unit testing frameworks available
for JavaScript today use an in-browser test runner. This means that tests must
run inside a browser by loading an HTML file (often referred to as an HTML
 
Search WWH ::




Custom Search