Performing Unit Tests with Qunit


After completing this lesson, you will be able to:

  • Run unit tests with Qunit

Unit Test with QUnit

Watch this short video to learn about unit testing.

The following figure provides an overview of QUnit.

QUnit is a JavaScript unit and integration test framework. It is capable of testing any generic JavaScript code, the framework supports asynchronous tests out-of-the-box. It can be found at the following:

QUnit Test Example

QUnit uses a set of top-level functions to provide semantic meaning in unit tests.

Just like most of the unit test frameworks, it follows an arrange-act-assert pattern, a common test pattern employed during unit testing. Its purpose is to make a clear distinction between the set up for the test, the action that is to be tested, and the evaluation of the results.

Let's take a look at the important constructs.

Test Page

The following figure shows the code for an app that is about to be tested.

Use the following interaction to learn about the test folder of an SAPUI5 project that is generated by SAP Business Application Studio, the details related to setting it up, and some examples.

Configuration of Unit Test Run

When you are using the SAPUI5 project template, which is provided by SAP Business Application Studio, all relevant aspects are generated to start the application under test mode using the unitTests.qunit.html file located in the unit-subfolder. To launch the application under the test start, Preview Application, from the menu in the project explorer of SAP Business Application Studio, or to open the file package.json located in the project, hover over the unit-tests-script and choose start script.

Results of Unit Test Run

When the unit test is fully complete, a results screen is displayed. The following figure shows the results of the unit test run.

Log in to track your progress & complete quizzes