Javascriptmvc tutorial-5. Start Using javascriptmvc-test cookbook

Source: Internet
Author: User

Javascriptmvc provides powerful support for testing. By using funcunit, you can easily create functions and unit tests that can run in a browser or automatically. In the previous lecture, we used the scaffolded command, and then the system helped you create a test script. Here we will do the following.

  • Run the unit test.
  • Understand unit testing.
  • Run the function test.
  • Measure the test taker's understanding about the function.
  • Test the istasty function.

 

  Run unit test

Funcunit uses qunit to test the model and basic plug-ins. You can run the test in a browser or envjs.

  Run in a browser

Open the cookbook/qunit.html page and you will see the following results:

  Run in envjs

Envjs is a javascript-based browser for rhino. funcunit can run the test in a simulated environment. Enter the following command in the command line:

js funcunit/run envjs cookbook/qunit.html

He will run the test in the simulated browser.

 

  Understanding Unit Testing

Funcunit uses qunit for assertions and organizes them into testing and modules. You can learn more about unit testing from qunit's documentation.

Load steal in cookbook/qunit.html and load your test file using cookbook/test/qunit. js and qunit. JS:

  • cookbook/test/qunit/cookbook_test.js
  • cookbook/test/qunit/recipe_test.js

These files are dependent on the loading of funcunit/qunit files. After all files are loaded, run the test. Open the cookbook/test/qunit/recipe_test.js file. Let's see what he has done:

// Create test ("findall", function () {// prevent the next test from running stop (2000); // request recipes cookbook. models. recipe. findall ({}, function (recipes) {// determine whether there is an OK recipes (recipes) // determine whether we have at least one recipe OK (recipes. length) // confirm that the recipe is normal OK (recipes [0]. name) OK (recipes [0]. description) // run the next test run start ()});})

 

  Test the running Function

Function tests are used to test user interaction requests, such as plug-ins that listen to click and Keyboard Events. The function test of cookbook mainly tests the creation and display plug-ins of recipe.

  Run in a browser

Open the cookbook/funcunit.html page, which opens a new page for automated testing. The final result is as follows:

 

  Run in Selenium

Selenium can automatically load the browser, which has been integrated into funcunit. Run the following command in the Command window:

> js funcunit\run selenium cookbook\funcunit.html

If you have any questions, you need to find the answer in funcunit documentation.

 

  Understand funcunit Testing

Funcunit extends the qunit and provides the page opening function. We open the cookbook/cookbook.html page. Its function is better than qunit.html, but it adds funcunit. "$" Is the alias of jquery. Let's see what functions he has implemented:

Test ("create recipes", function () {// enter ice S ("[name = Name]") in name. type ("ice") // enter cold water S ("[name = description]") in description. type ("Cold Water") // click the submit button S ("[type = submit]"). click () // wait until the second recipe appears S ('. recipe: Nth-child (2 )'). exists () // get the content s ('. recipe: Nth-child (2) TD: First '). text (function (text) {// confirm that it contains ice OK (text. match (/ICE/), "typed Ice ");});})

Funcunit executes many asynchronous operations, such as click and keypresses, and then executes assertions. Funcunit aims to provide readable and linear syntax. The funcunit statement is actually stored and executed asynchronously. Sometimes the page data is required to be obtained in the callback function.

 

Javascriptmvc tutorial directory

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.