SoftTest Ireland: Model Based Testing - January 27th 2011
Upcoming SlideShare
Loading in...5
×
 

SoftTest Ireland: Model Based Testing - January 27th 2011

on

  • 1,842 views

Visit www.softtest.ie and sign up for Irish Software Testing event updates.

Visit www.softtest.ie and sign up for Irish Software Testing event updates.

These are the slides from our Model Based Testing talk in IBEC.

Statistics

Views

Total Views
1,842
Views on SlideShare
1,687
Embed Views
155

Actions

Likes
0
Downloads
28
Comments
0

1 Embed 155

http://softtest.ie 155

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Although several definitions exists, most of them carry the same basic idea about an model describing a system of some sort and some way of using that model to get test cases (or rather test sequences).
  • The model describes the functionality of a system, or rather the functionality we want to test. You see the possible paths through the system visualized by arrows (aka edges) and nodes (aka vertexes). Traversing the model is quite simple; do something in an edge and verify that your actions turn out right in the following vertex, and on to the next one…. One beauty of this approach is that the code will be fairly small functions of “do:ing”, that would be Edges, and mainly “verifying”, Vertexes. I say mainly because one usually need to do some things to be able to verify, like open a customer dialog and search for latest transaction or create a database connection to check a certain post in a datatabel etc.
  • That is an interesting question! And a potential trap! Instinct will tell you not to model to “ shallow”, an extreme case would look like Edge_StartGoogle, Vertex_GoogleHome, Edge_NavToImagesAndVideosAndLoginGMailWithValidAndInvalidDataAndNavToHome and finally Vertex_ValidateAllWeJustDidt! Such a model will not benefit from anything. The data you want to verify is very far back and even more serious is the total lack of possible, “random”, paths through the system The opposite is not too good either, by cutting all and everything into small pieces you will end up with a too big model representing fairly little functionality compared to its size and loosing the overview benefits of the model. OK, so what is the appropriate medium way? I’d say use your knowledge, experience and gut feeling and fine-tune from that. Remember that you haven’t scripted anything yet so changes are fast and cheap!
  • You will be one that discover the misalignment of understanding between developers, testers, SME:s, product owners and the alike, and you didn’t even start to automate any tests yet! Now, that is proactive testing! (couldn’t we get this benefit with “classic” automation? Sure, just try getting the parties mentioned to read your test cases….compared to browsing through a model on the and informally discuss the functionality. I’ll bet even your boss will glance at the model and nod in pseudo-understanding….)
  • No UML GraphWalker  own ruleset in conjunction with  GraphML , is easier to get started with than UML. As testers, we do not need all functionality that UML has to offer. No exit/stop points The idea behind this, is that we want long, unpredictable test sequences. We do not want to walk the same path every time we execute a test. We want variation, spiced with randomness. This will create a better 'test coverage' of the system under test. The way to tell  GraphWalker  to stop generating test sequences are done by means of Stop Criterias, passed as arguments to the tool. Online GraphWalker  supports online test sequence generation. Using the online mode, the tool is capable of  testing non-deterministic systems. In essence, this means that the path walked through the model is decided runtime, during the actual test execution. This is very helpful if your test execution tool needs to communicate with the model during the test. Event-driven GraphWalker  will support (from version 2.5.1-SNAPSHOT) the possibility to switch model caused by an event. For example, let's say we have a model that executes the navigation of the GUI of a mobile phone. At any point in that execution, an incoming call will be such an event that will switch from navigating the GUI, to a model that handles the call.

SoftTest Ireland: Model Based Testing - January 27th 2011 SoftTest Ireland: Model Based Testing - January 27th 2011 Presentation Transcript

  • Model-based Testing Introduction and Hands-on session Stefan Ekman Dublin, 2011-01-27
  • Model Based Testing What is Model-based Testing?
  • What is MBT?
    • Wikipedia:
    • “ Model-based testing is software testing in which test
    • cases are derived in whole or in part from a model that
    • describes some (usually functional) aspects of the system
    • under test (SUT).”
  • Advantages
    • Model-based testing is easy to understand from both the business and developer communities
    • Model-based testing separates (business-) logic from testing code
    • Model-based testing increases the test coverage with the same effort as “Classic” test automation
    • Model-based testing is the fastest way to get use of automated test
  • Advantages
    • Model-based testing enables us to switch testing tool if needed or support multiple platforms using the same model
    • Model-based testing focuses on requirement coverage, not how many test cases you executed last week etc.
    • Model-based testing proved to positively affect the maintenance problem, the nemesis of all test automation.
  • The Model Modelling your tests
  • Tools / Environment . GraphML Model with yEd GraphWalker MBT engine Selenium Java or SOAP QTP Via SOAP Hudson Build system
  •  
  • Code behind
    • public void e_Nav_GoogleImages()
    • {
    • log .info("Edge: e_Nav_GoogleImages");
    • selenium .click( “link=Images" );
    • selenium .waitForPageToLoad(30000);
    • }
  • Modelling
    • What should the model represent?
    • I suggest that you start with the model representing the end usage/user functionality of the system. That will usually resemble your traditional functional test case approach. There are several other approaches for you to explore later in you new MBT career…
  • Modelling
    • To what level do we model?
  • Modelling
    • Who creates the model?
    • Start out yourself to begin with
    • Present the model – show it to SME’s and developers for input
    • If the system is non-existing, you probably would consider user stories, product backlog items, use-cases or the equivalent requirement's information.
  • Modelling
    • During this process you will collect the first benefits of working with MBT!
  • GraphWalker
    • GraphWalker is a tool for generating offline and online test sequences from Finite State Machines and Extended Finite State Machines.
    • http://www.graphwalker.org/
    • Lightweight MBT – No UML
    • No exit/stop points
    • Online
    • Event-driven
    • GraphWalker is an Open Source MBT engine created by Kristian Karl and are stable and used in large IT testing environment.
  • GraphWalker - Stop Criteria's
    • REACHED_EDGE
    • REACHED_VERTEX
    • EDGE_COVERAGE
    • VERTEX_COVERAGE
    • TEST_LENGTH
    • TEST_DURATION
    • REACHED_REQUIREMENT
    • REQUIEMENT_COVERAGE
    • NEVER
  • GraphWalker – XML configuration
    • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
    • <!DOCTYPE MBTINIT SYSTEM &quot;mbt_setup.dtd&quot; >
    • <MBTINIT EXECUTOR=&quot;java:com.paddypower.mbt.BetPlacementRegression&quot; EXTENDED=&quot;true&quot; GUI=“true&quot;>
    • <MODEL PATH=&quot;model/BetPlacementRegression.graphml&quot;/>
    • <CLASS PATH=&quot;JavaPPautomationbin&quot;/>
    • <CLASS PATH=&quot;.servlet-2.3.jar&quot;/>
    • <CLASS PATH=&quot;seleniumselenium-java-client-driver.jar&quot;/>
    • <CLASS PATH=&quot;seleniumselenium-server-2.0a6.jar&quot;/>
    • <SCRIPT>
    • PortNumber = 5555;
    • DBconnectionString = &quot;jdbc:informix-sqli://10.10.10.10/db:informixserver=testdb1;user=user;password=12345&quot;;
    • MAX_SELECTIONS = 10;
    • </SCRIPT>
    • <GENERATOR TYPE=&quot;RANDOM&quot;>
    • <CONDITION TYPE=&quot;REACHED_VERTEX&quot; VALUE=&quot;v_Done&quot;/>
    • </GENERATOR>
    • </MBTINIT>
  • GraphWalker - The Walks
    • RANDOM
    • A_STAR Will try to generate the shortest possible test
    • sequence through a model with given stop
    • condition. The algorithm only works well on
    • smaller models.
    • SHORTEST_NON_OPTIMIZED
  • GraphWalker - Edge
    • An edge is a transition. Could be a click on a button, a timeout, a server API call.
    • An edge can have a label, but it is not mandatory.
    • • The label of an edge will map against a method, function or sub routine during test execution.
    • As a rule of thumb, the best practice is to start the name with 'e_'. The reason for this, is that it is easier to recognize the function in the test execution tool, as an edge. For example: e_StartApplication e_EnterBasicView
    • The same name of an edge, can be re-used in the model.
  • GraphWalker - Vertex
    • A vertex is some kind of state that is possible to verify using some kind of oracle.
    • A vertex must always have a label.
    • The label of a vertex is mapped against a method, function or sub routine during test execution.
    • As a rule of thumb, the best practice is to start the name with 'v_'. The reason for this, is that it is easier to recognize the function in the test execution tool, as a vertex. For example: v_ApplicationStarted v_BasicView
    • The same name of a vertex, can be re-used in the model.
  • GraphWalker - Labels
    • Label [cond. expr.] / Statement1;Statement2;
    • White spaces not allowed.
    • Follow the naming convention for the implementing programming
    • language.
    • Example:
    • e_StartApplication
    • Example:
    • e_EnterBasicView
  • GraphWalker - Guards
    • Label [cond.expr.] / Statement1;Statement2;
    • Conditional expression that returns a Boolean value.
    • The guard indicates if the edge is accessible in the current state of the
    • machine. The language is either Java or JavaScript.
    • Example:
    • e_Evaluate [x>0 && y<=10]
    • Example:
    • e_Checkout [shoppingBasket.contains(&quot;Cerials&quot;)]
  • GraphWalker - Statements
    • Label [cond.expr.] / Statement1;Statement2;
    • Any applicable Java or JavaScript statements
    • Example:
    • e_Calculate / x=5;y++;
    • Example:
    • e_AddCerials / shoppingBasket.add(&quot;Cerials&quot;);
  • GraphWalker – Keyword Start
    • Used by Vertices only.
    • Each graph must have a start vertex, and that vertex holds this
    • keyword. There is only one vertex in a graph, holding this keyword.
    • The Start vertex can only have one out-edge.
    • If the graph is the main-graph, that edge must have a
    • label.
    • If the graph is a sub-graph, that edge cannot have a label.
  • GraphWalker - REQTAG
    • Used by Vertices
    • Used by GraphWalker for keeping track of which
    • requirements are fulfilled during testing.
    • In the example above, if v_BookInfomation is passed, it
    • would mean the requirement with tag UC01 2.2.3 has
    • passed.
    v_BookInfomation REQTAG=UC01 2.2.3
  • GraphWalker - Weight
    • Used by Edges only.
    • Used by MBT during random walks during test sequence generation. It holds a real value between 0 and 1, and represents the probability that a specific edge should be chosen. A value of 0.05, would mean a 5% chance of that edge to be selected during a run.
    • Note: It only works with the RANDOM generator
    v_BookInfomation REQTAG=UC01 2.2.3 e_NavA weight=0.25 e_NavB
  • GraphWalker – Keyword Blocked
    • Used by both Vertices and Edges.
    • A vertex or an edge with the key word BLOCKED, will be
    • excluded from the model when walked.
    v_BookInfomation BLOCKED
  • Metrics
    • Standard test metrics does not apply so well.
    • Test cases are not meaningful when running online tests.
    • MBT tends to drive the requirement work.
  • GraphWalker – QTP & SOAP
    • WebService(&quot;SoapServicesService&quot;).SetTOProperty &quot;WSDL&quot;, &quot;http://myComputerName:9090/mbt-services?WSDL&quot; If ( not WebService(&quot;SoapServicesService&quot;).Reload()  )Then     Reporter.ReportEvent micFail, &quot;MBT failure&quot;, &quot;MBT encountered an error. See the MBT log files for information.&quot;     ExitTest End If Do until not WebService(&quot;SoapServicesService&quot;).HasNextStep()     action = WebService(&quot;SoapServicesService&quot;).GetNextStep()     If len(action) > 0 Then         If not Eval( action ) Then             Reporter.ReportEvent micFail, &quot;Script failure&quot;, &quot;The script encountered an error when trying to run function: &quot; & action             ExitTest         End if     End If Loop Reporter.ReportEvent micDone, &quot;MBT Statistics&quot;, WebService(&quot;SoapServicesService&quot;).GetStatistics()
  • 5 min break..
    • I am not in the office at the moment. Please send any work to be translated.
  • Hands on session
    • Setup the environment
    • Create a model
    • Generate code from model
    • Automate with selenium
    • Create XML configuration file for GraphWalker
    • Run the model!
  • Files
    • 1. Create directory MBT i.e C:MBT
    • 2. Create directory Models under in the MBT folder
    • 3. Copy GraphWalker and Selenium jar files to the directory selenium-java-client-driver.jar selenium-server.jar graphwalker-2.5.1-SNAPSHOT-standalone.jar
  • Model
    • Visit www.brickor.com/MBT.htm with Firefox
    • Record with Selenium IDE by clicking on all elements and as well right clicking the result
    • Switch off recording.
    • Options > Format > JUnit4 (Java)
  • Model
    • Start yEd to create the model
  • Generate the Java Code
    • /**
    • * This method implements the {EDGE_VERTEX} '{LABEL}'
    • */
    • public void {LABEL}()
    • {
    • log.info( &quot;{EDGE_VERTEX}: {LABEL}&quot; );
    • throw new RuntimeException( &quot;The {EDGE_VERTEX}: {LABEL} is not implemented yet!&quot; );
    • }
    • java -jar graphwalker-2.5.1-SNAPSHOT-standalone.jar source -f Models/mbttest.graphml -t java.template.txt > javacode.txt
  • Eclipse – Create the Java project
    • Create new Java Project; MbtTest
    • Create new Java Package; ie.mbt.test
    • Create new Class; MBTtest
    • Copy paste the contents of the generated Java code from the model into the created class.
  • The java code
    • Include references to Selenium and GraphWalker in your project. Right click on your project and choose Properties. Under Java Build Path choose Libraries and then click Add External JARs.. Choose the two jar files:
    • graphwalker-2.5.1-SNAPSHOT-standalone.jar
    • selenium-java-client-driver.jar
    • private HttpCommandProcessor proc = new HttpCommandProcessor(&quot;localhost&quot;,4444, &quot;*chrome&quot;, “http://www.brickor.com/MBT.htm”);
    • private Selenium selenium = new DefaultSelenium(proc);
    • private Logger log = Util.setupLogger(MBTtest.class);
    • // import org.apache.log4j.Logger;
    • // import org.graphwalker.Util;
  • Writing the Java Code
    • In e_init we start the selenium object.
    • selenium.start();
    • selenium.open(&quot;http://www.brickor.com/MBT.htm&quot;);
    • Delete the Throw exception!
    • Update all e_r11, e_r12 etc
    • selenium.click(&quot;Radio1_1&quot;);
    • row1 = Integer. parseInt (selenium.getText(“r11&quot;));
  • Writing the Java Code
    • Create the utility GetResult
    • public boolean GetResult()
    • {
    • int rowTotal = row1 + row2 + row3;
    • int calcTotal = Integer. parseInt (selenium.getText(&quot;totalDiv&quot;));
    • if (rowTotal==calcTotal)
    • return true ;
    • else
    • return false ;
    • }
    • IMPORTANT!
    • Compile you class after any changes, CTRL + B
  • GraphWalker XML
    • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
    • <!DOCTYPE MBTINIT SYSTEM &quot;mbt_setup.dtd&quot; >
    • <MBTINIT EXECUTOR=&quot;java:ie.mbt.test.MBTtest&quot; EXTENDED=&quot;true&quot;>
    • <MODEL PATH=&quot;models/MBTTest.graphml&quot;/>
    • <CLASS PATH=&quot;MbtTestbin&quot;/>
    • <CLASS PATH=&quot;selenium-java-client-driver.jar&quot;/>
    • <CLASS PATH=&quot;selenium-server.jar&quot;/>
    • <GENERATOR TYPE=&quot;RANDOM&quot;>
    • <CONDITION TYPE=&quot;TEST_LENGTH&quot; VALUE=&quot;1000&quot;/>
    • </GENERATOR>
    • </MBTINIT>
  • Selenium Server
    • java -jar selenium-server.jar
    • Will start with default settings on port 4444
  • Start the scripts..
    • Command line to start GraphWalker with the correct settings:
    • java -jar graphwalker-2.5.1-SNAPSHOT-standalone.jar gui xml -f MBTTest.xml
  • Questions?
    • More info at:
    • www.graphwalker.org
    • mbt.tigris.org
    • http://en.wikipedia.org/wiki/Model-based_testing
    • Email: stefan.ekman@gmail.com