Main Content

matlab.mock.constraints.WasSet クラス

名前空間: matlab.mock.constraints

プロパティの set の相互作用を決定する制約

説明

WasSet 制約は、実際の値が PropertyBehavior インスタンスでない場合、または PropertyBehavior に対応するプロパティが指定された回数設定されていない場合、検定エラーを生成します。

構築

constraint = WasSet は、プロパティの set の相互作用を判別する制約を提供します。プロパティ値が 1 回以上設定されると、この制約が満たされます。プロパティが設定されていないことを検定するには、チルダ (~) 演算子を使用して WasSet 制約を否定します。

constraint = WasSet(Name,Value) は、1 つ以上の Name,Value のペアの引数で指定された追加オプションをもつ制約を提供します。たとえば、WasSet('ToValue',42) はプロパティ値が 42 に設定されると満たされる制約を作成します。また、WasSet('ToValue',42,'WithCount',3) はプロパティ値が厳密に 3 回 42 に設定されると満たされる制約を作成します。

入力引数

すべて展開する

名前と値の引数

引数のオプションのペアを Name1=Value1,...,NameN=ValueN として指定します。ここで Name は引数名で、Value は対応する値です。名前と値の引数は他の引数の後になければなりませんが、ペアの順序は重要ではありません。

R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name を引用符で囲みます。

指定したプロパティ値。スカラー、ベクトル、行列または多次元配列として指定します。値はどのデータ型にすることもできます。また、動作により指定されたプロパティに関連します。

例: 'Joe'

例: [1 2 3;4 5 6]

プロパティが設定された回数。整数として指定します。

この構文で WasSet を否定すると、プロパティ値が厳密に n 回設定されていない場合にこの制約が満たされます。たとえば、プロパティが 4 回設定された場合、~WasSet('WithCount',3) はパスし、~WasSet('WithCount',4) は失敗します。

例: 5

プロパティ

すべて展開する

プロパティ値。スカラー、ベクトル、行列または多次元配列として指定します。値はどのデータ型にすることもできます。また、動作により指定されたプロパティに関連します。

プロパティの 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 で導入