テスト・シナリオの作成

エンティティーとイベントにテストを実行して、ソリューションが予期したとおりに機能するかチェックできます。テスト・シナリオでは、1 つのファイルからエンティティーをロードし、イベントを送信します。次に、サーバー上でエンティティーの値、エンティティーの属性、およびイベントをチェックするテストを記述できます。

始める前に

エンティティーとイベントをテストする前に、シナリオに組み込む共通定義、エンティティー・ローダー、およびイベント・シーケンスを作成する必要があります。

このタスクについて

シナリオを作成し、各構成体をセミコロン (;) で終了させます。テストの結果は「コンソール」タブに表示されるので、結果と予測を比較できます。

手順

  1. テスト・シナリオを作成します。
    1. ソリューション・プロジェクトを選択して、ソリューション・マップの「テスト・シナリオの作成」をクリックします。
    2. 「テスト・シナリオ」ウィザードで、ワークスペース内のテスト・クライアント・プロジェクトを選択し、テスト・シナリオ・ファイルの名前を入力します。
    3. 「終了」をクリックします。 テスト・シナリオ・エディターが開きます。
  2. スペースまたは Ctrl + スペース を押して、使用可能な構成体を表示します。
  3. using definitions from: - "<common definitions file>" 構成体を使用して、共通定義を追加します。この構成体を使用する場合、これをテスト・シナリオ内の最初の句にする必要があります。
  4. load entities from "<entity loader file>" 構成体および submit events from "<event sequence file>" 構成体を使用して、エンティティーをロードし、イベントを実行依頼します。
    注: time-stamped by the test scenario 構成体を含むイベント・シーケンスは、イベント・シーケンスが送信される各回の絶対タイム・スタンプを持つ必要があります。
  5. エンティティーの状態をチェックするためのテストを作成します。
    • check that <entity> <exists/does not exist> 構成体を使用して、エンティティーが存在するかをチェックします。例:
      check that the customer "John" exists ;
    • check that for <entity> [identified by <entity id>] 構成体を使用して、エンティティーの属性をテストします。エディターが <list of tests> を提示したら、言語化された構成体を使用してテストを作成します。例:
      check that for the customer identified by "John" : 
         - the address of this customer is not null ; 
  6. 出力済みイベントの数および性質をチェックするためのテストを作成します。
    • check that for <event> emitted 構成体を使用して、シナリオによって出力される特定イベントの内容をテストします。例:
      check that for the delivery van request in the events emitted by "Delivery_van_agent" : 
         - it is not true that the driver of the delivery van of this delivery van request is null ;
    • check that there are <number> <events> in the events emitted 構成体を使用して、シナリオまたは特定のエージェントによって出力される特定イベントの予測数をテストします。例:
      check that there are 2 events in the events emitted
         by "Delivery_van_agent" ;
    • check that for <the event>/<all events> in the events emitted 構成体を使用して、シナリオまたは特定のエージェントによって出力される 1 つまたはすべてのイベントをテストします。
      check that for all events in the events emitted by "Delivery_van_agent" : 
         - it is not true that each event is null ; 
    • check that <event aggregate> is 構成体を使用して、グローバル・イベント集約の値をテストします。
      check that the number of 'delivery events' is between 6 and 10 ; 
    注: テスト・シナリオの check that <aggregate> is ステートメントは、グローバル・イベント集約のみをサポートします。
  7. continue processing および empty the events emitted 構成体を追加して、テスト・シナリオの対象期間を短縮または延長します。 empty the events emitted 構成体は、このステートメントの前に出力されたイベントを無視するためのものです。このステートメントが使用される前のソリューションで出力されたイベントは、後続のチェック・ステートメントでは無視されます。 continue processing until <date> 構成体は、時間の経過をシミュレートするためのものです。指定した日付からシナリオの最終ステップまでの期間が、処理のためにスケジュールされたイベントのどれがトリガーされるかを定義します。
  8. 作業内容を保存します。このファイルは、テスト・クライアント・プロジェクトの「テスト・シナリオ」フォルダーに保管されます。

例

次の例では、2 つのエンティティー・ローダー (customer_ids および items) のエンティティーがロードされ、2 つのイベント・シーケンス (purchases および returns) のイベントがサーバーに送信されます。次に、テストは、エンティティー「Betty」の属性をチェックします。テストでは、Betty の名前、職業、および住所がチェックされます。

load entities from:
   - "customer_ids" 
   - "items" ;

submit events from : 
   - "purchases" 
   - "returns" ;

check that for the customer "Betty" :
    - the name of this customer is "Betty"
    - the occupation of this customer is not "Software Architect" 
    - the address of this customer is not null 
    - the occupation of this customer is not null ;

次の例では、数値演算子を使用して、顧客の年齢が特定の範囲内に入るかチェックします。

check that for the customer "Betty" :
    - the age of this customer is between 18 and 65
    - the age of this customer is more than 21
    - the age of this customer is at most 50 ;

以下の例では、一連のトランザクションが行われた後、顧客のステータスは GOLD になります。時間が経過する中で何が発生するかをチェックするために、3 つのテストで、断続的期間の後に David のステータスをチェックします。continue processing until <date> 構成体は、イベントをスケジュール可能な、イベント・シーケンスの最終タイム・スタンプから、指定された <date> までの時間の経過をシミュレートします。この例で、David に他のトランザクション・イベントはスケジュールされていません。 あるテストでは、08/24/15 にステータスが SILVER であるかチェックし、別のテストでは、ステータス変更が出力されたことをチェックし、3 番目のテストでは、02/24/16 にステータスが BRONZE であるかチェックします。時間が、イベント・シーケンスのイベントの最終タイム・スタンプから 08/24/15 に、その後 02/24/16 に経過するにつれて、David のステータスは、GOLD から SILVER に、その後、BRONZE に結果として移ります。時間が経過する中で、David が新しいトランザクションを行わなかったため、顧客ステータスが下げられました。

submit events from "transactions until gold" ; 

check that for the customer "David":  
   - the status of this customer is GOLD ; 

continue processing until 08/24/16 ; 

check that for the customer "David" :  
   - the status of this customer is SILVER ; 

check that for the status change in the events emitted
    by "CustomerLoyaltyAgent" :
    - the customer id of the customer of this status change is "David"
    - the new status of this status change is SILVER ;

continue processing until 02/24/17 ; 

check that for the customer "David" :  
   - the status of this customer is BRONZE ;