Skip to content

Latest commit

 

History

History
90 lines (53 loc) · 2.43 KB

Creating_a_QUnit_Test_7080029.md

File metadata and controls

90 lines (53 loc) · 2.43 KB
loio
708002929ea548fd9433954a9275eb5f

Creating a QUnit Test


Prerequisites

As a prerequisite for creating a test, you need to have created a OpenUI5 application project that contains a test suite. For more information on how to do this, see Concept and Basic Setup. After completing this, continue with the steps described in the subsequent sections.


Creating a Test Module

Create a file MyTest.qunit.js in the folder webapp/test/unit.

Note:

You can use the file template shown in the following example. This code snippet shows a basic QUnit test template.

Each test file normally represents a OpenUI5 module, which is being tested.

/*global QUnit */
sap.ui.define([], function() {
  "use strict";

  QUnit.module("Module A"); 

  QUnit.test("Basic test example", function(assert) {
    assert.ok(true, "this test is fine"); 
    var value = "hello1"; 
    assert.equal(value, "hello1", "We expect value to be 'hello1'"); 
  });

});

QUnit test files do not include the OpenUI5 bootstrap (sap-ui-core.js). Instead, the test starter ensures that the QUnit tests are loaded within an HTML page.


In order to run a QUnit test, the corresponding module needs to be added to a test suite.


sap.ui.define(function() {
	"use strict";

	return {

		// ...

		tests: {
			"unit/MyTest": {
				title: "Unit tests for <NAMESPACE>"
			},
		}
	};
});

Open the test suite html file in your desired browser to run the newly created test module.

Related Information

QUnit Home Page

Testing Tutorial