This document discusses JavaScript unit testing and introduces the QUnit testing framework. It demonstrates how to write testable code, set up a basic testing file with QUnit, and run tests to validate code works as expected across browsers. Automating testing with tools like Phing is also presented to speed the testing process without using a browser. Cross-browser testing challenges are noted along with alternatives to browser-based testing for greater speed.
2. How do you test your JS?
1. Write your JavaScript code
2. See if it works in your favourite browser
3. Change something + [F5]
4. If it doesn't work repeat #3 until you make it work
or you go crazy...
5. In case you made it work, discover few
days/weeks later that it doesn't work in another
browser
15. Now what about testing?
Popular JS Unit-testing frameworks:
?
QUnit
?
Jasmine
?
UnitJS
?
JsUnit (no longer actively maintained)
?
Some other ¨C see:
http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript
16. What's about QUnit?
?
Used by the jQuery project to test jQuery, jQuery
UI, jQuery Mobile
?
Can be used to test any generic JavaScript
code, including itself
?
Very easy to install ¨C just include JS & CSS
file in your HTML