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.
3.2.1.1 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Testing Date.prototype.strftime with YUI</title>
<meta http-equiv="content-type"
content="text/html; charset=UTF-8">
</head>
<body class="yui-skin-sam">
<div id="yui-main"><div id="testReport"></div></div>
<script type="text/javascript"
src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js">
</script>
<script type="text/javascript" src="strftime.js">
</script>
<script type="text/javascript" src="strftime_test.js">
</script>
</body>
</html>
 
Search WWH ::




Custom Search