Video length is 3:21

Getting Started with App Testing in MATLAB

Get started with App Testing in MATLAB by walking through an example. You’ll learn the basics of what app testing in MATLAB is like through resources such as:

Be walked through how to test an app using the app testing framework. You will see how to simulate different gestures and how to verify whether they worked or not. You will also learn how to create tests from scratch.

Published: 12 Feb 2024

In the age where apps are making human lives easier and better, MATLAB is here to help you design modern and fully featured apps. To get started with the app building in MATLAB, go to the link in the description below.

You designed your cool app and got everything ready. But is it ready to go out yet? Well, if it is a code file, we can do automated unit testing to reassure that everything's working as expected. The good news is that app testing need not be manual.

By the end of this video, you will see how to create automated UI tests and know about the gestures you can simulate using this.

MATLAB documentation has an example app that I will be using in this video. A link to this page is in the description. By clicking on “open in MATLAB online”, the app is opened in a new tab in MATLAB online.

In the command window, type the app name to open an instance of it. Lets type PatientsDisplay. This is the app we will be using for our testing. Let’s go ahead and test some of it by using the app testing framework and unit testing framework.

Start by creating a file with an appropriate name and .m extension in your current folder. Now create a test class that derives from matlab.uitest.TestCase and add properties for this. App is the only property we will use in this example.

For every test, to create an instance of the app at the start and close it at the end, we use test method setup and pass in testcase as an input parameter.

We can now start creating our test methods. I would like to check if a user is able to choose the Data tab or not. testcase.choose will help us perform the choosing action in the test. To verify that this action took place, we will use verify equal to compare the active tab with “Data.”

Let’s run the test. The blue dot highlights the clicking action when the test is running. This makes it easier to know where the action is happening.

One thing to note here is that we are trying to simulate human behavior. If there is something hiding the button, the action cannot happen as users cannot click it unless they see it.

In this next test, to the scatter plot with male data we are trying to add female data and using verify equal to verify it.

Let’s run this test. The command window shows that it’s completed. We see that our test failed during verification. Let’s correct the test. After making necessary changes, we can rerun the test from the command window itself.

With the help of run tests button, we can run all the tests at once.

You can simulate different gestures of the UI components in your app. Here is a table detailing the list of components and the gestures that can be tested using app testing in MATLAB. The link to this is also provided in the description.

Happy testing!

Related Products