What are some JavaScript testers and Mocking Frameworks that you used?

My main JavaScript framework is jQuery , so I would like my unit test and mocking frameworks to be compatible with this. I would prefer not to introduce another JavaScript framework.

I am currently using QUnit for unit testing and Jack for ridicule, but I'm pretty new to all JavaScript unit testing.

Does anyone else have a better hint tool? What worked for you?

+41
javascript jquery unit-testing qunit mocking
Oct. 16 '08 at 16:56
source share
14 answers

QUnit
jQUnit
Writing JS Tests with QUnit and jQUnit

QUnit is a unit testing platform for the jQuery JavaScript framework. The test environment itself uses the jQuery library, but tests can be written for any JavaScript and do not require the use of jQuery code. JQUnit is a modified version of QUnit that adds to the settings, disables and approves functions that are more specific to the xUnit infrastructure and encapsulates everything in one global variable.

The visual interface of the testrunner page is good, allowing you to expand and see each statement in each test method. Written tests are fairly simple, and you can run the test code directly on the testRunner page [8]. This allows you to easily and visually test the DOM.

QUnit: MIT or GPL (select) jQUnit: MIT License

Pros
- Asynchronous support
- Good for testing DOM
- Tests are always performed sequentially in the order they are added to the set.
- Debugging on a test page using firebug
- The syntax is similar to JUnit if you use JQUnit, but just find out if you use QUnit
against
- Automation will be difficult to implement

+18
Oct. 16 '08 at 18:22
source share

I think Jack is the best mocking framework for JavaScript at the time of this writing. The main reason is that JavaScript right is unlikely, which is suitable for a strongly typed language such as Java.

Many fake JavaScript frames are inspired by Java frameworks (like great JsMockito for example). But the problem is that they require dependency injection , because this is the only reasonable way to use taunts in Java. But in JavaScript, there are many ways to use mockery, and you are not forced to use dependency injection everywhere.

For example, with JsMockito you need to make mocks, and then pass these mocks to your test software (SUT). SUT should directly call ridicule. Therefore, you are forced to encode SUT as a constructor or function that takes parameters in all its dependencies. (Sometimes this is a great way to implement it, but not in every case. The tail wags the dog if your mocking frame design forces your approach to implementation).

JavaScript is very easy to capture any function. Therefore, there are many ways to create something that you can mock particles without explicitly inserting your dependencies into it. For example, Jack allows you to mock any function, regardless of whether it is a public or local object. From there, you can spy on her, drown her out or express expectations on her. The key point is: when you mock a function, ANY calls to this original function will be directed to your layout . In other words, your bullying will continue to be used, even if the original, unmocked function was called. As a result, you are not forced to add dependencies, although you can certainly do so in cases that require it.

JavaScript is a different language than Java (and C #, etc.). It allows you to use different implementation idioms. Injection injection is still one of the valuable toolbar tools in JavaScript, but this is not the only game in the city. Your bold structure should know and respect this fact. Jack and a couple of others, but of those who do, Jack seems to be the most mature and rich in opportunities.

+20
Oct 27 '10 at 6:35
source share

I'm not sure why no one mentioned JsTestDriver ! This should be the only JS Testing tool that works as you would expect if you used unit testing tools in other languages.

Running tests can be done without touching the browser, you can integrate it with the IDE, you can integrate it with continuous integration systems ... Oh, and itโ€™s fast, and can run tests in multiple browsers at the same time.

You can also use other testing structures such as YUITest, which makes it even better.

+12
Dec 12 '09 at 23:20
source share

YUI test
TDD with YUI Test

YUI Test is a test environment for Yahoos UI Library. It is used by Yahoo to test its own library and has a syntax similar to jUnit.

Like jsUnit, YUI Test comes with its own logging console, which can display information, warnings and errors in addition to the results of each test.

YUI also provides the ability to send result reports in JSON or XML format.

The YUI Test is a licensed BSD.

Pros
- Really good documentation
- Active community
- Regular releases
- The syntax is similar to jUnit (test suites, approves and installs / disables)
- Asynchronous support
- Good for testing DOM
- Tests are always performed sequentially in the order in which they are added to the package.

against
- Automation is not trivial to implement, but less complicated than other structures

+6
Oct. 16 '08 at 18:29
source share

Also check out http://sinonjs.org/

Spyware Test Stubs Mocks Fake Timers Fake XHR Fake Server Sandbox-Based Claims

It works with qUnit and has been a plus so far.

+3
Mar 25 '11 at 17:41
source share

This is a pretty good overview of the funny frameworks available for Javascript:

http://testdrivenwebsites.com/2010/05/06/java-script-mock-frameworks-comparison

+2
Jun 02 2018-11-11T00:
source share

We used jsspec jsspec . This is very nice if you like rspec and BDD. Just saw the article "> Justin Getland articles on how to use it without a head.

+1
Nov 19 '08 at 7:38
source share

To taunt JavaScript, check out qMock , a framework I wrote by a colleague to complement our use of QUnit. Although the latter is great for unit tests, it does not allow very efficient testing of asynchronous / business logic. We did not mark โ€œany releaseโ€ as stable, but there are decent documents there, and if you choose svn, you will see that qmock itself has unit tests that are reasonably clear.

Oh, and to automate testing within the assembly, we used a simple selenium script to navigate our test (one test page in a JS file) and โ€œlistenedโ€ to the CSS class with bandwidth or error (QUnit added). This works headless as well for IE / FF2 AFAIK

+1
Nov 20. '08 at 10:24
source share

For mozilla development, I fall in love with MozUnit -based UXU, but am still active. It has some nice features like mock server or sleep / yeld.

+1
Oct 30 '09 at 16:02
source share

I use the Unit test framework, and I wrote my own jsMocha mocking library , which was actively used by the company that I have been working for over 6 months.

+1
Dec 12 '09 at 23:09
source share

I know that you are requesting jQuery-compatible frameworks, but I want to drop script.aculo.us into the mix for completeness. They have a unit test , which is not bad.

0
Oct 16 '08 at 17:08
source share

CrossCheck seemed very powerful when I looked at it, but we did not include it in our build process at this time. This has an advantage without a browser, and therefore should work well in an automated build and test script.

http://thefrontside.net/crosscheck

0
Oct. 16 '08 at 18:07
source share

JsUnit is launched either from the browser, through its Eclipse plugin, or automatically through the ANT task. You create an HTML page with a bunch of test functions that should be named using the prefix 'test', including the JS file you are testing. When any statement inside a function fails, the entire function fails and stops execution. There is no guaranteed order in which these tests are performed. You can create setup() and teardown() functions.

License: GPL, GLPL, MPL

Pros

  • Automation is relatively easy to implement.
  • A lot of functionality
  • The syntax is similar to JUnit

against

  • Not suitable for testing the DOM, as it runs tests inside the iFrame.
  • There is no guarantee that the tests will be performed in the order in which they are written.
  • I can not use Firebug on the testrunner page. You need to open another tab with the actual test code.
0
Oct. 16 '08 at 18:17
source share

You can try HtmlUnit , which had a jQuery compatible release more than a year ago.

The advantage of HtmlUnit is that it does not control the browser, so it is FAST.

The downside is that it does not control the browser, so there are some JS things that won't work. But compensating that they can run JQuery tests so that JS support can be good enough for what you need.

0
Nov 19 '08 at 7:57
source share



All Articles