Test Pages and Test Functions
We write an (HTML) Test Page of tests when using JsUnit (corresponding to a test class in JUnit). A test page contains JavaScript Test Functions (corresponding to test methods in JUnit). A Test Function is distinguished from other functions on the page by its name - it must begin with "test"; in addition a test function takes no parameters (just as things are in JUnit.) For example, a Test Function could have the signature testMyCode().
A test page must "include" the jsunit/app/jsUnitCore.js JavaScript file; this file is the JsUnit engine.
(This corresponds to extending the TestCase class in JUnit.)
That is, the document's <head> must contain the statement
<script language="JavaScript" src="jsUnitCore.js"></script>
Of course, you may need to change this to point at jsUnitCore.js if you are in a different directory.
For example, since the JsUnit self tests live in jsunit/tests, they point at "../app/jsUnitCore.js".
Under most platform/browser combinations, Test Functions are "auto-discovered" - that is, JsUnit can scan the Test Page and discover what Test Functions are present. For Mac 0S9 with IE5, Mac OSX with IE5, KDE with Netscape 6.x/Mozilla 0.9 and KDE with Konqueror, however, auto-discovery is not supported. You must expose the Test Function names using the exposeTestFunctionNames() function. This function must return a string array of all the Test Functions in the page.
Of course, test pages can include any other .js library files and can contain any other functions. Sometimes it is useful to define Test Functions in external .js files. For example, you may wish to set up several HTML with different contents and to run the same tests on each; placing the Test Functions in an external .js file and including it in each HTML page accomplishes this. If you define Test Functions in external .js files, you must expose the Test Function names using the exposeTestFunctionNames() function except in Mozilla.