Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:hybrid_model [2020/12/30 22:56]
admin [Add Data Sets to Model]
tutorial:hybrid_model [2021/01/05 03:00] (current)
Line 3: Line 3:
 Learning Objectives: Learning Objectives:
   * Differences between state model and combinatorial model   * Differences between state model and combinatorial model
-  * Hybrid model+  * Hybrid model (embedding combinatorial model in state model) 
  
  
Line 45: Line 46:
 ==== Create State Model ==== ==== Create State Model ====
  
-First create a state model with a transition named "checkout", the transition we will use to attach data sets to.  If you need help creating the state model, you may refer to [[state_modeling | Create State Model tutorial]].+First create a state model with a transition named "CheckOut", the transition we will use to attach data sets to.   
 + 
 +{{wiki:overview:tut_DataSet_SimpleModel.png?500}}  
 + 
 +If you need help creating the state model, you may refer to [[state_modeling | Create State Model tutorial]]. 
  
 You can also use any of your existing state model as well, just select a transition from the model which we will attach the data sets. You can also use any of your existing state model as well, just select a transition from the model which we will attach the data sets.
Line 128: Line 134:
 Now the payment types and credit card numbers are matching correctly. Now the payment types and credit card numbers are matching correctly.
  
 +Feel free to experiment with other algorithms and compare the # of rows generated in DataTable by different algorithms.
 +
 +Next step is to attach this data set to the "CheckOut" transition on the model.
  
  
 ==== Attach Data Set to Transition ==== ==== Attach Data Set to Transition ====
 +
 +In this step, we will attach the data set "PaymentOptions" we have created to the transition "CheckOut" in our model.
 +
 +Open the transition properties by double-clicking on the transition label or through transition context menu and select "PaymentOptions" from the "Data Set" dropdown list:
 +
 +{{wiki:overview:tut_DataSet_TransProp.png?300}} 
 +
 +When a data set is attached to the transition, the sequencer that generates test cases from the model will ensure the test cases generates will cover the transition the number of times to loop through all of the rows in the data set.
 +
 +Save the changes.  We are now ready to generate the test cases. 
 +
 +==== Generate Test Cases ====
 +
 +Select "Optimal" sequencer (default) and run the model.  Our expectation is that at least 25 test cases would be generated from the state model with each test case covering "CheckOut" transition to consume a row from the data set.
 +
 +The best way to show this is through {{wiki:overview:tut_DataSet_testcaseGraph.png?linkonly | Test Case Graph}} in //RESULT// tab. 
 +
 +Notice that in {{wiki:overview:tut_DataSet_testcaseGraph.png?linkonly | Test Case Graph}}, there are 25 test cases and each test case covers the transition "CheckOut" matching 25 rows in the data set.
 +
 +To confirm that each row in data set is used, let's print out the data row as model runs - the test cases generated and executed. 
 +
 +To write a line of script in TRIGGER for transition "CheckOut", select script context menu for transition "CheckOut":
 +
 +{{wiki:overview:tut_DataSet_menuTransScript.png?250}}
 +
 +IDE should navigate to //SCRIPT// tab.  Since the TRIGGER for transition "CheckOut" has not been created, you will be prompted to create it:
 +
 +{{wiki:overview:tut_DataSet_ScriptAddDialog.png?500}}
 +
 +Click "OK" to create the skeleton TRIGGER script for the transition:
 +
 +{{wiki:overview:tut_DataSet_ScriptCheckOut.png?500}}
 +
 +Alternatively you can add the skeleton TRIGGER script for the transition by pressing Ctrl-I while your cursor is placed on a blank line in //SCRIPT// tab and select transition "CheckOut":
 +
 +{{wiki:overview:tut_DataSet_AddTrigger.png?100}}
 +
 +
 +
 +TRIGGER script is just a //groovy// function, go ahead and add two lines of scripts as show below:
 +
 +{{wiki:overview:tut_DataSet_TriggerCheckOut.png?500}}
 +
 +
 +The "log" scripts above prints the current row of the data set and "Payment Type" and "CardNum" to //Script Log//.
 +
 +Save the changes and run the model again. Examine //Script Log// (click on the script log button {{wiki:overview:tut_DataSet_ScriptLogBtn.png?50}} in //RESULT// tab):
 +
 +Below is the first few lines from the script log:
 +
 +   C:\eclipse-workspace\TestOptimal_Dev\model\Demo_DataSet.fsm\temp\script.log
 +   
 +   >>> Date: 2020-12-30 
 +   20:51:25.915 data row [0]: [PaymentType:VISA, CardNum:4111-1111-1111-1111, Warranty:false, Shipping:0, PromoCode:Blank, $$hashKey:object:444]
 +   20:51:25.916 PaymentType: VISA, CardNum: 4111-1111-1111-1111
 +   20:51:25.917 data row [1]: [PaymentType:VISA, CardNum:4111-1111-1111-1111, Warranty:true, Shipping:1, PromoCode:10%OFF, $$hashKey:object:445]
 +   20:51:25.918 PaymentType: VISA, CardNum: 4111-1111-1111-1111
 +   20:51:25.918 data row [2]: [PaymentType:VISA, CardNum:4111-1111-1111-1111, Warranty:false, Shipping:2, PromoCode:20%OFF, $$hashKey:object:446]
 +   20:51:25.918 PaymentType: VISA, CardNum: 4111-1111-1111-1111
 +   20:51:25.919 data row [3]: [PaymentType:VISA, CardNum:4111-1111-1111-1111, Warranty:false, Shipping:0, PromoCode:$5OFF, $$hashKey:object:447]
 +   20:51:25.919 PaymentType: VISA, CardNum: 4111-1111-1111-1111
 +   20:51:25.919 data row [4]: [PaymentType:VISA, CardNum:4111-1111-1111-1111, Warranty:true, Shipping:0, PromoCode:15$OFF, $$hashKey:object:448]
 +   20:51:25.919 PaymentType: VISA, CardNum: 4111-1111-1111-1111
 +   20:51:25.919 data row [5]: [PaymentType:MASTER, CardNum:5500-0000-0000-0004 , Warranty:true, Shipping:1, PromoCode:Blank, $$hashKey:object:449]
 +   20:51:25.919 PaymentType: MASTER, CardNum: 5500-0000-0000-0004 
 +   20:51:25.920 data row [6]: [PaymentType:MASTER, CardNum:5500-0000-0000-0004 , Warranty:false, Shipping:2, PromoCode:10%OFF, $$hashKey:object:450]
 +   20:51:25.920 PaymentType: MASTER, CardNum: 5500-0000-0000-0004 
 +   20:51:25.920 data row [7]: [PaymentType:MASTER, CardNum:5500-0000-0000-0004 , Warranty:true, Shipping:0, PromoCode:20%OFF, $$hashKey:object:451]
 +   20:51:25.920 PaymentType: MASTER, CardNum: 5500-0000-0000-0004 
 +   20:51:25.921 data row [8]: [PaymentType:MASTER, CardNum:5500-0000-0000-0004 , Warranty:false, Shipping:1, PromoCode:$5OFF, $$hashKey:object:452]
 +   20:51:25.921 PaymentType: MASTER, CardNum: 5500-0000-0000-0004 
 +   20:51:25.921 data row [9]: [PaymentType:MASTER, CardNum:5500-0000-0000-0004 , Warranty:false, Shipping:0, PromoCode:15$OFF, $$hashKey:object:453]
 +   20:51:25.921 PaymentType: MASTER, CardNum: 5500-0000-0000-0004 
 +   20:51:25.922 data row [10]: [PaymentType:DISCOVER, CardNum:6011-0000-0000-0004, Warranty:true, Shipping:0, PromoCode:Blank, $$hashKey:object:454]
 +   20:51:25.922 PaymentType: DISCOVER, CardNum: 6011-0000-0000-0004
 +
 +
 +
  
 ==== Loop through Data Set ==== ==== Loop through Data Set ====
  
 +The data set can also be looped programmatically by scripting as follows:
 +   dataset = $SYS.getDataSet('PaymentOptions');
 +   
 +   // rewind dataset to first row
 +   dataset.rewind();
 +   
 +   // retrieve data
 +   paymentType = dataset.getData('PaymentType');
 +   
 +   // advance to next row, if rowIdx == 0, all rows exhausted
 +   rowIdx = dataset.nextRow();
  
 +Please note that the data set being looped programmatically as above can not be attached to the transition at the same time.