matlab.unittest.TestCase.forInteractiveUse
クラス: matlab.unittest.TestCase
パッケージ: matlab.unittest
対話型で使用するテスト ケースを作成
構文
説明
入力引数
testClass
— テスト クラス
meta.class
インスタンス
matlab.unittest.TestCase
から派生するテスト クラス。meta.class
インスタンスとして指定します。
例: ?ExampleTest
例
部分文字列のテスト
実際の値が指定された部分文字列を含むかテストします。
対話型テスト用にテスト ケースを作成します。
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 で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)