2. Basic components of any UT
framework
• Test Suite
– Spects / Tests
• Assertions
– Async Tests
– Test Runner
3. What is Q-Unit ?
• Unit testing framework build for JQuery.
• Additional features
– Supports asynchronous testing.
– Can break code into modules.
– Support test timeouts.
4. Q-Unit Assertions
• Just three assertions
– equal
– ok
– deepEqual
• Some advanced keywords for asynchronous
testing.
5. “ok”
• The most basic one is ok(), which requires just
one argument.
• If the argument evaluates to true, the assertion
passes, otherwise, it fails.
• In addition, it accepts a string to display as a
message in the test results.
Syntax : ok( truthy [, message ] )
ok( true, "true succeeds" );
6. “equal”
• The equal assertion uses the simple comparison
operator (==) to compare the actual and
expected arguments.
• When they are equal, the assertion passes;
otherwise, it fails .
Syntax : equal( actual, expected [, message ] )
equal( 0,0,”Yess !! 0 is equal to 0” );
7. “deepEqual”
• The deepEqual() assertion can be used just like
equal().
• Instead of the simple comparison operator (==), it
uses the more accurate comparison operator (===).
• When they are (deep)equal, the assertion passes;
otherwise, it fails .
Syntax : deepEqual( actual, expected [, message ] )
deepEqual( 0,0,”Yess !! 0 is equal to 0” );
8. Test for Synchronous Callbacks
• special assertion to define the number of
assertions a test contains in advance.
• When the test completes without the correct
number of assertions, it will fail, no matter
what result the other assertions.
9. Spyes or Mocks
• QUnit doesn't have spies or mocks. But you
can use the Sinon.JS mocking framework
• http://sinonjs.org/qunit/
• http://blog.building-blocks.com/javascript-
unit-testing-with-qunit-and-sinon-js
• http://cjohansen.no/en/javascript/using_sino
n_js_with_qunit