Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
vendingmachine [2016/09/22 02:36] – external edit 127.0.0.1 | vendingmachine [2020/05/10 03:01] (current) – removed admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Demo Model: Vending Machine ===== | ||
- | |||
- | {{http:// | ||
- | |||
- | ====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:// | ||
- | |||
- | ---- | ||
- | ==== What's Included ==== | ||
- | This demo includes the following components: | ||
- | |||
- | * java class to be tested that simulates vending machine: [[http:// | ||
- | * MBT model (shown above) from which the test sequences are generated. | ||
- | * MBT handler [[http:// | ||
- | |||
- | ---- | ||
- | ==== 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:// | ||
- | |||
- | If you were to write test cases to test this java class thoroughly, how many test cases do you have to write? [[http:// | ||
- | |||
- | ---- | ||
- | ==== 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 " | ||
- | |||
- | For example at the " | ||
- | |||
- | ---- | ||
- | ==== Test Generation ==== | ||
- | To create the test sequence to tested all transitions, | ||
- | |||
- | 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:// | ||
- | |||
- | ---- | ||
- | ==== 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 inherriting from **com.webmbt.plugin.JavaAppHandler**, | ||
- | |||
- | 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 " | ||
- | |||
- | 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:// | ||
- | |||
- | 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:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | |||