Fireunit-test-driven Javascript development

Source: Internet
Author: User

Fireunit is a Firefox extension and also a firebug extension. This extension provides a bunch of APIs to help you implement unit testing of JavaScript code, add another tab in firebug to display the test results. We still provide basic tests, but we need to believe in the potential of this extension, because it was prepared by John resig and Jan odvarko. What? Have you heard of them? Whispered question. Have you heard of JavaScript?

Http://ejohn.org/blog/fireunit/()
[Author] John resig

The following is a translation of the original text:

During the months I worked with the firebug team, Jan odvarko and I tried to establish a unit test method for JavaScript, the final result of this work is a Firefox/firebug extension called fireunit.

Fireunit provides a set of JavaScript APIs for simple unit tests and displays the results under the tab bar added in firebug.

Below are a few examples of using fireunit API for unit testing (now we only provide some basic methods, and more methods will be extended in the future ).

// The simplest test is true-like/false-like.
Fireunit. OK (true, "I'm going to pass! ");
Fireunit. OK (false, "I'm going to fail! ");

// Compare two strings and display the differences
Fireunit. Compare (
"The Lazy fox jumped over the log .",
"The lazy brown fox jumped the log .",
"Are these two strings the same? "
);

// Use a regular expression to compare strings
Fireunit. recompare (
/The. * fox jumped the log ./,
"The lazy brown fox jumped the log .",
"Compare a string using a Regexp ."
);

// Display all results
Fireunit. testdone ();

The unit test results are displayed in the "test" tab in firebug (of course, firebug must be installed first to run fireunit ). Each item on the results page displays detailed information, including test trace records and differences in string comparison.

Fireunit also provides a set of methods to simulate local browser events

// You can simulate browser events in the following ways
VaR input = Document. getelementsbytagname ("input") [0];
Fireunit. mousedown (input );
Fireunit. Click (input );
Fireunit. Focus (input );
Fireunit. Key (input, "");

And a way of running a batch of test files (each of which wocould contain a number of individual tests ).

// Or you can run a test on multiple pages together
Fireunit. runtests ("test2.html", "test3.html ");

// End ID of the Test File
Fireunit. testdone ();

We have designed many firebug test cases in this way, especially for those network-based functions.

For existing test cases, you can simply rewrite them to display the results directly in fireunit.

The test case of the jquery selector is composed of the following code snippets:

If (typeof fireunit = "object "){
Qunit. log = fireunit. OK;
Qunit. Done = fireunit. testdone;
}

The results of this test case are as follows:

If you want to start using fireunit, go to fireunit.org and download the latest version.

You can also go to GitHub to download the source code.

Jan also wrote a more detailed article on his blog to introduce how to apply fireunit during the development of firebug.

This project is still in its infancy and there is still much room for improvement. We need your feedback.

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.