Introduction to Unit Testing using QUnit
-
Upload
globallogic -
Category
Education
-
view
298 -
download
1
description
Transcript of Introduction to Unit Testing using QUnit
Software Testing by Varun Vaddiparty
● User Interface Development● Source Code● Quality Assurance (software testing)
Need for software testing:
● Meets the requirements ● works as expected● satisfies the need of customer
Different Methods:● Static Testing● Dynamic Testing
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.
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.
A minimal Qunit test setup.
The contents of test.js :
Result of the test:
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()
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”);
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”);
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”);
expect()
● used to check whether all the assertions have been executed or not
asyncTest()
● used for asynchronous testing
Practical Example:
Thank You