Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:hybrid_model [2020/12/31 18:07] – [Tutorial: Combined Hybrid Model] admin | tutorial:hybrid_model [2024/01/03 19:54] (current) – removed admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Tutorial: Combined Hybrid Model ====== | ||
- | |||
- | Learning Objectives: | ||
- | * Differences between state model and combinatorial model | ||
- | * Hybrid model (embedding combinatorial model in state model) | ||
- | |||
- | |||
- | |||
- | ===== State Model vs. Combinatorial Model ===== | ||
- | State model and combinatorial model are two most common types of models used in Model-Based Testing (MBT). | ||
- | |||
- | |||
- | ==== State Model ==== | ||
- | |||
- | State model is used when you can describe the AUT behavior using a state diagram or finite state machine (FSM). | ||
- | |||
- | |||
- | ==== Combinatorial Model ==== | ||
- | |||
- | Combinatorial model is typically used to generate test cases to test interactions between/ | ||
- | |||
- | |||
- | ==== Which model should I choose? ==== | ||
- | State model focuses on system behavior while combinatorial model focuses on static variable interaction. | ||
- | |||
- | Often times you may find that in your state model you need to test a set of variable interactions, | ||
- | * payment types: visa, master, discover, american express, gift card | ||
- | * promotion code: no code/blank, 10% discount code, 20% discount code, ... | ||
- | * product warranty offer: accepted (checked), denied (unchecked) | ||
- | * shipping methods: 2-day, next-day, same-day (rush) | ||
- | |||
- | So state model would be good to generate test cases to navigate web pages while combinatorial model would be good to test permutation of various options at check out page. | ||
- | |||
- | If you find similar situation, the hybrid model by bringing combinatorial model into your state model would allow you to perform both testing in one model. | ||
- | |||
- | |||
- | ===== Hybrid Model ===== | ||
- | You can embed combinatorial model in a state model as data sets in the state model and reference the data sets in the state model: | ||
- | |||
- | * create state model | ||
- | * add data sets and generate data table | ||
- | * attach data set to transition or | ||
- | * loop through data set programmatically in scripts | ||
- | |||
- | |||
- | ==== Create State Model ==== | ||
- | |||
- | First create a state model with a transition named " | ||
- | |||
- | {{wiki: | ||
- | |||
- | 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. | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ==== Add Data Sets to Model ==== | ||
- | Open the state model and select //DATASET// tab. You should see the following: | ||
- | |||
- | {{wiki: | ||
- | |||
- | As shown above, a new data set has been created for us and assigned a default name " | ||
- | |||
- | Let's rename the data set to " | ||
- | |||
- | {{wiki: | ||
- | |||
- | click on the pencil icon to open dataset rename dialog: | ||
- | |||
- | {{wiki: | ||
- | |||
- | Enter new data set name " | ||
- | |||
- | {{wiki: | ||
- | |||
- | |||
- | The data set created has no variables, let's proceed to add variables. | ||
- | |||
- | === Add Variables === | ||
- | |||
- | As stated earlier, the variables we would like to test all combinations of are: | ||
- | * PaymentType: | ||
- | * CardNum: 4111-1111-1111-1111 (visa), 5500-0000-0000-0004 (master), 6011-0000-0000-0004(Discover), | ||
- | * PromoCode: blank, 10%OFF, 20%OFF, $5OFF, 15$OFF | ||
- | * Warranty: true, false | ||
- | * Shipping: 2 (2-day), 1 (next-day), 0 (same-day) | ||
- | |||
- | To add a variable click on " | ||
- | |||
- | {{wiki: | ||
- | |||
- | and you should see a variable is added: | ||
- | |||
- | {{wiki: | ||
- | |||
- | Go ahead and enter first variable name " | ||
- | |||
- | {{wiki: | ||
- | |||
- | Note that the default data type is " | ||
- | |||
- | Proceed to add the rest of the variables as below - be sure to set the data type accordingly: | ||
- | |||
- | {{wiki: | ||
- | |||
- | Click on the orange disk button to save the changes before proceeding to the next step. | ||
- | |||
- | === Generate DataTable === | ||
- | |||
- | To generate the combinations of the variables, select an algorithm from the " | ||
- | |||
- | {{wiki: | ||
- | |||
- | Select " | ||
- | |||
- | {{wiki: | ||
- | |||
- | The system generated 25 combinations (rows). | ||
- | |||
- | === Adjustments === | ||
- | You may have noticed that " | ||
- | |||
- | We need to make " | ||
- | |||
- | {{wiki: | ||
- | |||
- | 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 " | ||
- | |||
- | |||
- | ==== Attach Data Set to Transition ==== | ||
- | |||
- | In this step, we will attach the data set " | ||
- | |||
- | Open the transition properties by double-clicking on the transition label or through transition context menu and select " | ||
- | |||
- | {{wiki: | ||
- | |||
- | 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. | ||
- | |||
- | ==== Generate Test Cases ==== | ||
- | |||
- | Select " | ||
- | |||
- | The best way to show this is through {{wiki: | ||
- | |||
- | Notice that in {{wiki: | ||
- | |||
- | 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 " | ||
- | |||
- | {{wiki: | ||
- | |||
- | IDE should navigate to //SCRIPT// tab. Since the TRIGGER for transition " | ||
- | |||
- | {{wiki: | ||
- | |||
- | Click " | ||
- | |||
- | {{wiki: | ||
- | |||
- | 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 " | ||
- | |||
- | {{wiki: | ||
- | |||
- | |||
- | |||
- | TRIGGER script is just a //groovy// function, go ahead and add two lines of scripts as show below: | ||
- | |||
- | {{wiki: | ||
- | |||
- | |||
- | The " | ||
- | |||
- | Save the changes and run the model again. Examine //Script Log// (click on the script log button {{wiki: | ||
- | |||
- | Below is the first few lines from the script log: | ||
- | |||
- | | ||
- | |||
- | >>> | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | |||
- | |||
- | |||
- | ==== Loop through Data Set ==== | ||
- | |||
- | The data set can also be looped programmatically by scripting as follows: | ||
- | | ||
- | |||
- | // rewind dataset to first row | ||
- | | ||
- | |||
- | // retrieve data | ||
- | | ||
- | |||
- | // advance to next row, if rowIdx == 0, all rows exhausted | ||
- | | ||
- | |||
- | Please note that the data set being looped programmatically as above can not be attached to the transition at the same time. | ||
- | |||
- | |||
- | |||