Main Content

matlab.mock.AnyArguments 클래스

네임스페이스: matlab.mock

인수의 개수 일치

설명

AnyArguments 클래스를 사용하여, 모의 동작을 지정하거나 모의 상호 작용을 가설 검정(Qualification)할 때 인수의 개수를 일치시킵니다.

생성

AnyArguments는 0을 포함한 무제한의 지정되지 않은 인수 개수를 일치시킵니다. 모의 동작을 정의하거나 모의 상호 작용을 가설 검정할 때 AnyArguments를 인수 목록의 마지막 인수로 지정하십시오.

복사 의미 체계

값입니다. 값 클래스가 복사 작업에 미치는 영향에 대한 내용은 객체 복사 항목을 참조하십시오.

예제

모두 축소

인수의 개수를 일치시킵니다.

import matlab.mock.AnyArguments
import matlab.mock.actions.ThrowException

testCase = matlab.mock.TestCase.forInteractiveUse;

% Create a mock for a bank account class
[saboteurAccount,behavior] = testCase.createMock('AddedMethods',"deposit");

% Define behavior to throw exception with any input argument
when(behavior.deposit(AnyArguments),ThrowException)

% All of the following interactions throw an exception:
saboteurAccount.deposit;
saboteurAccount.deposit(-10);
saboteurAccount.deposit(10);
saboteurAccount.deposit('a','b','c');

대안

AnyArguments 클래스는 matlab.mock.MethodCallBehavior 클래스의 withAnyInputs 메서드를 사용하는 것과 기능적으로 유사합니다. 예를 들어, 다음 코드 블록은 서로 유사합니다.

% Using the AnyArguments class
import matlab.mock.AnyArguments;
testCase.verifyCalled(behavior.myMethod(AnyArguments));

% Using the withAnyInputs method
testCase.verifyCalled(withAnyInputs(behavior.myMethod))
그러나 AnyArguments에서는 모의 객체가 첫 번째 입력 인수여야 하지만, withAnyInputs에서는 그렇지 않습니다. MethodCallBehavior 클래스는 동작을 지정하고 상호 작용(예: 정확한 입력값의 지정 또는 출력값의 수)을 기록하는 추가적인 메서드를 제공합니다.

버전 내역

R2017a에 개발됨