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
vendingmachine [2020/04/26 03:33]
127.0.0.1 external edit
— (current)
Line 1: Line 1:
-===== Demo Model: Vending Machine ===== 
- 
-{{http://TestOptimal.com/demo/Demo_VendingMachine.png?600x200}} 
- 
-====Objective==== 
-To demonstrate how to test the java applications (java classes) with a model. 
- 
----- 
-==== Background ==== 
-This is a modified version of Drink Vending Machine example from [[http://www.businessanalysisbooks.com/0123725011.html|Practical Model-Based Testing - A Tools Approach]] by Mark Utting & Bruno Legeard, pages 79 - 82. The intent of this demo is to demonstrate how a model is built for a java application and how this java program is tested from the generated test cases. 
- 
----- 
-==== What's Included ==== 
-This demo includes the following components: 
- 
-  * java class to be tested that simulates vending machine: [[http://TestOptimal.com/demo/VendingMachine.java|VendingMachine.java]]. 
-  * MBT model (shown above) from which the test sequences are generated. 
-  * MBT handler [[http://TestOptimal.com/demo/VendingMachineHandler.java|VendingMachineHandler.java]] which drives the java vending machine program. 
- 
----- 
-==== Vending Machine App ==== 
-The java class that simulates the vending machine is very simple, it consists of an attribute to keep track of the amount of coins (value) inserted and a set of methods to operate the machine: inserting coins, canceling and discharge the drink (see [[http://TestOptimal.com/demo/VendingMachine.text|VendingMachine.java]]).  
- 
-If you were to write test cases to test this java class thoroughly, how many test cases do you have to write? Here we will focus on how to unit test this same problem using Model-Based Testing with //TestOptimal//. 
- 
----- 
-==== Modeling ==== 
-First we build a model to describe the behaviour of this java class. The model is quite straight forward. Each state represents the amount of coins in the vending machine and a special state "Vending" to indicate enough coins are in the vending machine and it's ready to discharge the drink. See the model above. 
- 
-For example at the "Start" state, the system has a ballance of 0 coins and from this state, we can insert a quarter coin, half-dollar coin or request cancel. If we choose insert a quarter coin transition, then our vending machine enters OneQuarter state. From OneQuarter state, we have again three choices: add one quarter, one half-dollor or cancel the transition. 
- 
----- 
-==== Test Generation ==== 
-To create the test sequence to tested all transitions, we just need to follow the graph with a pencil until all states and transitions are covered. But when you are done, you might wonder if you could find a shorter path if you were to try it again. We will show you a better way than tracing the graph with a pencil. 
- 
-With a click on the run button, the system can generate the shortest test sequence covering all transitions in the model using a mathematical algorithm ([[http://en.wikipedia.org/wiki/Chinese_postman_problem|Chinese Postman Problem]]). The result would look like this sequence graph http://testoptimal.com/demo/Demo_VendingMachineJava_SeqGraph.png. Compare the system generated sequence with the one you've generated with a pencil and paper. 
- 
----- 
-==== Automation Scripting ==== 
-Now with test sequence generated, we are ready to write some code to execute it. To do this, we create an MBT handler java class implementing //com.webmbt.plugin.PluginHandlerIntf//, like [[http://TestOptimal.com/demo/VendingMachineHandler.java|VendingMachineHandler.java]]. 
- 
-You might notice that each method in the handler class corresponds to a transition in the model. For example the method OneQuarter_AddHalfDollar_action is for the transition "AddHalfDollor" in state "OneQuarter" and will be called when that transition is triggered. So, we just need to implement these methods with some java code to call the vending machien methods. 
- 
-At this point, we have built everything we need: a model and MBT handler (tesing script). 
- 
----- 
-==== Execute Model ==== 
-To run the test, click on the {{http://testoptimal.com/img/start.png|run}} button. The system first generates the optimal test sequence and then calls vending machine java methods for each transition on the path. 
- 
-While the model is executing, use Monitor tab, Sequence Log tab and Stats tab to check for the execution status. You should see something like these:  
- 
-  * [[http://testoptimal.com/demo/VendingMachine_Monitor.jpg | Monitor Tab]] 
-  * [[http://testoptimal.com/demo/VendingMachine_SeqLog.jpg | SeqTrace]]  
-  * [[http://testoptimal.com/demo/VendingMachine_Stats.jpg | Stats]] 
-