throwExceptionWhen
클래스: matlab.mock.TestCase
패키지: matlab.mock
메서드 호출 또는 속성 상호 작용에 대한 예외 발생시키기
구문
throwExceptionWhen(testcase,behavior)
throwExceptionWhen(testcase,behavior,exception)
설명
throwExceptionWhen(
는 메서드가 호출되거나 속성이 액세스 또는 설정되면 모의 객체가 예외를 발생시키도록 지정합니다.testcase
,behavior
)
throwExceptionWhen(
은 모의 객체가 발생시키는 예외를 지정합니다.testcase
,behavior
,exception
)
입력 인수
예제
대안
throwExceptionWhen
메서드를 사용하는 것은 MethodCallBehavior
, PropertyGetBehavior
또는 PropertySetBehavior
클래스의 when
메서드와 함께 matlab.mock.actions.ThrowException
동작을 사용하는 것과 기능적으로 동일합니다. 예를 들어, 다음 코드 블록들은 기능적으로 동일합니다.
% 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에 개발됨