How to use XML to specify a Model-Based testcase
When you need to define more complex abstract testcases working
with the CLI can sometimes be a burden. For this reason we have added a easier way to structure
the abstract testcases, using XML.
For example, say that you need a testcase that first moves the
shortest way into a problem area, then continues randomly until some other condition is met,
but break the execution if the test takes more than 15 minutes to run. Using the CLI this is
not possible, but with the use of xml based testcases you can.
Example:
To create a xml testcase that does the same job as the following
CLI command (random execution, stop after 10 edges)
$> java -jar mbt.jar offline -f model.graphml -g RANDOM -s TEST_LENGTH:10
You need to create a xml file that looks like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MBTINIT SYSTEM "templates/mbt_setup.dtd" >
<MBTINIT>
<MODEL PATH="model.graphml"/>
<GENERATOR TYPE="RANDOM">
<CONDITION TYPE="TEST_LENGTH" VALUE="10"/>
</GENERATOR>
</MBTINIT>
and then call the xml using the CLI
$> java -jar mbt.jar xml -f testcase.xml
e_Initialize
v_KeePassNotRunning
e_Start
v_MainWindowEmpty
e_CloseApp
v_KeePassNotRunning
e_StartWithDatabase
v_EnterMasterCompositeMasterKey
e_EnterCorrectKey
v_MainWindow_DB_Loaded
e_CloseDB
v_MainWindowEmpty
e_CloseApp
v_KeePassNotRunning
e_Start
v_MainWindowEmpty
e_CloseApp
v_KeePassNotRunning
e_StartWithDatabase
v_EnterMasterCompositeMasterKey
The xml should follow the defined DTD. For a more complex example see below.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MBTINIT SYSTEM "templates/mbt_setup.dtd" >
<MBTINIT EXTENDED="true" EXECUTOR="java:myPackage.myTestClass" LOG-COVERAGE="10">
<MODEL PATH="model/Main.graphml"/>
<MODEL PATH="model/basicSubModels"/>
<SCRIPT PATH="model/basicFunctions.bsh"/>
<SCRIPT>
x = 0;
</SCRIPT>
<GENERATOR TYPE="SHORTEST">
<CONDITION TYPE="REACHED_STATE" VALUE="v_MainWindow_DB_Loaded"/>
</GENERATOR>
<GENERATOR TYPE="RANDOM">
<OR>
<AND>
<CONDITION TYPE="EDGE_COVERAGE" VALUE="100"/>
<CONDITION TYPE="STATE_COVERAGE" VALUE="100"/>
</AND>
<CONDITION TYPE="TEST_DURATION" VALUE="900"/>
</OR>
</GENERATOR>
</MBTINIT>
Above,
- We use EFSM
- We let the java class myPackage.myTestClass provide us with the implementation
of the edges and vertices during the execution in java
- We have specified that we want the log updated with execution statistics
every 10 seconds
- We load model "model/Main.graphml" and all models in model/basicSubModels
- We load an external script file and appends a internal to it. This will be
executed on the model before actual testing starts, to initialize values and states.
- First we take the shortest route to the vertex v_MainWindow_DB_Loaded
- Then we execute randomly until Edge and State Coverage is 100 or the test has
been running for more than 15 minutes (900sec).