Differences
This shows you the differences between two versions of the page.
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:// | ||
- | |||
- | ====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? Here we will focus on how to unit test this same problem using Model-Based Testing with // | ||
- | |||
- | ---- | ||
- | ==== 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 implementing // | ||
- | |||
- | 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:// | ||
- | |||