throwExceptionWhen
Class: matlab.mock.TestCase
Namespace: matlab.mock
Throw exception for method call or property interaction
Syntax
throwExceptionWhen(testcase,behavior)
throwExceptionWhen(testcase,behavior,exception)
Description
Input Arguments
Examples
Alternatives
Using the throwExceptionWhen
method is functionally
equivalent to using the matlab.mock.actions.ThrowException
action
with the when
method of the MethodCallBehavior
, PropertyGetBehavior
,
or PropertySetBehavior
class. For example, the following
code blocks are functionally equivalent.
% 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
action.
For instance, you can specify different subsequent behavior for the
same mocked object interaction.Version History
Introduced in R2017a