cancel
Showing results for 
Search instead for 
Did you mean: 

QUnit testing for SAP UI5 apps

Former Member
0 Kudos

Hi All,

I am trying to implement QUnit testing for my UI5 app. As mentioned in some articles I have created my test.js file to write all the test cases, one qunit.html file for bootstrapping libraries including test.js and mycontroller.js files. All my functionalities are in mycontroller.js which I want to test.

Now my issue is, when I am trying to test the methods which are directly written inside other JS files, I am able to do that but when I am trying to test methods of controller file, its shows me method is undefined.

I suspect the reason is my controller has following structure.And when I am trying to access the method using "MyController.myMethod" the test.js file is not able to catch the method.

MyController.js

sap.ui.controller("MyController", {

myMethod: function(){}

}

test.js

QUnit.test( "Sample test", function(  ) {

      ok(MyController.myMethod, "Employee type Test Passed!" );

});

Can you please suggest a way how we can access methods of controller file?

Regards,

Anupriya

Accepted Solutions (0)

Answers (2)

Answers (2)

saivellanki
Active Contributor
0 Kudos

Hi Anupriya,

Did you check this blog?  

Scroll down the blog and there is a section as Unit Testing the Application, controller code testing is also mentioned.

Regards,

Sai Vellanki.

Former Member
0 Kudos

Have you loaded your controller in the test.js before you start with the Quint ? you can either do,


jQuery.sap.require("path-of-controller");

or the AMD style


sap.ui.require(["path/of/controller"],

                     

                   function(MyController){

     //Quint code

});

- Sakthivel

Former Member
0 Kudos

Hi,

Thanks for the response.

Yes I have already done that but its not able to access the method . As the structure of the controller file is

sap.ui.controller("MyController", {

     myMethod: function(){}

}

And I am not able to directly access the method using name_of_controller.method_name().

In normal JS files, the structure will be something like this:


jQuery.sap.declare("file");


MyTestFile = {

      myMethod: function(employeeID){

}}


In this case we can directly access method using dot operator.


But that is not happening in controller's case.


Regards,

Anupriya