In this post we will try to give some ideas how to use the Graphwalker Path generators combined with Stop conditions. We recommend you to read our latest post about the Graphwalker API , however here is the snippet of code from last post:

ModelHandler modelHandler = new ModelHandler();
File loginModelFile = new File("'your location for the graphml file'/LoginModel.graphml");
Test testModel = new Test(loginModelFile, true, new A_StarPathGenerator(new EdgeCoverage(1.0)), false);
modelHandler.add("Test", testModel);
modelHandler.execute("Test");
Assert.assertTrue(modelHandler.isAllModelsDone());
String actualResult = modelHandler.getStatistics();
System.out.println(actualResult);
testModel.getDriver().quit();

In the first two lines we are just creating an instance of class ModelHandler (class from Graphwalker API) which one we will use to manage our *.graphml file (LoginModel.graphml) and our generated Java class (Test.java). The things come interesting at third line, where we create one instance of Test class:
Test testModel = new Test(loginModelFile, true, new A_StarPathGenerator(new EdgeCoverage(1.0)), false);

The first parameter represents the previously opened *.graphml file. The second is about enabling the EFSM (Extended finite-state machine ). Enabling this function will allow you to use “if statements” and variables to control your model directly in your *.graphml file. In Graphwalker API “if statements” are called “guards” and setting values for variables are called “actions” (it is explained in post: Graphwalker – Guards and actions).
Skip to the third parameter for now. The fourth enables “weight” parameter at edges. The “weight” parameter holds a real value between 0 and 1, and represents the probability that the edge will be chosen. You can use it during random walks.

Finally the third parameter calls the constructor of “PathGenerator” super class. Concrete Path generators extends this super class. You should use Path generators to say Graphwalker which strategy to use to go through your model. The next list describes which one you should use for your purposes:

  • A_StarPathGenerator – Calculate and generate the shortest path through the model. The algorithm is not recommended to use at larger models, because it will take considerable time to calculate using data in the model (EFSM mode of model).
  • RandomPathGenerator – Navigate through the model in a completely random way. Also called “Drunkard’s walk”, or “Random walk”. This algorithm selects an out-edge from vertex by random, and repeats the process in the next vertex.
  • NonOptimizedShortestPath – Tries to run the shortest path through a model. The algorithm works well on very large models, and generates reasonably short sequence. The downside is that you can’t use it with EFSM model. The algorithm can choose a path which is blocked by guard.
  • AllPathPermutationsGenerator – Try to walk all paths, or branches in the model. The downside is that it can take a while to execute.

You can use almost every Path generator for your model, depends on what is your main goal during testing your system. The sense of Path generators comes to life when you combine it with Stop conditions.

As you can see, you can pass one parameter called Stop Condition when you make an instance of Path generator. With Stop conditions you can set one or more criteria’s that your test should achieve. When your test fulfill the Stop condition, your test runs successfully. The combination of Path generator and Stop condition is the main thing you should choose properly, because the sense of your test is depends on it. Stop conditions is all about reaching or covering (in percent) edge’s, vertices or requirement’s (requirements will be explain in future post). You can also set the number of hovered edges or the duration of test for criteria to successfully finish the test. If it’s not enough for you, there is an option to combine some of listed Stop conditions.

Posted By Szabolcs Berkó

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>