unit testing modular javascript
I am currently deriving a javascript framework pattern as an architecture for the client side development for an upcoming large scale application that I will developing.
I am looking to go with a module observer pattern in which each control I develop will have its own javascript file, holding no knoweldge of the other controls.
From designing this framework for my application, I am looking to integrate in a testing mechanism for my modules - a unit testing mechanism for javascript. I am not aware of any such frameworks or how I may set up such. Any suggestions?
As part of such testing, I will also need to mock up http requests.
The li开发者_StackOverflow社区brary I will be using in development is jquery.
The JQuery team has QUnit.
As for abstracting out AJAX, you should wrap it appropriately or just test the data manipulation methods.
Jasmine may be what you are looking for. It has built-in mock up support, and does not rely on any other frameworks.
They also have a separate module for faking AJAX responses.
The setup is simple. Just download the standalone version, write some testing suites, and view the SpecRunner.html in a browser.
Consider using JsTestDriver to run your JS tests. The main benefit it provides - it can run your tests on continuous integration environment, which is essential for unit testing practice.
Some additional features:
- It can be used along with QUnit and other testing frameworks.
- It can execute your tests in parallel across multiple browser.
- It supports calculation code coverage.
List of mocking libraries you can find in another thread.
BoilerplateJS is a reference architecture for large scale JavaScript product development. You can find the tests which are written using qunit, sinon and testr included under the tests folder.
精彩评论