Main Content

matlab.uitest.TestCase.forInteractiveUse

Class: matlab.uitest.TestCase
Namespace: matlab.uitest

Create test case for interactive use

Description

example

testCase = matlab.uitest.TestCase.forInteractiveUse creates a test case configured for interactive testing. The returned TestCase instance is suited for experimentation at the command prompt. It reacts to qualifications by printing messages to the screen for both passing and failing events.

Attributes

Statictrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a red lamp component that changes to green when a button is pressed.

fig = uifigure;
lamp = uilamp(fig,'Position',[50 100 20 20],'Color','red');
button = uibutton(fig,'ButtonPushedFcn',@(btn,event) set(lamp,'Color','green'));

Create a TestCase object configured for interactive use at the MATLAB® command prompt.

tc = matlab.uitest.TestCase.forInteractiveUse;

Press the button.

tc.press(button)

Verify the lamp color is green. This test fails because the lamp stores color as an RGB triplet.

tc.verifyEqual(lamp.Color,'green')
Verification failed.

---------------------
Framework Diagnostic:
---------------------
verifyEqual failed.
--> Classes do not match.
    
    Actual Class:
        double
    Expected Class:
        char

Actual Value:
     0     1     0
Expected char:
    green

Verify the lamp color is the RGB triplet for green.

tc.verifyEqual(lamp.Color,[0 1 0])
Verification passed.

Version History

Introduced in R2018a