Main Content

matlab.unittest.constraints.Eventually クラス

名前空間: matlab.unittest.constraints
スーパークラス: matlab.unittest.constraints.Constraint

関数が制約を非同期的に満たすかどうかをテストする

説明

matlab.unittest.constraints.Eventually クラスは、特定のタイムアウト期間内に関数ハンドルが指定した制約を満たすかポーリングする制約を提供します。

matlab.unittest.constraints.Eventually クラスは handle クラスです。

作成

説明

c = matlab.unittest.constraints.Eventually(constraint) は、関数ハンドルが constraint を満たすかポーリングする制約を作成します。20 秒のタイムアウト期間内に constraint を満たす値を関数ハンドルが生成した場合に、制約 c は満たされます。

関数ハンドルが constraint を満たすまで Eventually が待機している間、テスト フレームワークは Figure を更新し、保留中のコールバックをすべて処理します。

c = matlab.unittest.constraints.Eventually(constraint,"WithTimeoutOf",timeout) は、指定したタイムアウト期間内に constraint が満たされるかポーリングする制約を作成します。

入力引数

すべて展開する

非同期的に満たす必要がある制約。matlab.unittest.constraints.Constraint オブジェクトとして指定します。

タイムアウト期間 (秒)。非負の数値スカラーとして指定します。

この引数は Timeout プロパティを設定します。

データ型: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

プロパティ

すべて展開する

関数ハンドルで生成された最後の出力。任意のデータ型の値として返されます。

属性:

GetAccess
public
SetAccess
private

タイムアウト期間 (秒)。非負の数値スカラーとして返されます。

このプロパティは入力引数 timeout によって設定されます。

属性:

GetAccess
public
SetAccess
immutable

すべて折りたたむ

Eventually 制約を使用して、最終的に検定にパスするかどうかをテストします。

最初に、この例で使用するクラスをインポートします。

import matlab.unittest.TestCase
import matlab.unittest.constraints.Eventually
import matlab.unittest.constraints.IsGreaterThan
import matlab.unittest.constraints.IsLessThan

対話型テスト用にテスト ケースを作成します。

testCase = TestCase.forInteractiveUse;

tic を最後に呼び出してから 20 秒以内に、toc の呼び出しによって 10 を超える値が生成されるかを検証します。このテストでは、Eventually 制約により、IsGreaterThan 制約が満たされるか経過時間がタイムアウト期間を超えるまで繰り返し toc が呼び出されます。tic の呼び出し後、10 秒より長く待機してから verifyThat を呼び出すと、即時にテストにパスします。これは、toc は既に 10 より大きい値を生成するからです。

tic
testCase.verifyThat(@toc,Eventually(IsGreaterThan(10)))
Verification passed.

20 秒以内に、toc が負の値を生成するかどうかをテストします。経過時間が負になることはないためテストは失敗しますが、Eventually はタイムアウト期間に指定された期間、toc にポーリングします。

testCase.verifyThat(@toc,Eventually(IsLessThan(0)))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    Eventually failed.
    --> The constraint never passed with a timeout of 20 second(s).
    --> IsLessThan failed.
        --> The value must be less than the maximum value.
        
        Actual Value:
          45.073031200000003
        Maximum Value (Exclusive):
             0
    
    Evaluated Function:
      function_handle with value:
    
        @toc

Eventually が 5 秒間ポーリングするようにタイムアウト期間を調整します。ticverifyThat の呼び出しの間隔が 5 秒を超えない場合、変更されたタイムアウト期間内で経過時間が 10 秒以下になるため、テストは失敗します。

tic
testCase.verifyThat(@toc,Eventually(IsGreaterThan(10), ...
    "WithTimeoutOf",5))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    Eventually failed.
    --> The constraint never passed with a timeout of 5 second(s).
    --> IsGreaterThan failed.
        --> The value must be greater than the minimum value.
        
        Actual Value:
           5.068235800000000
        Minimum Value (Exclusive):
            10
    
    Evaluated Function:
      function_handle with value:
    
        @toc

バージョン履歴

R2013a で導入