Using QUnit, YUI Test and JSTestDriver for Javascript Unit Testing

The increased complexity of browser-executed code has increased the need to write unit test cases for JavaScript code. This article describes some of the most common tools for unit testing JavaScript: QUnit, YUI Test and JSTestDriver. The learning curve can be steep if you do not typically write tests for client-side scripting and testing the user interface could require adjustments in your thought process. This article provides code examples that will walk you through sample test cases.

QUnit is a powerful, easy-to-use, JavaScript test suite developed by the jQuery project to test its code and plugins. It is capable of testing any generic JavaScript code and even capable of testing JavaScript code on the server-side.

YUI Test is a complete testing framework for JavaScript and Web applications. You can use the simple JavaScript syntax to write unit tests that can be run in web browsers or on the command line, as well as functional tests to be run in web browsers. Additional tools that build on top of the JavaScript library’s core functionality allow integration with build systems.

JsTestDriver aims to help javascript developers use good TDD practices and aims to make writing unit tests as easy as what already exists today for java with JUnit.