Main Content

matlab.mock.constraints.WasCalled 클래스

네임스페이스: matlab.mock.constraints

메서드 호출을 결정하는 제약 조건

설명

WasCalled 제약 조건은 실제 값이 MethodCallBehavior 인스턴스가 아니거나 MethodCallBehavior에 해당하는 메서드가 지정된 횟수만큼 호출되지 않은 경우 가설 검정(Qualification) 실패를 생성합니다.

생성

constraint = WasCalled는 메서드 호출을 결정하는 제약 조건을 제공합니다. 메서드가 한 번 이상 호출된 경우 이 제약 조건이 충족됩니다. 메서드가 호출되지 않았음을 가설 검정하려면 물결표(~) 연산자로 WasCalled 제약 조건을 부정하십시오.

constraint = WasCalled('WithCount',n)은 메서드가 정확히 n번 호출되면 충족되는 제약 조건을 제공합니다.

이 구문으로 WasCalled를 부정하는 경우 메서드가 정확히 n번 호출되지 않았다면 이 제약 조건을 통과합니다. 예를 들어, 메서드가 4번 호출된 경우 ~WasCalled('WithCount',3)은 통과하고, ~WasCalled('WithCount',4)는 실패합니다.

입력 인수

모두 확장

메서드 호출 횟수로, 정수로 지정됩니다.

속성

모두 확장

메서드가 호출된 횟수로, 정수로 반환됩니다. 이 속성은 읽기 전용입니다. 제약 조건을 생성할 때 이 속성을 지정할 수 있습니다.

복사 의미 체계

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

예제

모두 축소

은행 계좌 클래스에 대한 모의 객체를 만듭니다.

testCase = matlab.mock.TestCase.forInteractiveUse;
[fakeAccount,behavior] = testCase.createMock('AddedMethods',"deposit");

모의 계정을 사용합니다.

fakeAccount.deposit(10);
fakeAccount.deposit(20);
fakeAccount.deposit(10);

통과 케이스를 생성합니다.

import matlab.mock.constraints.WasCalled
testCase.verifyThat(behavior.deposit(10),WasCalled)
Interactive verification passed.
testCase.verifyThat(behavior.deposit(10),WasCalled('WithCount',2))
Interactive verification passed.
import matlab.unittest.constraints.IsGreaterThan
testCase.verifyThat(behavior.deposit(IsGreaterThan(100)),~WasCalled)
Interactive verification passed.

실패 케이스를 생성합니다.

testCase.verifyThat(behavior.deposit(100),WasCalled);
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasCalled failed.
--> Method 'deposit' was not called with the specified signature.
--> Observed method call(s) with any signature:
        deposit([1×1 matlab.mock.classes.Mock], 10)
        deposit([1×1 matlab.mock.classes.Mock], 20)
        deposit([1×1 matlab.mock.classes.Mock], 10)

Specified method call:
    MethodCallBehavior
        [...] = deposit(<Mock>, 100)
testCase.verifyThat(behavior.deposit(20),WasCalled('WithCount',2))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasCalled failed.
--> Method 'deposit' was not called the expected number of times with the specified signature.
    
    Actual method call count:
             1
    Expected method call count:
             2
--> Observed method call(s) with any signature:
        deposit([1×1 matlab.mock.classes.Mock], 10)
        deposit([1×1 matlab.mock.classes.Mock], 20)
        deposit([1×1 matlab.mock.classes.Mock], 10)

Specified method call:
    MethodCallBehavior
        [...] = deposit(<Mock, 20)
testCase.verifyThat(behavior.deposit(IsGreaterThan(50)),WasCalled)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasCalled failed.
--> Method 'deposit' was not called with the specified signature.
--> Observed method call(s) with any signature:
        deposit([1×1 matlab.mock.classes.Mock], 10)
        deposit([1×1 matlab.mock.classes.Mock], 20)
        deposit([1×1 matlab.mock.classes.Mock], 10)

Specified method call:
    MethodCallBehavior
        [...] = deposit(<Mock>, <IsGreaterThan constraint>)

버전 내역

R2017a에 개발됨