HTML and CSS Reference
In-Depth Information
to keep things simple—complicated test runners greatly decreases the likelihood of
developers running tests.
3.2.1 YUI Test
Most of the major JavaScript libraries available today have their own unit testing
framework. YUI from Yahoo! is no exception. YUI Test 3 can be safely used to
test arbitrary JavaScript code (i.e., it has no obtrusive dependencies). YUI Test is,
in its own words, “not a direct port from any specific xUnit framework,” but it
“does derive some characteristics from nUnit and JUnit,” with nUnit being the
.NET interpretation of the xUnit family of frameworks, written in C#. YUI Test is a
mature testing framework with a rich feature set. It supports a rich set of assertions,
test suites, a mocking library (as of YUI 3), and asynchronous tests. Setup
Setup is very easy thanks to YUI's loader utility. To get quickly started, we can link
directly to the YUI seed file on the YUI server, and use YUI.use to fetch the
necessary dependencies. We will revisit the strftime example from Chapter 1,
Automated Testing , in order to compare YUI Test to the testCase function in-
troduced in that chapter. Listing 3.1 shows the HTML fixture file, which can be
saved in, e.g., strftime _ yui _ test.html .
Listing 3.1 YUI Test HTML fixture file
<title>Testing Date.prototype.strftime with YUI</title>
<meta http-equiv="content-type"
content="text/html; charset=UTF-8">
<body class="yui-skin-sam">
<div id="yui-main"><div id="testReport"></div></div>
<script type="text/javascript"
<script type="text/javascript" src="strftime.js">
<script type="text/javascript" src="strftime_test.js">
Search WWH ::

Custom Search