throwExceptionWhen
クラス: matlab.mock.TestCase
名前空間: matlab.mock
メソッドの呼び出しやプロパティの相互作用に対して例外をスロー
構文
throwExceptionWhen(testcase,behavior)
throwExceptionWhen(testcase,behavior,exception)
説明
throwExceptionWhen(
は、メソッドが呼び出された場合、またはプロパティがアクセスまたは設定された場合にモックが例外をスローすることを指定します。testcase
,behavior
)
throwExceptionWhen(
は、モックがスローする例外を指定します。testcase
,behavior
,exception
)
入力引数
例
代替方法
throwExceptionWhen
メソッドの使用は、matlab.mock.actions.ThrowException
アクションを MethodCallBehavior
クラス、PropertyGetBehavior
クラスまたは PropertySetBehavior
クラスの when
メソッドとあわせて使用するのと機能的には同じです。たとえば、次のコード ブロックは機能的に等価です。
% Using the throwExceptionWhen method testCase.throwExceptionWhen(behavior.deposit(IsLessThan(0)), ... MException('Account:deposit:Negative', ... 'Deposit amount must be positive.')); % Using the ThrowException action with the when function import matlab.mock.actions.ThrowException when(behavior.deposit(IsLessThan(0)),ThrowException( ... MException('Account:deposit:Negative', ... 'Deposit amount must be positive.')))
ThrowException
アクションを使用すると、さらに多くの機能を使用できます。たとえば、同じモック オブジェクトの相互作用に対して異なる後続の動作を指定することができます。バージョン履歴
R2017a で導入