TESTING FRAMEWORKSGayatri Ghanakota
OUTLINE Introduction to Software Test Automation. What is Test Automation. Where does Test Automation fit in the software life cycle. Why do we need test automation. Test Automation using Testing frameworks. What is a testing framework. Why do we need a testing framework. Types of testing frameworks. Comparison of different frameworks. Shift from Waterfall to Agile. Test Driven Development and Behavior Driven Development. Summary
Introduction To Software TestAutomation
What is Test Automation Test automation is the use of software (under a setting of testpreconditions) to execute tests and then determine whether the actualoutcomes and the predicted outcomes are the same. For example, Windows Vista offers per-application volume. It is possibleto turn down the volume on a game while leaving Windows Media Playerplaying loud. To do this, right-click on the speaker icon in the lowerright-hand corner of your screen and select "Open Volume Mixer."Moving the slider for an application down should cause its volume todecrease. Testing this manually is easy. Just play a sound, lower thevolume, and listen. Now automating this rather than doing it manually isthe process of test automation.
Where does Test Automation fit inthe Software Life Cycle Considering the earlier software life cycles such as the waterfall modelthe test automation appears in this life cycle during the implementationand testing phase.REQUIREMENTSTEST TIONS
Why do we need Test Automation Companies not only want to test software adequately, but also as quicklyand thoroughly as possible. To accomplish this goal, organizations areturning to automated testing. To increase the test coverage Reduces the need for manual testing and discovers defects manualtesting cannot expose and also manual testing is error prone and a timeconsuming process. Running the tests again and again gives us the confidence that the newwork we added to the system did not break the code that used to workand also to make sure that the changes we introduced are working. Executing the tests (particularly acceptance tests) can also help usunderstand what portion of the desired functionality has beenimplemented.
The set of the automated test suite can form a regression test suite. Thepurpose of the regression suite is to make sure that the software behavioris unchanged unless due to data change or latest software. Automating also reduces the time taken for regression testing. Automated unit test suite helps find the problems at an earlier stage andsolve them.
Test Automation Using TestingFrameworks
What is a Testing Framework A testing framework or more specifically a testing automation framework is anexecution environment for automated tests. It is the overall system in which thetests will be automated. It is defined as the set of assumptions, concepts, and practices that constitute awork platform or support for automated testing. The Testing framework is responsible for:§ Defining the format in which to express expectations.§ Creating a mechanism to hook into or drive the application under test§ Executing the tests§ Reporting results Properties of a testing framework:§ It is application independent.§ It is easy to expand, maintain and perpetuate.
Why we need a Testing Framework If we have a group of testers and suppose if each project implements aunique strategy then the time needed for the tester become productive in thenew environment will take long. To handle this we cannot make changes to the automation environment foreach new application that comes along. For this purpose we use a testingframework that is application independent and has the capability to expandwith the requirements of each application. Also an organized test framework helps in avoiding duplication of test casesautomated across the application. In short Test frameworks helps teams organize their test suites and in turnhelp improve the efficiency of testing.
Types Of Testing dDrivenHybrid
Modular Testing Framework The Modularity testing framework is built on the concept of abstraction. This involves the creation of independent scripts that represent the modulesof the application under test. These modules in turn are used in a hierarchicalfashion to build large test cases. Thus it builds an abstraction layer for a component to hide that componentfrom the rest of the application. Thus the changes made to the other part of theapplication do not effect that component.TestScriptModule1Module2TestScript Module NModule N 1Module N 2 Module N 10
Example of Modular Testing Framework To demonstrate the modular framework we use the calculator program. Consider the basic functions of the calculator such as addition,subtraction, multiplication, division which are part of the Standard view. We create scripts for these functions as follows:Add:Sub MainWindow Set Context, "Caption Calculator", "“PushButton Click, "ObjectIndex 10“‘Press 5PushButton Click, "ObjectIndex 20“‘Press PushButton Click, "ObjectIndex 14“‘Press 6PushButton Click, "ObjectIndex 21“‘Press Result LabelUP (CompareProperties, "Text 11.", "UP Object Properties")‘Compare Expected to Actual ResultsEnd Sub
In a similar way we create scripts for subtraction, multiplication and division. At the next level of hierarchy, we create two scripts for standard view andscientific view of which the standard view contains calls to the scripts wecreated as before.Driver wDivisionLogSin
The Driver script is the top most level of hierarchy which contains the scriptsof standard and scientific view.Driver Script:Sub Main'Test the Standard ViewCallScript "Test Script Mod Framework - Standard"'Test the Scientific ViewCallScript "Test Script Mod Framework - Scientific“End SubThus this framework introduces a high level of modularization. So when thereis a change in the functionality we can change the bottom level script withouteffecting all the other test cases that test that control.
Modular Testing Framework - ContdAdvantages: Modular division of scripts leads to easier maintenance and also thescalability of the automated test suites. The functionality is available in easy to use test libraries so creating newdriver scripts for different tests is easy and fast.Disadvantages: The main problem with modular frameworks is that the test script havetest data embedded in them. So when the test data needs to be updatedwe need to change the code of the script. This becomes a big problemwhen the test script is large.For this purpose, data- driven testing frameworks have beenintroduced.
Data-Driven Testing Framework Data driven testing is where the test input and the expected output resultsare stored in a separate data file (normally in a tabular format) so that asingle driver script can execute all the test cases with multiple sets ofdata. The driver script contains navigation through the program, reading of thedata files and logging of the test status information.Driver ScriptData FileExpectedOutput Actual Output
Example of Data Driven Testing Framework To demonstrate the data driven testing framework we use the login pageof the flight reservation The first step involves creating the test data file. (testdata.csv)Test CaseAdd Number1OperatorNumber2ExpectedResult2 35Subtract3-21Multiply2*36Divide2/-2-1This data file contains the different types of input data which will be givento the driver script.
In the next step we create a driver script and make references to the testdata file.data open ( ’ testdata.csv’ ) . read ( )l i n e s data . s p l i t l i n e s ( ) #excluding the header rowfor line in lines:Read Number1Read Number2Read OperatorCalculate the result using the Operator onNumber 1 and Number2Compare the result to the expected result This driver script reads the data from the data file computes the value andcompares it with the expected result from the data file.
Data-Driven Testing Framework - ContdAdvantages: This framework reduces the number of overall test scripts needed toimplement all the test cases. Less amount of code is required to generate all the test cases. Offers greater flexibility when it comes to maintenance and fixing of bugs. The test data can be created before test implementation is ready or evenbefore the system to be tested is ready.Disadvantages: The test cases created are similar and creating new kind of tests requirescreating new driver scripts that understand different data. Thus the test dataand driver scripts are strongly related that changing either requires changingthe other.For this purpose keyword driven testing frameworks have been introduced.
Keyword- Driven Testing Framework Keyword driven testing is an application independent framework utilizingdata tables and self explanatory keywords to explain the actions to beperformed on the application under test. Not only is the test data kept in the file but even the directives tellingwhat to do which is in the test scripts is put in external input data file. These directives are called keywords. The keyword based testing is anextension to the data driven testing.Keywords/ActionsTest DatainputDriverScriptoutputTestResults
Example of Keyword Driven Testing Framework To demonstrate the keyword driven testing we take the actions performed bythe mouse when making calculations. We create a table that maps the actions performed with the mouse on thewindow of the calculator application. In this table, The windows column represents the application for which we areperforming the mouse action. The control column represents the control that we are clicking with themouse. The action column represents the action performed by the mouse. The argument column contains the specific control value.
orPushbuttonClick2CalculatorPushbuttonClick k Verify Result5CalculatorCalculatorView, rPushbuttonClick Verify Result2Calculator
After creating the table, we create a set of scripts for reading in the table, executing eachstep based on the keyword contained in the action field and logs any relevant information. The below pseudo code represents this test of scripts.Main Script / ProgramConnect to data tables.Read in row and parse out values.Pass values to appropriate functions.Close connection to data tables.ReturnMenu Module Set focus to window.Select the menu pad option.Return.Pushbutton Module Set focus to window.Push the button based on argument.Return.Verify Result Module Set focus to window.Get contents from label.ReturnCompare contents with argument value.Log results.Return.
Keyword- Driven Testing FrameworkAdvantages: It has all the advantages that data driven testing has. Automation expertise is not required to maintain or create a new set of testcases. Keywords are reused across multiple test cases.Disadvantages: The main problem is that this requires a more complicated framework thanthe data driven framework. With the keyword driven approach the test cases get longer and complexand this is due to the greater flexibility that this approach offers.So in order to combine the strengths of all the frameworks and mitigatetheir weaknesses we use the hybrid testing framework.
Hybrid Testing Framework Hybrid testing framework is the combination of modular, data-driven andkeyword driven testing frameworks. This combination of frameworks helps the data driven scripts takeadvantage of the libraries which usually accompany the keyword driventesting.Driver t ScriptNFunction LibraryKeyword and Data drivenDataFile
Example of Hybrid Testing FrameworkThe hybrid framework for the calculator can be shown as esDriver ScriptScientificViewKeyword/Actions FileTest ResultsAddLogSubSinMulCosTest Data Pool
Comparison of FrameworksApproachModular testingframeworkAdvantagesDisadvantagesModular approachReusable functionsHierarchical StructureTest data within thescripts limits reusability,Test script isdependent on software.ImprovedMaintainabilityDependency ontechnical expertise,Test script isdependent on software.Keyword driven testingframeworkEase of maintenance,Scalability, Lessdependency ofsoftware.Dependency ontechnical expertise,Requires large effortHybrid testingframeworkIntegrates theadvantages of all theother frameworks.Increased ComplexityData driven testingframework
Shift from Waterfall to Agile
We do not see a working version of the software until late in the waterfalllife cycle. Problems may be more costly to fix in this phase than they wouldhave been earlier in the life cycle. Using test automation in the water fall model with feedback does not havemany advantages as only regression testing is covered in the testautomation and every time regression testing of the previous version hasto be executed. Hence it is required to start test automation early in the softwaredevelopment life cycle. Test automation with agile methodologies has advantages compared withthe traditional life cycles as testing is done throughout the life cycleprocess. In the agile life cycle the test automation execution starts early in thesoftware life cycle.
Testing Frameworks in the Agile
Agile life cycles are characterized by short and rapid test cycles andfrequent change requests. Thus test automation plays a crucial role insoftware testing. Any type of testing framework can be implemented in the agileenvironment but with the short iterations and rapidly changingrequirements it becomes difficult to maintain the test automation suite. In the agile environments, testing plays a crucial role through the differentphases of iterations. It involves continuous integration, unit testing (whichis usually done using test driven development) and constant regressiontesting which is difficult to accomplish using testing frameworks. Also, achieving maximum code and functionality coverage using testingframeworks is difficult.Hence testing frameworks are not a good fit for the agile environment.
Test Driven Development&Behavior Driven Development
Test driven development is a technique of using automated unit tests todrive the design of software and force decoupling of dependencies.With traditional testing a successful test finds one or more defects. Butusing TDD we have a clear measure of success when the test no longerfails. Thus TDD increases our confidence that the system meets therequirements and that the system is working properly when compared tothe confidence that traditional testing provides.Why TDD? To avoid wasting time on debugging. To improve the quality of code. To increase confidence.
Behavior driven development is an extension to the test drivendevelopment in that it focuses on the behavior of the system rather thanthe implementation aspect of the system. Thus it gives a clearunderstanding of what the system should do to both the developer aswell as the customer making the testing process even more efficient.Why BDD? Promotes Outside-In Development. BDD TDD automated acceptance testing.
Summary The test framework should be application-independent. The test framework must be easy to expand, maintain, and perpetuate. Data driven testing is the quickest and easiest to implement if we have atechnical expertise. Keyword driven testing is the hardest and most time consuming but onceimplemented it is the easiest to maintain. Hybrid testing combines the advantages of all the other frameworks butrequires technical expertise and is useful for long term projects. With agile methodologies, test driven development and behavior drivendevelopment are more useful as they ensure testing of the applicationto the fullest.
References http://safsdev.sourceforge.net/Default.htm /591.html spx#mtf ch02 softwaredevelopment http://eliga.fi/Thesis-Pekka-Laukkanen.pdf http://www.agiledata.org/ 77.pdf
Select the menu pad option. Return. Pushbutton Module Set focus to window. Push the button based on argument. Return. Verify Result Module Set focus to window. Get contents from label. Return Compare