Download the jsunit package jsunit2_2.zip from www.jsunit.net.
Decompress the package on drive C.
Jsunitcore. JS is in c: \ jsunit \ app \ jsunitcore. js.
Testrunner.html is in c: \ jsunit \ testrunner.html
I put test1.jsand test1.htmlCodeIn C: \ jsunit_code
Test1.js code:
Function add (num1, num2)
{
Return num1 + num2;
}
Function subtract (num1, num2)
{
Return num1-num2;
}
Function multiply (num1, num2)
{
Return num1 * num2;
}
Test1.html code:
<HTML>
<Head>
// Import jsunit \ app \ jsunitcore. js two points ".." to the directory on the previous LayerThe directory at the top layer of test1.html is c: \, which is represented .. \.C :\
<SCRIPT type = "text/JavaScript" src = ".. \ jsunit \ app \ jsunitcore. js"> </SCRIPT>
// Import test1.js
<SCRIPT type = "text/JavaScript" src = "test1.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Function setuppage ()
{
Alert ("setuppage invoked ");
Setuppagestatus = "complete ";
}
Function setup ()
{
Alert ("setup ");
}
Function teardown ()
{
Alert ("teardown ");
}
Function testadd ()
{
VaR result = add (2, 3 );
Assertequals (5, result );
}
Function testsubtract ()
{
VaR result = subtract (4, 2 );
Assertequals (2, result );
}
Function testmultiply ()
{
VaR result = multiply (2, 3 );
Assertequals (6, result );
}
</SCRIPT>
</Head>
<Body>
</Body>
</Html>
Open testrunner.html under c: \ jsunitand enter the test code path c: \ jsunit_code \ test1.html in file: //.
(Testrunner.html) there is a problem running in Firefox, and there is no problem running in IE and 360 browsers. You can also try other browsers)
Click Run. The result is displayed as follows: