Creating test scenarios

You can check that you solution works as expected by running tests on the entities and events. In test scenarios, you load entities and submit events from a single file, and then you can write tests that check the values of the entities, the entity attributes, and the events on your server.

Before you begin

Before you can test your entities and events, you must create the common definitions, entity loaders, event sequences that you want to include in your scenario.

About this task

You create your scenario and end each construct with a semi-colon (;). The results of your test display in the Console tab so that you can compare these results with what you expect.

Procedure

  1. Create a test scenario:
    1. Select a solution project and click Create test scenario in the solution map.
    2. In the Test Scenario wizard, select a test client project in your workspace and enter a name for your test scenario file.
    3. Click Finish. The test scenario editor opens.
  2. Press Space or Ctrl+Space to view the available constructs.
  3. Add common definitions by using the using definitions from: - "<common definitions file>" construct. If you use this construct, it must be the first phrase in the test scenario.
  4. Load entities and submit events by using the load entities from "<entity loader file>" and submit events from "<event sequence file>" constructs.
    Note: Event sequences that contain a time-stamped by the test scenario construct must have an absolute timestamp every time the event sequence is submitted.
  5. Write tests to check the state of your entities:
    • Check the existence of an entity by using the check that <entity> <exists/does not exist> construct. For example:
      check that the customer "John" exists ;
    • Use the check that for <entity> [identified by <entity id>] construct to test the attributes of your entities. When the editor proposes <list of tests>, use the verbalized constructs to write your tests. For example:
      check that for the customer identified by "John" : 
         - the address of this customer is not null ; 
  6. Write tests to check the number and nature of emitted events.
    • Use the check that for <event> emitted construct to test the content of specific events emitted by the scenario. For example:
      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 ;
    • Use the check that there are <number> <events> in the events emitted construct to test the expected number of specific events emitted by the scenario or by a particular agent. For example:
      check that there are 2 events in the events emitted
         by "Delivery_van_agent" ;
    • Use the check that for <the event>/<all events> in the events emitted construct to test one or all of the events emitted by the scenario or by a particular agent.
      check that for all events in the events emitted by "Delivery_van_agent" : 
         - it is not true that each event is null ; 
    • Use the check that <event aggregate> is construct to test the value of global event aggregates.
      check that the number of 'delivery events' is between 6 and 10 ; 
    Note: The test scenario check that <aggregate> is statement only supports global event aggregates.
  7. Shorten or lengthen the period of interest in your test scenario by adding the continue processing and empty the events emitted constructs. The empty the events emitted construct to disregard the events emitted before this statement. Events that are emitted by the solution before this statement is used are ignored in subsequent check statements. A continue processing until <date> construct to simulate the passing of time. The period between the specified date and the last step in the scenario defines which events that are scheduled for processing are triggered.
  8. Save your work. The file is stored in the Test Scenarios folder of your test client project.

Example

In the following example, entities from two entity loaders (customer_ids and items) are loaded and events from two event sequences (purchases and returns) are submitted to the server. Next, a test checks the attributes for the entity Betty. The test checks Betty's name, occupation, and address.

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 ;

The following example uses number operators to check that the age of the customer falls within a range.

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 ;

In the following example, a customer has a status of GOLD after a set of transactions is made. To check what happens when times passes, three tests check David's status after intermittent periods of time. The continue processing until <date> construct simulates the passing of time from the last timestamp in the event sequence to the <date> specified, during which events can be scheduled. In this example, no other transaction events are scheduled for David. A test checks that his status is SILVER on 08/24/15, another test checks that a status change was emitted, and a third test checks that his status is BRONZE on 02/24/16. As time passes from the last timestamp in the event sequence event to 08/24/15 and then to 02/24/16, David's status goes from GOLD to SILVER and then to BRONZE as a result. The customer status is lowered because, as time passes, David makes no new transactions.

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 ;