Main Content

matlab.mock.constraints.WasSet 클래스

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

속성 set 상호 작용을 결정하는 제약 조건

설명

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

생성

constraint = WasSet은 속성 set 상호 작용을 결정하는 제약 조건을 제공합니다. 속성값이 한 번 이상 설정된 경우 이 제약 조건이 충족됩니다. 속성이 설정되지 않았음을 가설 검정하려면 물결표(~) 연산자로 WasSet 제약 조건을 부정하십시오.

constraint = WasSet(Name,Value)는 하나 이상의 Name,Value 쌍 인수로 지정된 추가 옵션이 있는 제약 조건을 제공합니다. 예를 들어, WasSet('ToValue',42)는 속성값이 42로 설정되는 경우 충족되는 제약 조건을 생성하며, WasSet('ToValue',42,'WithCount',3)은 속성값이 42로 정확히 3번 설정되는 경우 충족되는 제약 조건을 생성합니다.

입력 인수

모두 확장

이름-값 인수

선택적 인수 쌍을 Name1=Value1,...,NameN=ValueN으로 지정합니다. 여기서 Name은 인수 이름이고 Value는 대응값입니다. 이름-값 인수는 다른 인수 뒤에 와야 하지만, 인수 쌍의 순서는 상관없습니다.

R2021a 이전 릴리스에서는 쉼표를 사용하여 각 이름과 값을 구분하고 Name을 따옴표로 묶으십시오.

지정된 속성값으로, 스칼라, 벡터, 행렬 또는 다차원 배열로 지정됩니다. 값은 임의의 데이터형일 수 있으며, behavior로 지정된 속성과 관련됩니다.

예: 'Joe'

예: [1 2 3;4 5 6]

속성이 설정된 횟수로, 정수로 지정됩니다.

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

예: 5

속성

모두 확장

속성값으로, 스칼라, 벡터, 행렬 또는 다차원 배열로 지정됩니다. 값은 임의의 데이터형일 수 있으며, behavior로 지정된 속성과 관련됩니다.

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

복사 의미 체계

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

예제

모두 축소

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

testCase = matlab.mock.TestCase.forInteractiveUse;
[fakePerson,behavior] = testCase.createMock('AddedProperties',["Name" "Age"]);

모의 객체를 사용합니다.

fakePerson.Name = 'David';

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

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

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

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

---------------------
Framework Diagnostic:
---------------------
Negated WasSet failed.
--> Property 'Name' was unexpectedly set to the specified value 1 time(s).
--> Observed property set(s) to any value:
        <Mock>.Name = 'David'

Specified property set:
    PropertySetBehavior
        <Mock>.Name = <IsAnything constraint>
testCase.verifyThat(behavior.Age,WasSet)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasSet failed.
--> Property 'Age' was never set.

Specified property set:
    PropertySetBehavior
        <Mock>.Age = <IsAnything constraint>
testCase.verifyThat(behavior.Name,WasSet('ToValue','Andy'))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasSet failed.
--> Property 'Name' was not set to the specified value.
--> Observed property set(s) to any value:
        <Mock>.Name = 'David'

Specified property set:
    PropertySetBehavior
        <Mock>.Name = 'Andy'
testCase.verifyThat(behavior.Name,WasSet('WithCount',5))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
WasSet failed.
--> Property 'Name' was not set to the specified value the expected number of times.
    
    Actual property set count:
             1
    Expected property set count:
             5
--> Observed property set(s) to any value:
        <Mock>.Name = 'David'

Specified property set:
    PropertySetBehavior
        <Mock>.Name = <IsAnything constraint>

버전 내역

R2017a에 개발됨