How to create a project test program starting with JavaScriptMVC

Source: Internet
Author: User

JavaScriptMVC puts a major emphasis on testing. The JavaScriptMVC framework uses the FuncUnit module to help us write functions and unit tests more easily, and the tests can be executed in a browser or fully automated.

After you complete the recipe module, it will automatically generate the test code. The following article describes how to complete the following five tasks.

1. Perform unit tests.
2. Understand unit testing.
3. perform a function test.
4. Test the understanding function.
5. testing is a good function.

1. Execute unit test

FuncUnit uses Jquery's QUnit tool to test the image module and basic plug-ins. You can perform these tests in your browser or Envjs.

Execute unit test in the browser

Open cookbook/qunit.html and you will see:

Next, let's take a look at the second method. First, let the test be executed in the Envjs environment.

Execute unit tests in the Envjs Environment

Envjs is a basic script browser. FuncUnit can perform your tests in this simulated environment.

On the DOC console of Window, enter the following command:
Js funcunit/run envjs cookbook/qunit.html

Then, qunit.html will be executed in a simulated browser environment. Enter the following information:


2. Understanding Unit Testing

FuncUnit uses the assertion of the QUnit tool to combine test functions into modules. To better understand unit testing, read the QUnit help documentation.
Cookbook/qunit.html loads the steal module and lets steal load the cookbook/test/qunit. js file. This file is used to load all unit test files:
Cookbook/test/qunit/cookbook_test.js
Cookbook/test/qunit/recipe_test.js

Once all scripts are loaded, the test assertions are executed.

Open the cookbook/test/qunit/recipe_test.js file and let's see how the findAll test works.
// Creates a test
Test ("findAll", function (){
// Prevents the next test from running
Stop (1, 2000 );

// Requests recipes
Cookbook. Models. Recipe. findAll ({}, function (recipes ){

// Makes sure we have something
OK (recipes)

// Makes sure we have at least 1 recipe
OK (recipes. length)

// Makes sure a recipe looks right
OK (recipes [0]. name)
OK (recipes [0]. description)

// Allows the next test to start
Start ()
});
})

3. perform a function test

Function testing is used to test mouse and keyboard events generated by simulating user-interface interaction.

The functional test of the chef manual is to test the interaction between recipe creation and list interfaces.

Run the function test on the browser www.2cto.com.

Open cookbook/funcunit.html and you will see the following:

Perform a functional test in the Selenium environment.

Selenium can automatically load browsers and encapsulate them into the FuncUnit module.

Run the following command:
Js funcunit \ run selenium cookbook \ funcunit.html

If you are using the Window system, it will open Firefox and IE browsers. The test results are as follows:


If an exception occurs when executing this test in IE, You need to modify the configuration of IE. For more information, see the FuncUnit help documentation.

4. Test the comprehension Function

FuncUnit and QUnit can be used to open other pages. In this example, cookbook/cookbook.html has Interactive Actions and obtains some information from the page.

The cookbook/funcunit.html page can work like qunit.html because the FuncUnit module loads the FuncUnit plug-in. Like Jquery APIs, FuncUnit is called using the "S" alias.

Open the cookbook \ recipe \ create \ create_test.js file, and we can see the following code:

Test ("create recipes", function (){

// Type Ice in the name field
S ("[name = name]"). type ("Ice ")

// Type Cold Water in the description field
S ("[name = description]"). type ("Cold Water ")

// Click the submit button
S ("[type = submit]"). click ()

// Wait until the 2nd recipe exists
S ('. recipe: nth-child (2)'). exists ()

// Gets the text of the first td
S ('. recipe: nth-child (2) td: first'). text (function (text ){

// Checks taht it has ice
OK (text. match (/Ice/), "Typed Ice ");
});

})

From the test, we can easily see that this test case is to create a recipe and add it to the list.

5. testing is a good function.

FuncUnit makes Web Testing readable and linear syntax possible. JavaScriptMVC provides this test function to make great contributions to Web development.


From xpp02
 

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.