introduction to unit testing using qunit
DESCRIPTION
An Introduction to Unit testing, what it is, why is it needed and how it is done. Using QUnit.TRANSCRIPT
![Page 1: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/1.jpg)
Software Testing by Varun Vaddiparty
![Page 2: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/2.jpg)
● User Interface Development● Source Code● Quality Assurance (software testing)
![Page 3: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/3.jpg)
Need for software testing:
● Meets the requirements ● works as expected● satisfies the need of customer
Different Methods:● Static Testing● Dynamic Testing
![Page 4: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/4.jpg)
![Page 5: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/5.jpg)
![Page 6: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/6.jpg)
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.
![Page 7: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/7.jpg)
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.
![Page 8: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/8.jpg)
![Page 9: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/9.jpg)
A minimal Qunit test setup.
![Page 10: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/10.jpg)
The contents of test.js :
![Page 11: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/11.jpg)
Result of the test:
![Page 12: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/12.jpg)
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()
![Page 13: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/13.jpg)
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”);
![Page 14: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/14.jpg)
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”);
![Page 15: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/15.jpg)
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”);
![Page 16: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/16.jpg)
expect()
● used to check whether all the assertions have been executed or not
![Page 17: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/17.jpg)
asyncTest()
● used for asynchronous testing
Practical Example:
![Page 18: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/18.jpg)
![Page 19: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/19.jpg)
![Page 20: Introduction to Unit Testing using QUnit](https://reader034.vdocument.in/reader034/viewer/2022052321/554a4d35b4c905572f8b456e/html5/thumbnails/20.jpg)
Thank You