How to find a good JavaScript unit test tool

Source: Internet
Author: User
Tags versions ruby on rails xunit advantage

Let's look at the status of JavaScript unit testing and the testing tools.

1.JsUnit

We are already using it as our Unit test tool.

Advantage:

Can be called by ant build file;

Start the browser to run the test case;

Eclipse plug-in support;

Disadvantages:

Need to start the browser to run test cases;

Does not support the use of JS file to write unit test code: it must be embedded in the HTML file;

It has not been updated for several years;

Attention:

There is a test tool called jsunit (2);

Ant is an open source build tool; it's called Ant because it's small, but it can be used to build large projects;

2.RhinoUnit

Advantage

Ant Drive

Support JS file

Very easy to use

Disadvantages

The simulated JavaScript engine is not good enough to support our code. I tried using it to run "run on Jsunit" test code, but we ran into problems loading our generic JavaScript files

3.crosscheck

Advantage

Can be called by ant build file

Simulate real-World browser behavior

Disadvantages

The emulated JavaScript engine has only a few browser versions

Not updated for two years: Firefox 2.x or 3.x not supported

4.jsspec

Advantage

Run on the Real browser

Disadvantages

JavaScript only frames, cannot be called by ant build file

5. Jspec

Advantage

Run on the Real browser

Disadvantages

Seemingly unsupported by our code, I tried to run the "run on Jsunit" test code, but encountered problems loading our generic JavaScript files

JavaScript only frames, cannot be called by ant build file

6. Screw.unit

Advantage

Running in a real browser

Disadvantages

JavaScript only frames, cannot be called by ant build file

Note: We've used it, but it's smaller than Jsspec and Jspec.

So Jsunit is our only option. Note that it is already in use in other components. It's not perfect, it doesn't provide a convenient way to implement test-driven Development (TDD):

It does not provide a simple, integrated way to run unit tests

It forces you to write unit tests in HTML files instead of JS files

It forces you to install a local Jsunit framework to avoid the path of hard coded JS unit test files

As a result, when you are in "test-driven development" JavaScript, you have to switch back and forth between your IDE and the browser you want to test. It's doable, but I don't think it's efficient (I might be wrong here).

Of course I'm still looking for a better JavaScript editor or an Eclipse plug-in that can easily be referenced and refactored. Part of the WTP project is called the JSTD plugin, but I don't have enough experience to comment on it.

Summing up, I don't think we have the tools to fully implement "TDD". We can TOD (for test-oriented development), but I haven't found anything that will allow us to write JavaScript as efficiently as we write Java. Again, the ideal solution will be similar to JUnit.

What unit test tool are you using?

The answer to the highest votes comes from Gregers

1. Buster.js

Similar to the server/client concept of jstestdriver (which will be discussed later). Except that the server is implemented using Node.js, not java. And the API follows the best practices of JS.

A browser JavaScript test tool library. Automated browser test (think of Jstestdriver bar), Qunit style static HTML page test, can be in the browser without interface (Phantomjs,jsdom ... ) and other browsers in the test. Look at the overview of it!

A Node.js test tool library. You have the same test case library, the assertion library, and so on. This is good for code that supports both browsers and Node.js. Use Buster.js to write your test cases and then run them in Node.js and real browsers.

Screenshot: Buster.js Getting Started (2:45)

Advantage:

Using Node.js, compatible Win/os x/linux

Can be run in a normal browser or without an interface Phantomjs (FAST)

Run multiple clients at once

Support Nodejs Test

No need to run server/clients on the development machine (ie not required)

Run tests on the command line (can be integrated by Ant/maven) write xunit or BDD-style tests

Supports multiple JavaScript test frameworks

Support for delaying testing rather than commenting out the code

Built in Sinonjs

Run tests automatically while saving

Agent cross-domain request:

Can be extended to include other test frameworks (built in Jstestdriver)

Plus your own assertion/rejection

Reports (Xunit XML, traditional dots, specification, tap, teamcity and more built in)

Customize or replace HTML that runs in a browser test

TextMate and Emacs Integration

Disadvantages:

Still in beta, there are a lot of bugs.

There are no eclipse or IntelliJ plug-ins.

Do not organize results in a os/browser/version manner like testswarm. Note: It will, but only print the browser name and version in the test results

There's no historical support like Testswarm, and I don't see the test results.

Note: When you need to provide an independent CI service for Buster.js, Testswarm can also serve as a continuous integration (CI) service. However, Buster.js can output xunit XML reports, so it can be easily integrated into CI services such as Hudson,bamboo.

2. Testswarm

Testswarm is a distributed JavaScript test tool created by John Resig (jquery author). Mainly for open source JavaScript project testing, but Testswarm is also open source, so you can configure yourself with a testswarm server for enterprise testing. But this may require a lot of changes.

Advantage

Continuous Integration Services for JavaScript

Support for all major browsers and operating systems

Run multiple clients at once

No need to run server/client on the development machine (ie not required)

When you submit something (or modify a script), run the test automatically on all clients

Show Test history results for each submission

Supports multiple JavaScript test frameworks

There are results for the operating system and browser versions

Crowdsource to test in a multitude of browsers

Disadvantages:

Unable to interrupt the test through Ant/maven

Failed to know test case before committing

No IDE plugin support

http://ejohn.org/blog/javascript-testing-does-not-scale/

Testswarm's Architecture:

3. Jstestdriver

Some Google engineers have also started the development of a distributed JavaScript tool, Jstestdriver. Like Testswarm, it has a server and the client is connected to the server. But it also supports running from the command line and has Eclipse and IntelliJ Plug-ins!

Advantage:

Support for all major browsers and operating systems

Run multiple clients at once

No need to run server/client on the development machine (ie not required)

Can run tests at the command Line (jar) (can be integrated by Ant/maven)

Eclipse Plug-in

IntelliJ Plugin

Supports multiple JavaScript test frameworks

Disadvantages:

The operating system or browser version is not displayed. Only the browser name, but it will print the version in the test results

Test history results are not supported

Project is not very active, update slow

Jstestdriver's running overview is as follows: Jstestdriver

Eclipse Plug-in screenshot: Jstestdriver for Eclipse

Simple Introduction to Video: Http://www.youtube.com/watch?v=V4wYrR6t5gE

4. YUI Yeti

Yahoo has now run the test Javascript,yeti on its own services. Build based on Node.js. It can run your existing yui-test and support a variety of browsers. Since it can be run from the command line, I guess it's similar to Jstestdriver.

Posted on August 25, 2010:

If you are familiar with it, please provide me with more information:

Project Address: http://yuilibrary.com/projects/yeti/

5. Jasmine

This test tool may cause attention to developers who are "familiar with Ruby/ruby on rails." Its syntax is based on tests that Rspec,rspec is used for rails projects.

Jasmine is a JavaScript test framework for behavioral-driven Development (BDD). It does not rely on any other JavaScript framework. It also does not rely on the DOM.

If you are familiar with it, please provide me with more information:

Project home: https://github.com/pivotal/jasmine/

6. Qunit

Qunit focuses on JavaScript testing on browsers, providing as much convenience as possible. Introduction from the official website:

Qunit is a powerful, easy-to-use JavaScript unit Test Library. jquery, the jquery UI, and the jquery mobile project all use it. It can also be used to test common JavaScript code.

Qunit and Testswarm have some of the same history:

Qunit is part of jquery and is developed by John Resig. In 2008, it had its own home page, name, and API documentation, allowing others to use it as a unit test. It was based on jquery at the time. A refactoring that solved this problem in the 2009 is now Qunit completely independent of jquery. Qunit's assertion method follows the COMMONJS unit Test standard, which is also partly influenced by Qunit.

Project home: http://qunitjs.com/

7. Sinon

Sinon.js is another great test tool. It was developed by Christian Johansen, author of the book "Test-driven JavaScript Development". He thinks it's the best.

Provides independent spies,stubs and mocks for JavaScript. Without any dependencies, you can work with any unit test framework.

http://tddjs.com/

Note: This article is compiled by Zhou Minhming from the stack Overflow with the same name, and other replies can be found in StackOverflow original post

Article Source: Bole Online

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.