Model-Based Testing: An Evaluation - DiVA Portal

Transcription

Faculty of Economic Sciences, Communication and ITDepartment of Computer ScienceJohan NordholmModel-Based Testing: An EvaluationDegree Project of 30 ECTS credit pointsMaster of Science in Information TechnologyDate/Term:Supervisor:Examiner:Serial Number:Karlstads universitet 651 88 KarlstadTfn 054-700 10 00 Fax 054-700 14 60Information@kau.se www.kau.se2010-01-22Donald F RossKerstin AnderssonE2010:01

Model-Based Testing: An EvaluationJohan Nordholm 2010 The author(s) and Karlstad University

This thesis is submitted in partial fulfillment of the requirements for theMaster’s degree in Computer Science. All material in this report which isnot my own work has been identified and no material is included for whicha degree has previously been conferred.Johan NordholmApproved, 2010-01-22Advisor: Donald F RossExaminer: Kerstin Anderssoniii

AbstractTesting is a critical activity in the software development process in order to obtain systems ofhigh quality. Tieto typically develops complex systems, which are currently tested through alarge number of manually designed test cases. Recent development within software testinghas resulted in methods and tools that can automate the test case design, the generation of testcode and the test result evaluation based on a model of the system under test. This testingapproach is called model-based testing (MBT).This thesis is a feasibility study of the model-based testing concept and has been performedat the Tieto office in Karlstad. The feasibility study included the use and evaluation of themodel-based testing tool Qtronic, developed by Conformiq, which automatically designs testcases given a model of the system under test as input. The experiments for the feasibilitystudy were based on the incremental development of a test object, which was the clientprotocol module of a simplified model for an ATM (Automated Teller Machine) client-serversystem. The experiments were evaluated both individually and by comparison with theprevious experiment since they were based on incremental development. For each experimentthe different tasks in the process of testing using Qtronic were analyzed to document theexperience gained as well as to identify strengths and weaknesses.The project has shown the promise inherent in using a model-based testing approach. Theapplication of model-based testing and the project results indicate that the approach should befurther evaluated since experience will be crucial if the approach is to be adopted withinTieto’s organization.v

AcknowledgementsI would like to thank my supervisor Donald F Ross at Karlstad University for his guidance,feedback and encouragement during the writing of this thesis. I would also like to thank mysupervisors Sören Torstensson and Robert Magnusson at Tieto for their support during thethesis project and for the instructive discussions about software testing as well as my projectpartner Yasir Malik, from Blekinge Institute of Technology, for a great team work. Finally, Iwould like to thank Athanasios Karapantelakis and Michael Lidén at Conformiq for theQtronic course and all the support during the project.vii

Contents12Introduction . 11.1Motivation. 21.2Goals . 21.3Feasibility study . 31.4Thesis Organization . 4Background . 62.1Introduction. 62.2Software Development . 62.2.12.2.22.2.32.2.42.3Software Testing . 92.3.12.3.22.3.32.3.42.4What is model-based testing?Scope of MBTApproaches of MBTMBT processBenefitsLimitationsSummaryInterfaces . 272.6.12.6.22.6.32.6.42.6.52.7Testing processClassic testing processesTesting at TietoSummaryModel-based testing . 192.5.12.5.22.5.32.5.42.5.52.5.62.5.72.6Testing levelsTesting characteristicsTest design techniquesSummaryIntroduction to model-based testing . icationsTestingTest object (ATM)QtronicJavaTCLUMLSummary . 29ix

3Experiment. 313.1Purpose . 313.2Test System . 313.2.13.2.23.2.33.2.43.3Introductory example . 403.3.13.3.23.3.33.3.43.43.54ModelingTest generationScript rendering and test harness implementationTest executionDesign Factors in Modeling. 47Experiments . 483.5.13.5.23.5.33.5.43.6Test tool: QtronicTest objectTest scriptsTest execution environmentExperiment 1Experiment 2Experiment 3Experiment 4Summary . 68Results and Evaluation . 694.1Design Factors in Modeling. 694.2Experiment 1 . 704.2.14.2.24.2.34.2.44.2.54.3Experiment 2 . 764.3.14.3.24.3.34.3.44.3.54.4Model DevelopmentTest generationTest harness implementationTest executionResults and conclusions: experiment 2Experiment 3 . 834.4.14.4.24.4.34.4.44.4.54.5Model DevelopmentTest generationTest harness and test execution environment implementationTest executionResults and conclusions: experiment 1Model DevelopmentTest generationTest harness implementationTest executionResults and conclusions: experiment 3Experiment 4 . 884.5.14.5.24.5.34.5.44.5.5Model DevelopmentTest generationTest harness implementationTest executionResults and conclusions: experiment 44.6Summary of Experiment Results . 934.7Project Analysis . 944.7.1 Project work4.7.2 Qtronic4.7.3 Qtronic Modelerx

5Conclusion . 1025.1Results. 1025.2Discussion . 1045.3Future work . 1065.3.1 Manual test design vs. MBT5.3.2 Modeling of current applications at Tieto5.3.3 Evaluation of the tool5.4Final Comments . 107References . 108ARequirements and Specifications . 110A.1 Requirements . 110A.1.1A.1.2A.1.3A.1.4User requirementsSystem requirementsFunctional requirementsNon-functional requirements (quality requirements)A.2 Specifications . 112A.2.1A.2.2A.2.3A.2.4A.2.5A.2.6BSoftware requirements specificationSystem requirements specificationSoftware design specificationComponent specificationInterface specificationBehavioral specificationTesting . 114B.1 Terminology . 114B.1.1 GlossaryB.1.2 DefectsB.2 Testing techniques . 116B.2.1 Static techniquesB.2.2 Black-box techniquesB.2.3 White-box testing techniquesB.3 Traceability matrix . 119CTest System . 121C.1 Specifications . 121C.1.1 Version 1C.1.2 Version 2C.1.3 Version 3C.2 Qtronic . 128C.2.1 Test design configuration parametersC.2.2 Test generation optionsC.2.3 Views for test generation result analysisxi

List of FiguresFigure 1.1: Model-based testing approach . 1Figure 1.2: Feasibility study . 4Figure 2.1: Different kinds of testing . 9Figure 2.2: Overview of test design techniques [31] . 12Figure 2.3: Summary of different kinds of testing . 13Figure 2.4: Overview of the testing process at Tieto . 16Figure 2.5: Test phases at Tieto: actors and specifications . 18Figure 2.6: Scope of model-based testing [35] . 20Figure 2.7: The model-based testing process [35] . 22Figure 3.1: Qtronic stand-alone client . 32Figure 3.2: Status of the generation shown in Qtronic console . 34Figure 3.3: Test case interaction . 35Figure 3.4: ATM system overview . 36Figure 3.5: Qtronic example: Top-level state machine . 42Figure 3.6: Qtronic example: Authentication state machine . 43Figure 3.7: Qtronic example: Test Design Configuration . 43Figure 3.8: Qtronic example: Test generation progress . 44Figure 3.9: Qtronic example: Generated test cases . 44Figure 3.10: Qtronic example: Test execution . 46Figure 3.11: Experiment 1: Authentication state machine . 50Figure 3.12: Experiment 1: Authentication in top-level state machine . 51Figure 3.13: Experiment 1: State of top-level state machine . 52Figure 3.14: Experiment 2: Error handling . 56Figure 3.15: Experiment 2: QML transition example . 57Figure 3.16: Experiment 3: Biometric authentication . 62Figure 3.17: Experiment 4: QML model transition . 64Figure 4.1: Qtronic2 Client . 97xiii

Figure 4.2: Qtronic Modeler . 100Figure B.1 Example of a traceability matrix . 119Figure C.2: Specification 1: Top-level state machine . 121Figure C.3: Specification 1: Authentication state machine . 122Figure C.4: Specification 1: Withdrawal state machine. 122Figure C.5: Specification 2: Top-level state machine . 123Figure C.6 : Specification 2: Transfer state machine . 124Figure C.7: Specification 2: Deposit state machine . 124Figure C.8: Specification 3: Top-level state machine . 125Figure C.9: Specification 3: Biometric authentication state machine . 126Figure C.10: Specification 3: Balance state machine. 126Figure C.11: Specification 3: Withdrawal state machine. 127Figure C.12: Specification 3: Transfer state machine . 127Figure C.13: Specification 3: Deposit state machine . 128xiv

List of tablesTable 2.1: Overview of testing processes and approaches to test automation . 27Table 3.1: Results experiment 1 . 53Table 3.2: Results experiment 2 . 59Table 3.3: Results experiment 3 . 63Table 3.4: Results experiment 4 . 67Table 4.1: Results experiment 1 . 70Table 4.2: Results experiment 1 and experiment 2 . 76Table 4.3: Results experiment 2 and experiment 3 . 83Table 4.4: Results experiment 3 and experiment 4 . 88Table 4.5: Results summary . 93xv

1 IntroductionThe purpose of this thesis, and of the project undertaken for Tieto, is to evaluate the conceptof model-based testing (MBT) and the model-based testing tool Qtronic. This thesis is afeasibility study of the MBT approach as well as a study of Qtronic. The feasibility studyincludes the development of a test object, the creation of a model and related tasks necessaryto test the test object.QtronicTest casesGlue code:User application interfaceTest object(ATM)Glue code:Network interfaceModel(ATM)Test casesFigure 1.1: Model-based testing approachFigure 1.1 above is an illustration of the thesis work. A test object is tested using a testingtool. The testing tool (Qtronic) uses a model, describing the outwardly observable behavior ofthe test object, to generate test cases automatically. To successfully execute the test casesagainst the test object, glue code, or a test harness implementation, is required. The glue codedefines how the test scripts communicate with the system under test (the test object), i.e.sending input to and receiving output from the system under test.MBT is a black-box testing technique where common testing tasks such as test generationand test result evaluation are automated based on a model of the system under test (SUT).This approach has recently spread to a variety of software domains but originates fromhardware testing, most notably from telephone switches, and from the increasing use of objectorientation and models in software design and software development [12]. When successfullydeployed, it has been shown to yield economic benefits. Justifications of a software purchaseor deployment of a change to an existing process include traditional metrics such as cost,quality and time to market. The methodology of MBT has proven its ability to provideimprovements in all three of these areas [2].1

1.1 MotivationThe Tieto office in Karlstad develops telecommunication products and provides testingservices within the same area. Tieto is a supplier, or subcontractor, of telecommunicationsolutions and services for global actors, such as Ericsson. Thus projects at Tieto incorporatecomplex systems and products. In the development process of large and complex systemstesting is a critical activity in order to obtain a system of high quality. Testing must be donecontinuously during the development of a system, as its functionality is gradually increasing,and is necessary on a daily or at least weekly basis. Systems developed at Tieto typically havea large number of states as well as a large number of input and output signals. Thus thenumber of test cases is very high. Normally it is not possible to test all combinations of statetransitions so a representative subset of the important use cases has to be tested.Currently much of the software testing at Tieto makes use of a script-based testingapproach, where the test scripts are written manually by testers. For complex systems thisapproach results in a large number of test cases which have to be manually designed andmaintained as the system evolves. Furthermore, the test scripts are dependent on the testerimplementing the tests, hence test scripts may be difficult to maintain. Recent developmentwithin software testing has led to the development of methods and tools that can generate testcode automatically, based on a model of the system to be tested. This testing approach iscalled MBT.The MBT approach is a black-box testing technique which automates testing tasks such astest generation and test result evaluation [12] and has when deployed shown to yieldeconomic benefits [2]. Moreover, reports claim that software defects can be found earlier inthe development process using a MBT approach compared to the use of manual testingpractices [5]. The use of models to depict the behavior of a system is a proven and majoradvantage in software development [11] as well as in software testing [2]. Software modelsare now accepted as a part of modern object orientated analysis and design. Modeling is agood way of capturing knowledge about a system and then reusing this information as thesystem grows. The model may also be used as a means of communication between differentteams in an organization during development and the model may be reviewed by new teammembers to quickly come up to speed. For test teams, models provide a useful mechanism forstructured analysis of the system [2].1.2 GoalsThe general goal of this thesis is to evaluate the concept of MBT. This general goal includes apre-study of the concept as well as a feasibility study. The initial goals of the feasibility studyare to learn the MBT tool Qtronic and to implement a test object. The general goal of thefeasibility study is to apply and evaluate MBT, to document experiences and to makerecommendations for future work. To summarize, the purpose of the feasibility study is toprove the concept but also to produce guidelines for future reference, as if MBT were to beadopted at Tieto.2

The general goal of the thesis work was further divided into sub-goals.1. Learn the concepts of model-based testing2. Learn to use a tool (Qtronic) for modeling, test code generation and test execution3. Develop a framework for a finite state machine and implement a logic on theframework (with incrementally increased complexity) to be used as a test object.4. Develop a model for the test object in the test tool and try different criteria forgeneration of test code5. Establish the test environment including development of “glue” between the testcode and the test object.6. Execute the tests and incrementally make the test object and the model morecomplex.7. Evaluate the result, document the experience gained and make recommendations.The project goals listed above will be performed as they are listed, with the exception thatall goals except the initial goal, to study the theory behind the MBT concept, will beperformed in an iterative and incremental fashion.1.3 Feasibility studyThe general purpose of the feasibility study is to evaluate the concept of MBT as well as aspecific MBT tool, namely Qtronic. Specifically, the purpose is to develop a test object and totest this test object using Qtronic. The idea is that the test object will be developedincrementally while documenting experiences and results from the testing process. The testobject, and consequently the model, will be extended and modified for different experiments.Each experiment will focus on different aspects for evaluation. Since the test object will beincrementally developed the results and the experiences of the experiments will be compared.The test object is a part of a simplified model for an ATM client-server system, using anapplication layer protocol. The complete system specification includes the ATM (the client)and the central bank computer (the server), which communicates over a network. Both theclient and the server are divided into subsystems. The client consists of the user interface,where the user can withdraw money and request account balance information, and a protocolmodule. The server has a corresponding structure. The test object in the feasibility study islimited to the protocol module of the client, which consists of a finite state machine whichhandles incoming messages from two interfaces and responds with outgoing interfaces forboth interfaces. Thus the finite state machine describes the state of the protocol module andwhich outgoing message that follows an incoming message. The specifications for the finitestate machines are defined in Appendix C.1.Qtronic is the MBT tool that will be used. Qtronic automatically designs test cases given amodel of the system under test (SUT) as input. The generated test cases are black-box tests,which mean that they evaluate the SUT based only on the system’s external behavior. Thusthe models do not need to reflect the test object implementation structurally given that theydescribe the intended outwardly observable behavior [8]. The design models are expressed inthe Qtronic Modeling Language (QML), and its graphical notation, which is defined in aseparate tool, namely Qtronic Modeler. The generated test cases in Qtronic are abstract testcases that then are rendered to an executable format. In this thesis the test cases will berendered to TCL scripts.3

Qtronic renders the test cases to executable test scripts. Glue code, or a test harness, is thenimplemented using a test execution environment, i.e. a means of communicating with theSUT. The test harness is necessary to execute the test cases against the SUT.Feasibility studyExp 1Exp 2Exp 3Exp 4TimeInitial acted frommodel,implemented intest harnessFigure 1.2: Feasibility studyAs Figure 1.2 indicates, this thesis includes four experiments. The approach of the thesiswork is to incrementally develop the test object and the model for each experiment as if MBTwere deployed in a new project within the organization. Since the experiments are based onincremental development of the test object each experiment is analyzed individually but willalso be compared to the previous experiment, except for the initial experiment. The purposeof the initial experiment is to create a working model of the test object and to successfullyexecute the generated test cases. The purpose of the second experiment is to extend thespecification, thus also the test object and the model, to evaluate how added requirementspropagate through the process. The purpose of the third experiment is to change theauthentication requirements for the protocol module to see how changed requirementspropagate through the process. The specification of this experiment will require a successfulbiometric authentication to complete account requests against the central bank computer. Asecond goal of the third experiment is to model a reusable structure, i.e. encapsulate logic thatcan be reused in multiple state machines in the model. The purpose of the fourth experimentis to extract some logic from the model and implement this logic in the test harness, whileusing the same version of the specification and testing the same version of the SUT as for thethird experiment. For the specifications see Appendix C.1.1.4 Thesis OrganizationThis thesis consists of five chapters. In chapter 2 software testing is discussed in generalbefore introducing the concept of MBT. Software testing is discussed to place MBT in theperspective of traditional testing approaches and its testing scope. Chapter 3 includes adescription of the whole test system, an introductory example of the testing process in thisproject as well as experiment descriptions and corresponding results. The analysis and thediscussion of each experiment are provided in chapter 4. Chapter 4 also includes an analysisof this project and evaluations of Qtronic and Qtronic Modeler. In chapter 5 the conclusions4

from the project are described. The conclusions include the results, a discussion of the projectand suggestions for future work that may be performed in the context of this project area.5

2 Background2.1 IntroductionThis background chapter includes the pre-study of the project. The chapter starts with section2.2 by briefly discussing the process of software development and the roles of requirementsand specifications in the process. Section 2.3 is an introduction to software testing, includingcharacteristics and levels of testing as well as testing techniques. The concept of model-basedtesting (MBT) is introduced in section 2.5 and includes the different approaches, the processas well as benefits and limitations. The chapter ends with section 2.6 which briefly describesthe interfaces used in this project.2.2 Software DevelopmentAs an introduction to software testing some basic concepts of software development will bediscussed. These will be described to place software testing in an overall perspective of thesoftware development process as well as to introduce the requirements and basic ideas fortesting.2.2.1 ProcessA software process is a set of activities and associated results which lead to the production ofa software product. Such activities may include software development from scratch or byextending and modifying existing systems [33].Today there are a number of software development processes deployed in the industry,such as Scrum [32], eXtreme Programming [3] and Rational Unified Process [23]. However,there is no ideal process and different organizations have developed different approaches tosoftware development. Although there are many different software processes used, there arefundamental activities which are common to all software processes [33]:1. Software specification: The functionality of the software and constraints on itsoperation must be defined.2. Software design and implementation: The software to meet the specification mustbe produced.3. Software validation: The software produced must be validated to ensure that itfulfills its purpose.4. Software evolution: In many cases the software must evolve to meet the changingcustomer requirements.2.2.2 RequirementsSoftware engineers often have to solve complex problems. Understanding the nature of theproblems can be very difficult, especially if the system is new, and hence it is difficult toestablish exactly what the system should do. The descriptions of the services and

model-based testing tool Qtronic, developed by Conformiq, which automatically designs test cases given a model of the system under test as input. The experiments for the feasibility study were based on the incremental development of a test object, which was the client protocol module of a simplified model for an ATM (Automated Teller Machine .