Main Content

matlab.unittest.TestCase.forInteractiveUse

Class: matlab.unittest.TestCase
Package: matlab.unittest

Create test case for interactive use

Description

example

testCase = matlab.unittest.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.

example

testCase = matlab.unittest.TestCase.forInteractiveUse(testClass) creates an instance of the specified test class for interactive testing.

Input Arguments

expand all

Test class deriving from matlab.unittest.TestCase, specified as a meta.class instance.

Example: ?ExampleTest

Attributes

Statictrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Test if the actual value contains the specified substring.

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Define the actual value.

actual = "This is a long message.";

Verify that actual contains the text "long".

verifySubstring(testCase,actual,"long")
Verification passed.

Show that case matters. This test fails because actual does not contain "Long".

verifySubstring(testCase,actual,"Long","Test is case sensitive.")
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    Test is case sensitive.
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifySubstring failed.
    --> The value does not contain the substring.
    
    Actual Value:
        "This is a long message."
    Expected Substring:
        "Long"
    ------------------
    Stack Information:
    ------------------
    In C:\work\TestForSubstringsExample.m (TestForSubstringsExample) at 22

Show that the test fails if the substring is longer than the actual string.

verifySubstring(testCase,actual,"This is a long message with extra words.")
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifySubstring failed.
    --> The value does not contain the substring.
    
    Actual Value:
        "This is a long message."
    Expected Substring:
        "This is a long message with extra words."
    ------------------
    Stack Information:
    ------------------
    In C:\work\TestForSubstringsExample.m (TestForSubstringsExample) at 27

Run a Test method of a test class interactively.

In a file named ZerosTest.m in your current folder, create the ZerosTest class, which tests the zeros function.

classdef ZerosTest < matlab.unittest.TestCase
    properties (TestParameter)
        type = {'single','double','uint16'};
        size = struct("s2d",[3 3],"s3d",[2 5 4]);
    end
    
    methods (Test)
        function testClass(testCase,size,type)
            testCase.verifyClass(zeros(size,type),type)
        end
        
        function testSize(testCase,size)
            testCase.verifySize(zeros(size),size)
        end
        
        function testDefaultClass(testCase)
            testCase.verifyClass(zeros,"double")
        end
        
        function testDefaultSize(testCase)
            testCase.verifySize(zeros,[1 1])
        end
        
        function testDefaultValue(testCase)
            testCase.verifyEqual(zeros,0)
        end
    end
end

Create an instance of the ZerosTest class for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse(?ZerosTest);

Use the test case to call the testSize method interactively. The test passes.

testCase.testSize([5 10])
Verification passed.

Version History

Introduced in R2014a