Main Content

matlab.uitest.TestCase.forInteractiveUse

Class: matlab.uitest.TestCase
Package: matlab.uitest

Create a TestCase object for interactive use

Description

example

tc = matlab.uitest.TestCase.forInteractiveUse creates a matlab.uitest.TestCase instance for interactive use. The TestCase is configured so you can experiment with it at the MATLAB® command prompt. The TestCase reacts to qualification failures and successes by displaying messages to the screen for both passing and failing conditions.

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