Java Reference
In-Depth Information
Listing 13.6
jsUnitTestSuite.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JsUnit Test Suite - Chapter 13</title>
<link rel="stylesheet" type="text/css"
href="../../../jsunit/css/jsUnitStyle.css">
<script type="text/javascript"
src="../../../jsunit/app/jsUnitCore.js"></script>
<script type="text/javascript">
function suite() {
var newsuite = new JsUnitTestSuite();
newsuite.addTestPage(
"../src/test/webapp/jsFactorialTests.html");
return newsuite;
}
</script>
</head>
<body>
<h1>JsUnit Test Suite for Chapter 13</h1>
<p>This page contains a suite of tests for testing JsUnit.</p>
<p>To see the tests, view the source for this page.</p>
</body>
</html>
To define a test suite, create a function called
suite
b
, which returns a
JsUnitTestSuite
object. You then build up a
suite
object by adding test pages or other
suite
objects. In
our example, we add one page
C
, the page we previously defined by calling the
addTest-
Page
function. The rest of the code in this
HTML
page is the same as our previous exam-
ple with the exception that we don't need to refer to our JavaScript factorial library.
B
C
JsUnit
addTestPage
tip
The
addTestPage
argument is a location relative to the test runner page you'll use.
In our examples, we use the test runner
jsunit/testRunner.html
.
To add a test suite to another test suite, create a new
JsUnitTestSuite
object, and call
the
addTestSuite
API
. This allows you to organize your tests just as you can in
JU
nit.
Listing 13.7 defines and adds two test suites to a main test suite.
Listing 13.7
Building a JsUnit test suite
function featureASuite() {
var result = new JsUnitTestSuite();
result.
addTestPage
("../tests/featureA/Test1.html");
result.
addTestPage
("../tests/featureA/Test2.html");
return result;
}