MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Overview of App Testing Framework


Use the MATLAB app testing framework to test App Designer apps, or apps built
programmatically using the uifigure function. The app testing framework lets you
author a test class that programmatically performs a gesture on a UI component, such as
pressing a button or dragging a slider, and verifies the behavior of the app.

App Testing


Test Creation – Class-based tests can use the app testing framework by subclassing
matlab.uitest.TestCase. Because matlab.uitest.TestCase is a subclass of
matlab.unittest.TestCase, your test has access to the features of the unit testing
framework, such as qualifications, fixtures, and plugins. To experiment with the app
testing framework at the command prompt, create a test case instance using
matlab.uitest.TestCase.forInteractiveUse.

Test Content – Typically, a test of an app programmatically interacts with app
components using a gesture method of matlab.uitest.TestCase, such as press or
drag, and then performs a qualification on the result. For example, a test might press one
check box and verify that the other check boxes are disabled. Or it might type a number
into a text box and verify the app correctly computes a result. These types of tests require
understanding of the properties of the app being tested. To verify a button press, you
must know where in the app object MATLAB stores the status of a button. To verify the
result of a computation, you must know how to access the result within the app.

Test Clean Up – It is a best practice to include a tear-down action to delete the app after
the test. Typically, the test method adds this action using the addTeardown method of
matlab.unittest.TestCase.

App Locking – When an app test creates a figure, the framework locks the figure
immediately to prevent external interactions with the components. The app testing
framework does not lock UI components if you create an instance of
matlab.uitest.TestCase.forInteractiveUse for experimentation at the command
prompt.

To unlock a figure for debugging purposes, use the matlab.uitest.unlock function.

Gesture Support of UI Components


The gesture methods of matlab.uitest.TestCase support various UI components.

33 Unit Testing

Free download pdf