matlab.mock.constraints.WasSet クラス
名前空間: matlab.mock.constraints
プロパティの set の相互作用を決定する制約
説明
WasSet
制約は、実際の値が PropertyBehavior
インスタンスでない場合、または PropertyBehavior
に対応するプロパティが指定された回数設定されていない場合、検定エラーを生成します。
構築
constraint = WasSet
は、プロパティの set の相互作用を判別する制約を提供します。プロパティ値が 1 回以上設定されると、この制約が満たされます。プロパティが設定されていないことを検定するには、チルダ (~
) 演算子を使用して WasSet
制約を否定します。
constraint = WasSet(
は、1 つ以上の Name,Value
)Name,Value
のペアの引数で指定された追加オプションをもつ制約を提供します。たとえば、WasSet('ToValue',42)
はプロパティ値が 42 に設定されると満たされる制約を作成します。また、WasSet('ToValue',42,'WithCount',3)
はプロパティ値が厳密に 3 回 42 に設定されると満たされる制約を作成します。
入力引数
引数のオプションのペアを Name1=Value1,...,NameN=ValueN
として指定します。ここで Name
は引数名で、Value
は対応する値です。名前と値の引数は他の引数の後になければなりませんが、ペアの順序は重要ではありません。
R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name
を引用符で囲みます。
ToValue
— 指定したプロパティ値
スカラー | ベクトル | 行列 | 多次元配列
指定したプロパティ値。スカラー、ベクトル、行列または多次元配列として指定します。値はどのデータ型にすることもできます。また、動作により指定されたプロパティに関連します。
例: 'Joe'
例: [1 2 3;4 5 6]
WithCount
— プロパティが設定された回数
整数
プロパティが設定された回数。整数として指定します。
この構文で WasSet
を否定すると、プロパティ値が厳密に n
回設定されていない場合にこの制約が満たされます。たとえば、プロパティが 4 回設定された場合、~WasSet('WithCount',3)
はパスし、~WasSet('WithCount',4)
は失敗します。
例: 5
プロパティ
Value
— プロパティ値
スカラー | ベクトル | 行列 | 多次元配列
プロパティ値。スカラー、ベクトル、行列または多次元配列として指定します。値はどのデータ型にすることもできます。また、動作により指定されたプロパティに関連します。
Count
— プロパティの set アクセス回数
整数
プロパティの set アクセス回数。整数として返されます。このプロパティは、制約が作成されると読み取り専用になります。これは制約の作成時に指定できます。
コピーのセマンティクス
値。値クラスがコピー操作に与える影響については、オブジェクトのコピーを参照してください。
例
モック プロパティの 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 で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)