Java Reference
In-Depth Information
Let's start by showing how to run a test from JsUnit and then automating the test
from Ant. The source code for this chapter includes a copy of JsUnit; for details please
see appendix E.
13.4.3
Writing JsUnit tests
You write a JsUnit test by creating an HTML page containing JavaScript test functions.
You then run the test from a web browser. You use HTML only as the container for the
JavaScript. Listing 13.5 is our factorial test.
Listing 13.5
jsFactorialTests.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JsUnit Factorial Tests - 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"
src="../../../src/main/webapp/factorial.js"></script>
<script type="text/javascript">
B
C
D
function test15() {
assertEquals(factorial(15), 1307674368000);
}
E
function testRegEx() {
var actual = "JUnit in Action";
assertTrue(actual, /in/.test(actual));
assertFalse(actual, /out/.test(actual));
}
</script>
</head>
<body>
<h1>JsUnit Chapter 13 Tests</h1>
<p>This page contains tests for the Chapter 13 examples.</p>
<p>To see the tests, view the source for this page.</p>
</body>
</html>
You define the JsUnit test in the HTML head element and start with the references
needed to bring in the JsUnit framework b and the JavaScript code to test C .
JsUnit tip
The references in the link href and script src attributes are relative to the loca-
tion of the HTML test file.
 
 
 
 
 
Search WWH ::




Custom Search