In this lesson we described the fundamental concepts of software testing and why unit-testing your code is so important. Testing gives you more confidence that your code is working properly and that it (virtually) doesn’t have bugs.
We provided an overview of the frameworks available for unit testing JavaScript projects, focusing our attention on QUnit. This framework, maintained by the same team that offers you the lovely jQuery library, provides an easy-to-use set of methods to test your code.
After describing how to create tests with QUnit.test(), we introduced you to several assertion methods used to verify that the returned values of your functions and methods are what you expect. You also learned the importance of setting the number of assertions you expect to run through the use of the assert.expect() method.
Then you discovered how to test functions that run asynchronously—for example, those passed to JavaScript’s native function setTimeout() or to jQuery’s Ajax functions—with the help of assert.async().
Finally, you learned how to organize your test suite into modules and how to set a project-specific configuration. With all this power in your hands, you developed a complete and working test suite. Our hope is that starting from tomorrow, or even today, you’ll begin testing your code so that you can use and refactor it with more confidence.
In the next and last lesson of this app you’ll discover some useful tools that can help you employ jQuery in large projects.
Leave a Reply