Javascript notes-simple example of jsunit

Source: Internet
Author: User

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:







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.