QUnit - Overview


Testing is the process of checking the functionality of the application whether it is working as per the requirements and to ensure that at the developer level, unit testing comes into picture. Unit testing is the testing of a single entity (class or method). Unit testing is very essential for every software organization to offer quality products to their clients.

Unit testing can be done in two ways as mentioned in the following table.

Manual testing Automated testing
Executing the test cases manually without any tool support is known as manual testing. Taking tool support and executing the test cases using automation tool is known as automation testing.
Time consuming and tedious. Since the test cases are executed by human resources, it is very slow and tedious. Fast Automation. Runs test cases significantly faster than human resources.
Huge investment in human resources. As test cases need to be executed manually, more number of testers are required. Less investment in human resources. Test cases are executed using automation tool hence, less number of testers are required.
Less reliable, as tests may not be performed with precision each time due to human errors. More reliable. Automation tests perform precisely the same operation each time they are run.
Non-programmable. No programming can be done to write sophisticated tests, which fetch hidden information. Programmable. Testers can program sophisticated tests to bring out hidden information.

What is QUnit?

QUnit is a unit testing framework for JavaScript programming language. It is important in the test driven development, and is used by jQuery, jQuery UI, and jQuery Mobile projects. QUnit is capable of testing any generic JavaScript codebase.

QUnit promotes the idea of "first testing then coding", which emphasizes on setting up the test data for a piece of code, which can be tested first and then implemented. This approach is like "test a little, code a little, test a little, code a little..." which increases the programmer’s productivity and the stability of program code reducing the programmer’s stress and the time spent on debugging.

Features of QUnit

QUnit is an open source framework used for writing and running tests. Following are its most prominent features −

  • QUnit provides Assertions for testing expected results.

  • QUnit provides Test fixtures for running tests.

  • QUnit tests allow to write code faster, which increases the quality.

  • QUnit is elegantly simple. It is less complex and takes less time.

  • QUnit tests can be run automatically and they check their own results and provide immediate feedback. There's no need to manually comb through a report of test results.

  • QUnit tests can be organized into test suites containing test cases and even other test suites.

  • QUnit shows test progress in a bar that is green if the test is going fine, and it turns red when a test fails.

What is a Unit Test Case?

A Unit Test Case is a part of code which ensures that another part of the code (method) works as expected. To achieve the desired results quickly, test framework is required. QUnit is a perfect unit test framework for JavaScript programming language.

A formal written unit test case is characterized by a known input and by an expected output, which is worked out before the test is executed. The known input should test a precondition and the expected output should test a post-condition.

There must be at least two unit test cases for each requirement: one positive test and one negative test. If a requirement has sub-requirements, each sub-requirement must have at least two test cases as positive and negative.