matlab.uitest.TestCase class

Package: matlab.uitest
Superclasses: matlab.unittest.TestCase

TestCase to write tests with app testing framework


Use the matlab.uitest.TestCase class to write tests that use the app testing framework. The matlab.uitest.TestCase derives from the matlab.unittest.TestCase class.

To avoid user interference with the app during testing, the framework locks new figure instances. The components of locked figures only respond to programmatic gestures via TestCase methods such as press and choose.


The testing framework constructs the matlab.uitest.TestCase instances.


choosePerform choose gesture on UI component
chooseContextMenu Perform choose gesture on context menu item
dragPerform drag gesture on UI component
forInteractiveUseCreate a TestCase object for interactive use
hoverPerform hover gesture on UI component
pressPerform press gesture on UI component
typeType in UI component

Inherited Methods

addTeardownDynamically add teardown routine to TestCase instance
applyFixtureUse fixture with TestCase
forInteractiveUseCreate TestCase for interactive use
getSharedTestFixturesProvide access to shared test fixtures
logRecord diagnostic information during test execution
onFailureDynamically add diagnostics for test failures
runRun TestCase test

Also, the TestCase class inherits methods from these classes:

matlab.unittest.qualifications.AssertableQualification to validate preconditions of a test
matlab.unittest.qualifications.AssumableQualification to filter test content
matlab.unittest.qualifications.FatalAssertableQualification to abort test execution
matlab.unittest.qualifications.VerifiableQualification to produce soft failure conditions



For information on class attributes, see Class Attributes.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.


collapse all

Create a discrete knob.

knob = uiknob('discrete');

A figure with a discrete knob. The knob value is 'Off'.

Create an interactive test case and choose the 'High' knob value. An animated blue dot performs the programmatic choose gesture.

tc = matlab.uitest.TestCase.forInteractiveUse;

A figure with a discrete knob. The knob value is 'High'.

View the value of the Items property on the knob.

ans =

  1×4 cell array

    {'Off'}    {'Low'}    {'Medium'}    {'High'}

Choose the 'Low' knob value by index. The knob moves from 'High' to 'Low'.


A figure with a discrete knob. The knob value is 'Low'.

Create a state button.

b = uibutton('state');

Create an interactive test case and verify that the value of the state button is false.

tc = matlab.uitest.TestCase.forInteractiveUse;
Verification passed.

Press the button and verify the state changes to true. A blue dot representing the programmatic push gesture appears and then disappears on the button.
Verification passed.

Create a slider with a minimum value of -237, a maximum value of 237, and a starting value of 7.

slider = uislider('Limits',[-237 237],'Value',7);

Create an interactive test case and verify the initial value of the slider.

tc = matlab.uitest.TestCase.forInteractiveUse;
Verification passed.

Drag the slider between two values and verify the final value. Since the framework mimics a user manipulating the component to an arbitrarily precisioned value, it is a best practice to use a tolerance to compare the actual and expected slider values.

val = 26.75;
Verification passed.
Introduced in R2018a