Use D. O. H to test Javascript applications (2)

Source: Internet
Author: User
Tags event timer

In the previous chapter, "Use d.o. H for Javascript Application Testing (I)" uses firebug and Javascript injection technology to quickly demonstrate the functions and basic usage of d.o. H. Mainly:

  • Pass
    dojo.provide("demo.doh.tests.functions.demoFunctions");

    To register the test code module, and pass the familiar

    //Import in the code being tested.
    dojo.require("demo.doh.demoFunctions");

    To introduce the tested code module.

Use doh. register () instead of dojo. declare to define the test code module:

 

 

Doh. register ("demo. doh. tests. functions. demoFunctions ",[

 

Function test_alwaysTrue (){

 

// Summary:

 

// A simple test of the alwaysTrue function

 

// Description:

 

// A simple test of the alwaysTrue function

 

Doh. assertTrue (demo. doh. demoFunctions. alwaysTrue ());

 

}

 

]);

 

 

However, some of these problems have not been solved:

  1. Who will introduce doh? Previously, it was injected through the firebug console.
  2. How can the test code be run? In the previous article, the test code was injected through the firebug console, and the doh. run () command was manually executed to start the test.

Now let's take a look at how testing should be deployed in regular development.

First, I suggest you set the Development Directory to a structure similar to the following (test is irrelevant, but test is mentioned here, by the way ):

When we started Java web application Development a few years ago, we always placed the test folder in parallel with the src folder. The above structure is the style of Spring Roo. Now I can better accept this directory structure.

First, notice the runner.html in util/doh. This file provides the following infrastructure for running the test:

  • A graphical window and browser environment. This not only allows you to run the test code related to the browser window, but also provides a better graphical display of the test report.
  • Load dojo and doh. This solves the problem of who injected the doh mentioned above.
  • Start the test engine doh. run ().

Now the only question is, how can we make this framework run our test code?

In runner.html, query strings can be used as input parameters! (I once saw a blog saying that using a similar method to enable the debugging switch of dojo ).

Runner.html can accept the following parameters:

  • In dojoUrl, runner.html uses ...../dojo. js as the position of dojo. This parameter is used to override this setting.
  • TestUrl if you use any third-party library in your test and cannot use the dojo. require injection, this parameter is used to inject the third-party library. Although the keyword testUrl uses the singular form, it can actually receive multiple URLs, which must be separated by commas. If the url does not contain '. js', it is automatically added.
  • TestModule uses this parameter to introduce our test code. Likewise, it can receive multiple moduleName, which are separated by commas. In most places, the singular and plural nouns are used to distinguish between a single object and a set of objects. This is a small accident.
  • If the module introduced before registerModulePath is not located in the dojo. js/. Directory, you need to use this parameter to register it. Runner.html only saves the input parameters, parses them into an array and saves them, but does not really call the dojo. regiesterModulePath.

So, to run the myModuleTest test module, You need to input the url: http://www.bkjia.com/dojolib/util/doh/runner.html? TestModule = myModuleTest

If your server is not a static resource server such as apache or nginx, but an application server such as tomcat, there may be some problems. I'm Not sure whether the server will report a non-famous 404 Not Found error. However, I used nginx and didn't use address rewrite redirection. It seems that nginx has removed queryString directly, and the previous part is returned as the request address.

 

 

10:58:53 http request line: "GET/dojolib/util/doh/runner.html? TestModule = myModuleTest HTTP/1.1"

10:58:53 http uri: "/dojolib/util/doh/runner.html"

10:58:53 http args: "testModule = myModuleTest"

10:58:53 http exten: "html"

10:58:53 http process request header line

10:58:53 http header: "Host: www.lotus-scent.com"

10:58:53 http header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv: 7.0.1) Gecko/20100101 Firefox/7.0.1"

10:58:53 http header: "Accept: text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8"

10:58:53 http header: "Accept-Language: zh-cn, zh; q = 0.5"

10:58:53 http header: "Accept-Encoding: gzip, deflate"

10:58:53 http header: "Accept-Charset: GB2312, UTF-8; q = 0.7, *; q = 0.7"

10:58:53 http header: "Connection: keep-alive"

At 10:58:53 http header: "Cookie: Drupal. toolbar. collapsed = 0; cocat1 =-19.-6.-3"

10:58:53 http header done

10:58:53 event timer del: 4: 1318215561487

10:58:53 rewrite phase: 0

10:58:53 test location :"/"

10:58:53 test location: "dojodoc"

10:58:53 test location: "edward"

10:58:53 test location: "dojolib"

10:58:53 test location :~ "/Blog /.*\.(? : Ico | css | js | gif | jpe? G | png | zip )"

10:58:53 using configuration "/dojolib"

10:58:53 http cl:-1 max: 1048576

10:58:53 rewrite phase: 2

10:58:53 post rewrite phase: 3

10:58:53 generic phase: 4

10:58:53 generic phase: 5

10:58:53 access phase: 6

10:58:53 access phase: 7

10:58:53 post access phase: 8

10:58:53 content phase: 9

10:58:53 content phase: 10

10:58:53 content phase: 11

10:58:53 http filename: "/usr/www/dojolib/util/doh/runner.html"

10:58:53 add cleanup: commandid 1e3ed7d0

10:58:53 http static fd: 3

10:58:53 http set discard body

10:58:53 HTTP/1.1 200 OK

 

 

 

When the current url request returns, the window object still stores the original url address, rather than the address of the file actually returned by the server. Therefore, when the runner.html document is loaded in the browser, the javascript engine can parse the parameters carried in the query string and initiate a new request to load the test module.

 

From: midsummer lotus-cutting-edge web Technology

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.