Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

matlab.unittest.TestCase.forInteractiveUse

クラス: matlab.unittest.TestCase
名前空間: matlab.unittest

対話型で使用するテスト ケースを作成

説明

testCase = matlab.unittest.TestCase.forInteractiveUse は、対話型テスト用に構成されたテスト ケースを作成します。返される TestCase インスタンスはコマンド プロンプトでの実験に適しています。パスと失敗の両方のイベントについて、画面にメッセージを出力して検定に反応します。

testCase = matlab.unittest.TestCase.forInteractiveUse(testClass) は、指定されたテスト クラスの対話型テスト用のインスタンスを作成します。

入力引数

すべて展開する

matlab.unittest.TestCase から派生するテスト クラス。meta.class インスタンスとして指定します。

例: ?ExampleTest

属性

Statictrue

メソッドの属性の詳細については、メソッドの属性を参照してください。

すべて展開する

実際の値が指定された部分文字列を含むかテストします。

対話型テスト用にテスト ケースを作成します。

testCase = matlab.unittest.TestCase.forInteractiveUse;

実際の値を定義します。

actual = "This is a long message.";

actual にテキスト "long" が含まれていることを検証します。

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

大文字と小文字の区別が重要であることを示します。このテストは、actual"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

部分文字列が実際の文字列より長い場合にテストが失敗することを示します。

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

テスト クラスの Test メソッドを対話形式で実行します。

現在のフォルダー内の ZerosTest.m という名前のファイルに、関数 zeros をテストする ZerosTest クラスを作成します。

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

対話型テスト用に ZerosTest クラスのインスタンスを作成します。

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

テスト ケースを使用して testSize メソッドを対話形式で呼び出します。テストはパスします。

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

バージョン履歴

R2014a で導入