Let's get started
Learning QUnit at first might be overwhelming. But once you learn that its' API has only 14 methods (and some of them are just negation of others, e.g.
notEqual()), the learning process gets more manageable and easy. Here is an overview of those 14 methods mentioned above:
- 8 assertions (
- 3 assertion organisation methods, also known as test suites in other unit testing frameworks (
- 3 helper methods to test async methods, such as AJAX, setTimeout(), callbacks, etc. (
This out of the way, we are ready to learn QUnit.
Here are 4 steps that will (1) introduce you to unit testing and QUnit, (2) cover all API methods, (3) show and discuss some common testing scenarios and (4) see how others are using it:
- Read an Introduction to unit testing. The article introduces the idea of unit testing and sets the stage to and introduces QUnit. - 20 min
- Go through those 14 methods we talked about above (assert, async assert, test). The API explanations are very short and to the point. - 30 min
- Read and examine some tests on GitHub: - 30 min
PS. In upcoming posts we will cover other testing frameworks such as Mocha and Jasmine (has syntax that resembles Ruby's rspec), object stubbing and mocking with Sinon.JS, and some alternatives to assertions with Chai. Also, to make coding more pleasant we'll cover CoffeeScript as well. So stay tuned: Like us on Facebook, follow on Twitter or subscribe to RSS.