18, JavaScript Unit test framework jsunit__ Large data

Source: Internet
Author: User

1. JavaScript Coding specification: Usually underline the names of the members and methods that JavaScript does not want outside access

2, the Jsunit test function to follow the rules and JUnit3.8 similar (for example, the test function name to start with testing, etc.)

To use Jsunit, to introduce the Jsunit library jsunitcore.js, use the following statement:

<script type= "Text/javascript" src= "Jsunit/app/jsunitcore.js" > </script>

 


For normal projects, the test code and the actual code will be separated, the actual code into a single JS file, such as: Test1.js

function Add (num1,num2)
		{return	
			num1 + num2;
		}	
		function Subtract (num1,num2)
		{return
			num1-num2;
		}
		function Multiply (num1,num2)
		{return
			num1 * NUM2;
		}


Test:

 


3. For Jsunit, the setup and Teardown methods are different from the operating principles of junit, and there is no relationship between Setuo and teardown in JUnit, which means that different test methods run in different test subjects. The Jsunit test functions are run on the same test page. Therefore, Setup and teardown will operate on the same variable:

 


Jsunit provides a setuppage method, similar to the @beforeclass in JUNIT4, which executes only once (after the page is loaded) and must be added on the last line of the function: Setuppagestatus = "complete";

This line of code must be placed on the last line of the Setuppage function, telling Jsunit that the Setuppage function has been executed and will stop here without adding the page until the browser prompts to timeout

 


does not provide a function corresponding to the @afterclass

3, the three input text on the page, enter the number on the 1,2, provide an Add button, click the button to fill in the third text field, and then test the Add function

 


Test1.js file:

	function Add (num1,num2)
		{return	
			num1 + num2;
		}	
		function Subtract (num1,num2)
		{return
			num1-num2;
		}
		function Multiply (num1,num2)
		{return
			num1 * num2;
		}

function AddNumbers ()
{
	var v1 = document.getElementById ("value1"). Value;
	var v2 = document.getElementById ("value2"). Value;

	V1 = parseint (v1);
	V2 = parseint (v2);

	var v3 = v1 + v2;
	
	document.getElementById ("Value3"). Value = V3;
}


4. Test Kits

 


The example above is to add only the test page in the suite, and the following example is to add both the test page and the test suite, which is the test suite nesting:

 


 

Related Article

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.