matlab.uitest.TestCase class

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

TestCase to write tests with app testing framework

Description

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.

Construction

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

Methods

choosePerform choose gesture on UI component
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
applyFixtureUse fixture with TestCase
forInteractiveUseCreate TestCase for interactive use
getSharedTestFixturesProvide access to shared test fixtures
logRecord diagnostic information
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

Attributes

Abstracttrue
HandleCompatibiletrue

For information on class attributes, see Class Attributes.

Copy Semantics

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

Examples

collapse all

Create a discrete knob.

knob = uiknob('discrete');

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;
tc.choose(knob,'High')

View the value of the Items property on the knob.

knob.Items
ans =

  1×4 cell array

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

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

tc.choose(knob,2)

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;
tc.verifyFalse(b.Value)
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.

tc.press(b)
tc.verifyTrue(b.Value)
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;
tc.verifyEqual(slider.Value,7)
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;
tc.drag(slider,-val,val)
tc.verifyEqual(slider.Value,val,'AbsTol',0.1)
Verification passed.

Introduced in R2018a