UML Modelling for Model Base Testing

201 views Asked by At

I have a few questions relating to modelling my problem.I am working on a thesis project for Model Based Testing. Would also like to know from an expert point of view if I am taking the right approach fro modelling my scenario. I am modelling the UI of android applications , traversing through them , generating test cases and generating test codes for the espresso framework.

I would explain in simplicity the way I am modelling my system under test and to generate the test code for the test cases. (I am writing algorithms to generate the android code also). I am generating code for the android espresso testing framework. The structure of espresso always needs to find first the element to interact with. This is done with the “OnView()” method passing into in it parameters like withId(R.id.title) or withText(“Hello”) to find the element with the given Id or Text respectively. We then attach what the framework calls ViewActions or ViewMatchers to interact with the elements by performing actions or performing assertions respectively. Below is an example of an espresso test case, that finds a text view with a text “Lucky button” clicks on it and checks whether it is displayed.

@Test
public void test () {

  onView(withText(“Lucky Button”))      //ViewMatcher
       .perform(click())             // ViewAction  .check(matches(isDisplayed())); // ViewAssertion

Simple Case Let us take an android application with two screens. Screen A and Screen B. Each screen contains different elements. E.g. TextView(Textlabel), ImageView(Image label), e.t.c. I use the state diagram to describe the states a screen can be in. For each state exists an activity diagram that describes the tests to be performed on elements e.g. TextView,ImageView. We group each test suite in swimlanes and represent the test actions with activity actions. But there is input information that is needed. For example, an activity action may be called isVisible to check visibility of the toolbar which is in the ToolBarDesign swimlane. To arrive at this action, we need information on the toolbar to first locate it and check its visibility. I do this by providing the necessary information on the transitions of the actions or states. Below is an example of a state diagram and an activity diagram describing the scenario.

enter image description here

This state diagram has 2 states. And transitioning from MainActivity to NewNote is a trigger called openNewNote with an action which is in the format of a freetext. The freetext action contains the necessary information by which I process and extract in my java framework for generating the piece of code like for the one above. In the framework, I first select the element with id title and then perform the click method. Also in the MainActivity state contains a sub activity diagram as described earlier. In this sub activity diagram, we give the opportunity for the person modelling (which we consider to be one who has knowledge of the espresso framework) to write activity actions for testing. Below is an example of the activity diagram for MainActivity which test the toolbar of the application and the login screen.

enter image description here

The toolbar transitions to the isVisible activity from the initial node. On the transition, we make a description as explained above on the transition on the state diagram. Here we get the freetext action “withText:Lucky Button,matches,isDisplayed” and then process it in our framework to get the code.

 @Test
public void test () {

  onView(withText(“Lucky Button”))      //ViewMatcher
        .check(matches(isDisplayed())); // ViewAssertion

Questions. This so far works for the team as programmers are the ones modelling. I will provide a documentation for modelling the system. I would like to ask if this is a valid way of modelling and can be described in my research. And also if you have any comments or suggestions.

1

There are 1 answers

1
goofy On

Without going into deep details, I would recommend going one step back and start broader:

  • Define more formally what the system under test (SUT) is in your case: inputs, ouputs, requirements correlating inputs and outputs. Examples would be a state machine, activity diagram etc.
  • Define more formally what you like to model: a parallel implementation to the SUT which is your test model (TM). It is usually abstracter and only valid in some limited area of the behaviour of the SUT. In your case the sequence and activity diagrams.
  • A conformance relation: What is the formal definition that SUT conforms to TM? How do these two models SUT and TM compare?
  • What is the theory which can formally and automatically prove the conformance relation? This gives also the answer to the tools needed for automation.

The best way to start is to exercise on examples:

  • Understand all demo examples from at least one of the big MBT-Tools: Microsoft Spec Explorer, Conformiq Designer ...
  • Model your example in one of them roughly.
  • See how they use UML. I recommend the UML extension of Spec Explorer to you which focuses on input data generation and scenarios and less on behaviour - similar to your application.
  • Understand the theory behind these tools: symbolic execution, alternating simulation, scenarios etc.

If you answer these questions you have also the answer if your approach is valid or has any errors, which I can't answer from what you presented.