Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Unit Testing using QUnit


Published on

An Introduction to Unit testing, what it is, why is it needed and how it is done. Using QUnit.

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Introduction to Unit Testing using QUnit

  1. 1. Software Testing by Varun Vaddiparty
  2. 2. ● User Interface Development ● Source Code ● Quality Assurance (software testing)
  3. 3. Need for software testing: ● Meets the requirements ● works as expected ● satisfies the need of customer Different Methods: ● Static Testing ● Dynamic Testing
  4. 4. Unit Testing ● Verify the functionality of specific section of the code. ● Usually at the function level. ● To ensure that a specific function is working as expected.
  5. 5. Qunit ● A Javascript unit testing framework. ● It can be used to test any generic Javascript code. ● You can test your code in the browser itself.
  6. 6. A minimal Qunit test setup.
  7. 7. The contents of test.js :
  8. 8. Result of the test:
  9. 9. Asserting Results ● Essential elements of any unit tests. ● You express the result expected and have the testing framework compare them to the actual values that the functions output. Qunit provides three assertions: ● ok() ● equal() ● deepEqual()
  10. 10. ok() ● ok(truthy,[message]) ● most basic assertion ● requires only one argument, in addition you can send a string to show as a message examples: ok(true,”true succeeds”); ok(1==1,”test passed”);
  11. 11. equal() ● equal(actual,expected,[message]); ● compares your expected value with the actual value examples: equal(1,1,”1 equals 1, test passes”); equal(“”,0,”zero equals empty, test passes”);
  12. 12. deepEqual() ● deepEqual(actual,expected,[message]); ● can be used just like equal, is a better choice ● uses more accurate comparison operator (===) instead of simple (==) examples: deepEqual(0,””,”test fails, zero not equal to empty”);
  13. 13. expect() ● used to check whether all the assertions have been executed or not
  14. 14. asyncTest() ● used for asynchronous testing Practical Example:
  15. 15. Thank You