Main Content

matlab.mock.constraints.WasAccessed 클래스

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

속성 get 액세스를 결정하는 제약 조건

설명

WasAccessed 제약 조건은 실제 값이 PropertyBehavior 인스턴스가 아니거나 PropertyBehavior에 해당하는 속성이 지정된 횟수만큼 액세스되지 않은 경우 가설 검정(Qualification) 실패를 생성합니다.

속성 액세스 횟수에는 MATLAB®이 이 속성에 묵시적으로 액세스하는 횟수가 포함됩니다. 예를 들어, 모의 객체를 표시하는 경우 MATLAB은 이 객체 속성에 액세스하여 해당 값을 표시합니다.

생성

constraint = WasAccessed는 속성 get 액세스를 결정하는 제약 조건을 제공합니다. 속성에 한 번 이상 액세스한 경우 이 제약 조건이 충족됩니다. 속성에 액세스되지 않았음을 가설 검정하려면 물결표(~) 연산자로 WasAccessed 제약 조건을 부정하십시오.

constraint = WasAccessed('WithCount',n)은 속성에 정확히 n번 액세스했을 때 충족되는 제약 조건을 제공합니다.

이 구문으로 WasAccessed를 부정하는 경우 속성에 정확히 n번 액세스하지 않았다면 이 제약 조건을 통과합니다. 예를 들어, 속성에 4번 액세스한 경우 ~WasAccessed('WithCount',3)은 통과하고 ~WasAccessed('WithCount',4)는 실패합니다.

입력 인수

모두 확장

속성 get 액세스 횟수로, 정수로 지정됩니다.

속성

모두 확장

속성 액세스 횟수로, 정수로 반환됩니다. 이 속성은 일단 제약 조건이 생성되면 읽기 전용입니다. 제약 조건을 생성할 때 이 속성을 지정할 수 있습니다.

복사 의미 체계

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

예제

모두 축소

사람 클래스에 대한 모의 객체를 만듭니다.

testCase = matlab.mock.TestCase.forInteractiveUse;
[fakePerson,behavior] = testCase.createMock('AddedProperties',["Name" "Age"]);
fakePerson.Name = 'David';
fprintf(1,'The person''s name is %s.\n',fakePerson.Name);
The person's name is David.

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

import matlab.mock.constraints.WasAccessed
testCase.verifyThat(behavior.Name,WasAccessed)
Interactive verification passed.
testCase.verifyThat(behavior.Age,~WasAccessed)
Interactive verification passed.
testCase.verifyThat(behavior.Name,WasAccessed('WithCount',1))
Interactive verification passed.

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

testCase.verifyThat(behavior.Name,~WasAccessed)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
Negated WasAccessed failed.
--> Property 'Name' was unexpectedly accessed 1 time(s).

Specified property access:
    PropertyGetBehavior
        <Mock>.Name
testCase.verifyThat(behavior.Age,WasAccessed)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasAccessed failed.
--> Property 'Age' was never accessed.

Specified property access:
    PropertyGetBehavior
        <Mock>.Age
testCase.verifyThat(behavior.Name,WasAccessed('WithCount',5))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasAccessed failed.
--> Property 'Name' was not accessed the expected number of times.
    
    Actual property access count:
             1
    Expected property access count:
             5

Specified property access:
    PropertyGetBehavior
        <Mock>.Name

버전 내역

R2017a에 개발됨