Unit test of Web 2.0 applications with Dojo Objective harness

Source: Internet
Author: User
Tags require visibility

Unit testing is an important part of ensuring the quality of software development, especially for agile and extreme programming development methods. In general, automated unit testing of the WEB 2.0 client user interface is difficult, so few people try. However, Dojo provides a unit test tool that allows you to evaluate the functionality of JavaScript and the visibility of the user interface. The user interface that has been thoroughly tested by this tool will eventually contain a significant reduction in the number of bugs. This article describes the main features of the Dojo objective Harness (DOH) and demonstrates its powerful features by comparing it with other WEB 2.0 application test tools.

Unit Test Cases

Writing unit tests is usually to test a section of source code. In theory, the Code fragment (or unit of code) is the smallest testable part of the source code. A unit test is usually done automatically, but it does not have to be done automatically, and the results of the unit test indicate whether the code will work as designed.

It is well known that software developers are usually tense in terms of time. In order to put the product into the market as soon as possible, they have to face a lot of pressure, then why to write unit test to spend more time? This is because a full unit test suite not only produces high quality code, but ultimately saves a lot of time by reducing the time to debug bugs. In addition, if you can write unit tests before you write the source code in accordance with agile development methods, you will also reduce the code you need to write. You can also reduce the amount of code you need to write to achieve the purpose of unit testing, if you consider the design thoroughly before you start coding.

What is Dojo objective harness?

Unit testing has many supporters, as seen in extreme programming and agile programming. The extensive use of asynchronous JavaScript + XML (Ajax) and WEB 2.0 user interfaces has spawned the need for client unit testing. Dojo Objective Harness is a tool used by WEB 2.0 UI developers for JUnit. Unlike existing JavaScript unit test frameworks, such as JSUnit, DOH not only implements JavaScript functions automatically when using or not using Dojo, it can also unit-test the visibility of the user interface. This is because DOH (a good acronym) provides both a command-line interface and a browser-based interface to test the framework.

Browsers and non-browser environments

As mentioned earlier, DOH provides both a command-line interface and a browser-based interface. If unit testing requires complete automation and does not require a visual component, the command-line interface is a good choice because it can be started with a build script and the results can be logged. In addition, this interface provides a unit test environment that is very similar to JUnit. DOH also uses Rhino for its command-line interface, an Open-source JavaScript engine written in Java™ code. For this reason, references to document, window, Domparser, and XMLHttpRequest objects cannot be parsed. Another problem with Rhino is that it uses a JavaScript interpreter that is different from the General browser, which makes it possible to pass the test within one runtime and not within the other runtime.

If unit tests require visual components and access to a variety of JavaScript objects, the Browser-based interface is the best choice. You need to be reminded that unit tests using browsers are not 100% automatic; You must start unit tests in your favorite browser and check their results. Actually, it's not surprising. The quality of a UI appearance is usually a subjective judgment of the person. The running program of the browser test provides two ways to display the test results: one is a visual result and the other is unit test statistics. Figure 1 shows the running test case on the left side, and the code execution is visualized by the right Test Page tab (click here to see a larger picture of Figure 1).

Figure 1. DOH Unit Test Visualization

Figure 2 shows the unit test statistics under the Log tab (click here to see a larger view of Figure 2).

Figure 2. DOH Unit Test statistic data

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.