text:
Software test automation
ACM PRESS BOOKS This book is published as part of ACM Press Books - a collaboration between the Association for Computin...
Author: Mark Fewster | Dorothy Graham
491 downloads 3436 Views 8MB Size Report
ACM PRESS BOOKS This book is published as part of ACM Press Books - a collaboration between the Association for Computing (ACM) and Addison Wesley Longman Limited. ACM is the oldest and largest educational and scientific society in the information technology field. Through its high-quality publications and services, ACM is a major force in advancing the skills and knowledge of IT professionals throughout the world. For further information about ACM, contact: ACM Member Services
ACM European Service Center
1515 Broadway, 17th Floor
108 Cowley Road
Oxford 0X4 1JF
Fax: +44-1865-381388 E-mail: [email protected] URL: http://www.acm.org
Selected ACM titles Component Software: Beyond Object-Oriented Programming Clemens Szyperski The Object Advantage: Business Process Reeingineering with Object Technology (2nd edn) Ivar Jacobson, Maria Ericsson, Agneta Jacobson, Gunnar Magnusson Object-Oriented Software Engineering: A Use Case Driven Approach Ivar Jacobson, Magnus Christerson, Patrik Jonsson, Gunnar Overgaard Software for Use: A Practical Guide to the Models and Methods of Usage Centered Design Larry L Constantine, Lucy A D Lockwood Bringing Design to Software: Expanding Software Developments to Include Design Terry Winograd, John Bennett, Laura de Young, Bradley Hartfield CORBA Distributed Objects: Using Orbix Sean Baker Software Requirements and Specifications: A Lexicon of Software Practice, Principles and Prejudices Michael Jackson Business Process Implementation: Building Workflow Systems Michael Jackson, Graham Twaddle Interacting Processes: A Multiparty Approach to Coordinated Distributed Programming Nissim Francez, Ira Forman Design Patterns for Object-Oriented Software Development Wolfgang Free Software Testing in the Real World: Improving the Process Ed Kit Test Process Improvement: A Practical Step-by-Step Guide to Structured Testing Tim Koomen, Martin Pol Requirements Engineering and Rapid Development: An Object-Oriented Approach Ian Graham
Software Test Automation Effective use of test execution tools MARK FEWSTER DOROTHY GRAHAM
ACM Press New York
Addison-Wesley An imprint of Pearson Education Harlow, England • London • Reading, Massachusetts Menlo Park, California • New York Don Mills, Ontario * Amsterdam • Bonn Sydney • Singapore • Tokyo * Madrid San Juan • Milan • Mexico City • Seoul • Taipei
PEARSON EDUCATION LIMITED Head Office: Edinburgh Gate Harlow CM20 2JE Tel:+44 (0)1279 623623 Fax: +44 (0) 1279 431059
London Office: 128 Long Acre London WC2E 9AN Tel:+44 (0)20 7447 2000 Fax: +44 (0)20 7240 5771
Website: www.awl.com/cseng/ h'irsl published in Grout liriUiiu 1994 Copyright'«') by ACM Press, A Division of the Association for Computing Machinery Inc. (ACM) The rights of Mark Fewstcr and Dorothy Graham to be identified as authors of this work have been asserted by them in accordance with the Copyright, Designs and Patents Act 1988. ISBN 0-201-33140-3 British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library. Library of Congress Cataloging in Publication Data Fewster, Mark, 1959Soltvvarc lest automation / Mark Fcwster, Dorothy Graham. p. cm. "ACM Press books" -CIP facing t.p. Includes bibliographical references and index. ISBN 0-201-33140-3 (pbk. : alk. paper) 1. Computer software-Testing-Automation. I. Graham, Dorothy, 1944. II. Title. QA76.76.T48F49 1999 005. l'4-dc21 99-35578 CIP All rights reserved; no part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without either the prior written permission of the Publishers or a licence permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London VV1P OLP. The programs in this book have been included for their instructional value. The publisher does not offer any warranties or representations in respect of their fitness for a particular purpose, nor does the publisher accept any liability for any loss or damage arising from their use. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Pearson Education has made every attempt to supply trademark information about manufacturers and their products mentioned in this book. A list of the trademark designations and their owners appears on page xviii. 10 9 8 7 6 5 4 3 Typeset by Panlek Arts, Maidstonc, Kent. Printed and bound in Great Britain by Biddies Ltd, Guildford and King's Lynn. The Publishers' policy is to use paper manufactured from sustainable forests.
Part 1: Techniques for Automating Test Execution
Test automation context 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
Introduction Testing and test automation are different The V-model Tool support for life-cycle testing The promise of test automation Common problems of test automation Test activities Automate test design? The limitations of automating software testing Summary
Capture replay is not test automation
An example application: Scribble The manual test process: what is to be automated? Automating test execution: inputs Automating test result comparison The next steps in evolving test automation Conclusion: automated is not automatic Summary
Scripting techniques
3.1 Introduction 3.2 Scripting techniques 3.3 Script pre-processing Summary
4 Automated comparison 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10
Verification, comparison, and automation What do comparators do? Dynamic comparison Post-execution comparison Simple comparison Complex comparison Test sensitivity Comparing different types of outcome Comparison filters Comparison guidelines Summary
5 Testware architecture 5.1 5.2 5.3 5.4
What is testwarc architecture? Key issues to be resolved An approach Might this be overkill? Summary
6 Automating pre- and post-processing
What are prc- and post-processing? Pre- and post-processing What should happen after test case execution? Implementation issues Summary
7 Building maintainable tests 7.1 7.2 7.3 7.4
Problems in maintaining automated tests Attributes of test maintenance The conspiracy Strategy and tactics Summary
8 Metrics
8.1 8.2 8.3 8.4 8.5 8.6 8.7
Why measure testing and test automation? What can we measure? Objectives for testing and test automation Attributes of software testing Attributes of test automation Which is the best test automation regime? Should I really measure all these? Summary
Other issues 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8
Which tests should be automated (first)? Selecting which tests to run when Order of test execution Test status Designing software for (automated) testability Synchronization Monitoring progress of automated tests Tailoring your own regime around your tools Summary
10 Choosing a tool to automate testing 10.1 Introduction to Chapters 10 and 11 10.2 Where to start in selecting tools: your requirements, not the tool market 10.3 The tool selection project 10.4 The tool selection team 10.5 Identifying your requirements 10.6 Identifying your constraints 10.7 Build or buy? 10.8 Identifying what is available on the market 10.9 Evaluating the shortlisted candidate tools 10.10 Making the decision Summary
11 Implementing tools within the organization 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.10
What could go wrong? Importance of managing the implementation process Roles in the implementation/change process Management commitment Preparation Pilot project Planned phased installation or roll-out Special problems in implementing testing tools People issues Conclusion Summary
Part 2: Test Automation Case Studies and Guest Chapters Introduction: case studies and guest chapters 12 Racal-Redac case history Mark Fewster and Keiron Marsden 12.1 Introduction 12.2 Background
Solutions Integration test automation System test automation The results achieved Summary of the case history up to 1991 What happened next?
13 The evolution of an automated software test system 326 Marnie Hutcheson 13.1 Introduction 13.2 Background 13.3 Gremlin 1 13.4 Gremlin 2.0: a step beyond capture replay 13.5 Finding the real problem 13.6 Lessons learned
13.7 Summary
14 Experiences with test automation Clive Bates 14.1 Background 14.2 Planning, preparation, and eventual success 14.3 Benefits of test automation 14.4 Lessons learned 14.5 The way forward 14.6 Summary
15 Automating system testing in a VMS environment Peter Oakley 15.1 Background 15.2 The first attempt at automation 15.3 New tool selection and evaluation 15.4 Implementation of V-Test 15.5 Conclusion
16 Automated testing of an electronic stock exchange Paul Herzlich 16.1 Background 16.2 The system and testing 16.3 Test automation requirements 16.4 Test tool selection 16.5 Implementation 16.6 Maturity and maintenance 16.7 Our results
17 Insurance quotation systems tested automatically every month
Simon Mills 17.1 Background: the UK insurance industry 17.2 The brief, or how I became involved 17.3 Why automation? 17.4 Our testing strategy 17.5 Selecting a test automation tool 17.6 Some decisions about our test automation plans 17.7 The test plan 17.8 Some additional issues we encountered 17.9 A telling tale: tester versus automator 17.10 Summary
18 Three generations of test automation at ISS Steve Allott 18.1 Introduction 18.2 The software under test 18.3 First generation 18.4 Second generation 18.5 Third generation 18.6 Three generations: a summary
19 Test automation failures: lessons to be learned Stale Amland 19.1 Introduction 19.2 The projects 19.3 Problems 19.4 Recommendations 19.5 Pilot project 19.6 Epilogue
20 An unexpected application of test automation
Bob Bartlett and Susan Windsor 20.1 Introduction and background 20.2 Helping the bank make its product selection 20.3 Doing the testing 20.4 Automated testing 20.5 The results
21 Implementing test automation in an Independent Test Unit Lloyd Roden 21.1 Introduction and background 21.2 The evaluation process
The implementation phase The deployment of the tool How QARun has been used Problems we have experienced The benefits achieved in two years Conclusion
22 Testing with Action Words Hans Buwalda 22.1 Introduction 22.2 Test clusters 22.3 The navigation 22.4 The test development life cycle 22.5 Applicability for other types of tests 22.6 Templates: meta-clusters 22.7 Summary 23 Regression testing at ABN AMRO Bank Development International Iris Pinkster 23.1 Background 23.2 Problems with conventional testing 23.3 Pilot project using TestFrame 23.4 Regression test project 23.5 Spin-offs 23.6 Future 23.7 Summary
24 Business Object Scenarios: a fifth-generation approach to automated testing Graham Dwyer and Graham Freeburn 24.1 Introduction 24.2 The five generations of testware development 24.3 RadSTAR 24.4 Window-centric Scenario Libraries 24.5 Business Object Scenarios 24.6 Mixing Business Object Scenarios with existing tests 24.7 Reuse versus repeatability 24.8 Conclusion
25 A test automation journey
Jim Thomson 25.1 Introduction 25.2 First steps 25.3 An off-the-shelf automated test foundation: RadSTAR
25.4 How we have implemented automated testing using RadSTAR 25.5 Payback
26 Extracts from The Automated Testing Handbook Linda Hayes 26.1 Introduction to this chapter 26.2 Introduction to the Handbook 26.3 Fundamentals of test automation 26.4 Test process and people 26.5 Test execution: analyzing results 26.6 Test metrics 26.7 More information about the Handbook
27 Building maintainable GUI tests
Chip Groder
Introduction and background Cost drivers Test planning and design Well-behaved test cases Encapsulated test set-up Putting it all together Summary
28 Test automation experience at Microsoft
Angela Smale 28.1 History 28.2 Batch files 28.3 Capture/playback tools 28.4 Scripting language 28.5 Cosmetic dialog box testing 28.6 Help testing tool 28.7 Tools to randomize test execution 28.8 What should I automate first? 28.9 My top ten list for a successful test automation strategy
In a better world than ours, there would be magic. If you had a problem, you'd approach a wise old magician who embodied the experience of years of study and practice. You'd give the magician some money. In return, you would receive a magical object to make your problem go away. We don't have magic, but we do have technology. And, as Arthur C. Clarke famously wrote, 'any sufficiently advanced technology is indistinguishable from magic.' That brings us to test automation. As a tester or test manager, one of your problems is that developers keep changing the product. They introduce new bugs in what used to work. You're responsible for finding those bugs. To do that, you re-execute tests you've already run. The yield (bugs found per test) is low. You need a way to make the cost (human effort) correspondingly low. Only then can you escape the trap of spending so much time re-running old tests that you have no time to create new ones. So why not give your money to a magician (test automation tool vendor) and receive a magical object (testing tool) that will make the problem go away? Simply create the test once and let the tool take it from there. Why not? The technology isn't sufficiently advanced. In untutored hands, the magic object won't work. Without the magician's touch, it will be dead ... rotting . . . a destructive distraction from the job of finding bugs. That's where this book comes in. It will teach you how to.make automated testing tools useful, instead of a big rat hole down which to pour your precious time and budget. It embodies the experience of a fantastic number of people who have suffered through trial and error. Reports about what they've learned have been too scattered: a conference paper here, a few pages in a book there, a conversation over beers somewhere else. Mark Fewster and Dorothy Graham have taken that scattered experience and made it accessible, concise, specific, and systematic. I wish I'd read this book in 1981. I'd have spent less time trying and much less time erring. Brian Marick Principal SQA Practitioner, Reliable Software Technologies
What this book is about This book describes how to structure and build an automated testing regime that will give lasting benefits in the use of test execution tools to automate testing on a medium to large scale. We include practical advice for selecting the right tool and for implementing automated testing practices within an organization. An extensive collection of case studies and guest chapters are also included, reflecting both good and bad experiences in test automation together with useful advice.
Who is this book for? This book is intended to be of most help to those starting out on the road to automation, so they do not have to spend time discovering the hard way the most likely problems and how to avoid them. The target audience for this book includes: • •
potential and recent purchasers of test execution automation tools; those who already have a test execution automation tool but are having problems or are not achieving the benefit they should; « people responsible for test automation within an organization; • anyone who is building an in-house test execution automation tool; • technical managers who want to insure that test automation provides benefits; • testers and test managers who want to insure that tests are automated well; • management consultants and test consultants; • test tool vendors.
Why should I read this book? If you want to automate testing (not just automate a few standalone tests) then this book will be useful to you. Specifically: » » «
if you automate on a small scale, you will pick up some useful tips; if you automate hundreds of tests, this book will help you do so efficiently; if you automate thousands of tests, you will be more certain of long-term success if you follow the advice given in this book (or have discovered it for yourself).
You do not need to read this book: » « » »
if you plan to run all your tests manually, forever; if you only hope to automate a few tests, say up to a dozen or so; if your tests will only be run once and will never be needed again; if you don't care that your test automation actually takes longer and costs more than manual testing.
The more tests you automate, the more benefit you can gain from this book.
Spaghetti tests? An analogy for the main subject of this book is structured programming. Before structured techniques were used, there was little discipline in software engineering practices. It appeared that all you needed to know was a programming language and how to work the compiler. This led to serious problems with 'spaghetti code,' i.e. code that was difficult to understand, hard to test, and expensive to maintain. The search for a solution led eventually to a disciplined approach, where requirements were analyzed and software designed before the code was written. The benefits of a structured approach included greatly increased maintainability, understandability, and testability of the software produced. Today, test execution tools are very popular, particularly capture replay tools, but there is little discipline in the design of the test automation in many organizations. The obvious benefits of test execution tools are in automating a tedious but necessary task, that of regression testing. However, there is an assumption that all you need to know is a scripting language and how to work the test execution tool. This approach leads to 'spaghetti tests' that are hard to understand and difficult and expensive to maintain, thereby negating the benefits of automating testing. This book is about 'testware design techniques' that are parallel to the 'software design techniques' of 20 or more years ago.
What this book does not include We do not include any information about specific tools currently on the market (except where they are mentioned in the case studies in Part 2). This is intentional, for two reasons. First, this book is about techniques that are applicable using any test execution tool, available now or in the near future. This book therefore contains generic principles that are not restricted to any existing specific tools. Second, the test execution tool market is very volatile, so any specific information would soon become out of date. This book does not include techniques for testing, i.e. for designing good test cases. Although an important topic, it is outside the scope of this book (that's our next project). This book covers the automation of test execution, not the automatic generation of test inputs, for reasons explained in Chapter 1.
How to read this book This book is designed so that you can dip into it without having to read all of the preceding chapters. There arc two parts to the book. Part 1 is technical and will give you the techniques you need to construct an efficient test automation regime. Part 2 contains case studies of test automation in a variety of organizations and with varying degrees of success, plus some guest chapters giving useful advice. Any chapter in Part 2 can be read on its own, although there are two sets of paired chapters. A guided tour of the content of the case studies is given in the introduction to Part 2. We have used some terms in this book that are often understood differently in different organizations. We have defined our meaning of these terms in the Glossary at the end of the book. Glossary terms appear in bold type the first time they are used in the book. The table on the next page shows our recommendations for the chapters that you may like to read first, depending on your objectives.
Guided tour to Part 1: techniques for automating test execution Each chapter in Part 1 concludes with a summary, which contains an overview of what is covered in that chapter. Here we outline the main points of each chapter. Chapter 1 is a general introduction to the content of the book. We discuss testing and the difference between the testing discipline and the subject of this book, and we explain why we have concentrated on test execution automation. If you have not yet experienced the difference between post-purchase euphoria and the grim reality of what a tool will and will not do for you,
Read these chapters first
Shopping for a test execution tool
1, 2, and 10
A manager wondering why test automation has failed
1, 2, 7, and 8
Using a test execution tool to automate tests, i.e. you will be writing scripts, etc.
2, 3, 4, and 5 (and then 6, 7, 8, and 9)
Concerned with achieving the best benefits from testing and test automation
1 and 8
Having difficulty persuading other people in your organization to use the tools you already have in place
1 and 11
Wanting to know what other people have done
Any chapter in Part 2
Wanting to know why we think we know the answers to the problems of test automation
Having problems with maintenance of automated tests
7, then 3 and 5
Wanting to know what other people advise
22, 24, 26, 27, and 28
Interested in 'failure' stories
19, then 13
Chapter 2 will open your eyes. A simple application ('Scribble') is tested manually and then taken through typical initial stages of the use of a capture replay tool. Chapters 3-9 contain the technical content of the book. Chapter 3 describes five different scripting techniques. Chapter 4 discusses automated comparison techniques. Chapter 5 describes a practical testware architecture. Chapter 6 covers automation of set-up and clear-up activities. Chapter 7 concentrates on testware maintenance. Chapter 8 discusses metrics for measuring the quality of both testing and of an automation regime. Chapter 9 brings together a number of other important topics. The next two chapters deal with tool evaluation and selection (Chapter 10) and tool implementation within the organization (Chapter 11).
Acknowledgments We would like to thank the following people for reviewing early drafts of this book: Yohann Agalawatte, Steve Allott, Stale Amland, Hans Buwalda, Greg Daich, Peter Danson, Norman Fenton, Dave Gelperin, Paul Gerrard, David Hedley, Bill Hctzel, Herb Isenberg, Ed Kit, David Law, Shari Lawrence-Pfleeger, Aidcn Magill, Pat McGee, Geoff Quentin, David Ramsay, Krystyna Rogers, Hans Schaefer, Melanie Smith, Graham Titterington, Otto Vintcr, Jelena Vujatov, Stuart Walker, Robin Webb, and Kerry Zallar.
We are particularly grateful to the authors of the case studies, for taking the time out of their busy schedules to prepare their material. Thanks to Keiron Marsden for bringing up to date the case history in Chapter 12, Marnie Hutcheson for sharing insights and lessons learned, and Clive Bates, Peter Oakley, Paul Herzlich, Simon Mills, Steve Allott, Bob Bartlett, Susan Windsor and Lloyd Roden for chapters on automation in various UK industries. Special thanks to Marnie Hutcheson and Stale Amland for sharing experiences that were not as successful as they might have been, and to all the authors for their honesty about problems encountered. Thanks to two sets of authors who have given us a description and experience story of using what we consider to be good ways of achieving efficient and maintainable automation: Hans Buwalda and Iris Pinkster for the 'Action Words' approach, and Graham Freeburn, Graham Dwyer, and Jim Thomson for the 'RadSTAR' approach. We are particularly grateful to the US authors of the final three chapters: Linda Hayes has kindly given permission to reproduce a number of sections from her Test Automation Handbook, Chip Groder has shared his insights in building effective test automation for GUI systems over many years, and Angela Smale gives useful advice based on her experiences of automating the testing for different applications at Microsoft. Thanks to Roger Graham for his support and for writing our example application 'Scribble'. Thanks to Sally Mortimore, our editor, for her support, enthusiasm, and patience over the past three years. We would also like to thank those who have attended our tutorials and courses on test automation and have helped us to clarify our ideas and the way in which we communicate them. Some parts of this book first appeared in different forms in the following publications: The CAST Report, Cambridge Market Intelligence, 1995 (Chapters 10 and 11) The Journal of Software Testing, Verification and Reliability, 1991, Sigma Press, now published by Wiley (Chapter 12) Proceedings of the International Conference on Testing Computer Software, 1991 (Chapter 12) Proceedings of the EuroSTAR conference, 1993 (Chapter 7). Please accept our apologies if we have not included anyone in this acknowledgment that we should have.
Mark Fewster and Dorothy Graham, May 1999 http://www.grove.co. uk
Mark Fewster Mark has 20 years of industrial experience in software engineering, half of this specializing in software testing. He has been a software developer and manager for a multi-platform graphical application vendor, where he was responsible for the implementation of a testing improvement programme and the successful development and implementation of a testing tool which led to dramatic and lasting savings for the company. Mark spent two years as a consultant for a commercial software testing tool vendor, providing training and consultancy in both test automation and testing techniques. Since joining Grove Consultants in 1993, Mark has provided consultancy and training in software testing to a wide range of companies. As a consultant, Mark has helped many organizations to improve their testing practices through improved process and better use of testing tools. Mark serves on the committee of the British Computer Society's Specialist Interest Group in Software Testing (BCS SIGIST). He has also been a member of the Information Systems Examination Board (ISEB) working on a qualification scheme for testing professionals and served on the BCS SIGIST working party that drafted the Software Component Testing Standard BS7925-1. He has published papers in respected journals and is a popular speaker at national and international conferences and seminars.
Dorothy Graham Dorothy has worked in the area of Software Testing for more than 25 years, first for Bell Telephone Laboratories in New Jersey and then with Ferranti Computer Systems in the UK. Before founding Grove Consultants she worked for the National Computing Centre developing and presenting software engineering training courses. She originated the CAST Report on Computer-Aided Software Testing Tools, published by Cambridge Market Intelligence, and is co-author with Tom Gilb of Software Inspection (Addison-Wesley, 1993). She has written articles for a number of technical journals, and is a frequent and popular keynote and tutorial speaker at national and international conferences and seminars. Dot was Programme Chair for the first EuroSTAR Conference in 1993. She is on the editorial boards of the Journal for Software Testing, Verification and Reliability and the Software Testing & Quality Engineering magazine, and is a board member for the International Conference on Testing Computer Software (an annual conference in Washington DC USA) and the Information Systems Examination Board for Software Testing (ISEB). Grave Consultants' Web site: www.grovc.co.uk
Techniques for automating test execution
Trademark notice TestFrame™ is a trademark of CMC Automator; QA™, QA Centre™, QARun™ arc trademarks of Compuware; SQA Robot™, SQA Team Test™, SQA Manager™, V-Test™ are trademarks of Cyrano (formerly Systems FX); DEC VMS™ is a trademark of DEC Digital Test Manger; (DTM)™ is a trademark of Digital; RadSTAR™ is a trademark of IMI Systems Inc./Integrated Computer Technologies Ltd; 123™ is a trademark of Lotus; WinRunner™, XRunner™ are trademarks of Mercury Interactive; Windows®95, Windows^S, NT, 3.1™, Word®, Excel™, FoxPro™, IE3™, IE4™, Source Safe™ are registered trademarks and trademarks of Microsoft Corporation; Oracle™, Personal Oracle™ are trademarks of Oracle; PSenterprise™ is a trademark of Peterborough Software; PRODIGY™, Gremlin™ are trademarks of Prodigy Services Company; QA Partner™, AutoTester™ are trademarks of Segue Software Inc; SQL Anywhere™ is a trademark of Sybase; QEMM™ is a trademark of Quarterdeck International Ltd; SPSS® is a registered trademark of SPSS (UK) Ltd.
Permissions acknowledgment The publisher and the authors would like to thank the following for permission to reproduce material in this book. Paul Godsafe for the Experience Report (p. 41) about Squat the robot dog, from his presentation 'Automated testing', at the British Association of Research Quality Assurance 13th International Conference, May 1998, Glasgow; Computer Weekly for the Experience Report (p. 61) Bug in jet engine downs Microsoft's high-flyer, published on 10 September 1998, Computer Weekly, Quadrant House, The Quandrant, Sutton, Surrey SM2 5AS UK; Herb Isenbcrg, for the Experience Report (p. 97) adapted from 'Flexible testing systems', published in Dr Dobb's journal, June 1995, pp. 88-95. Dr Dobb's Journal, P.O. Box 56188, Boulder, CO 80322-6188 USA; Robert Glass for Experience Report (p. 282) 'Testing automation, a horror story', originally published in The Software Practitioner, Mar-Apr 1995, published by Computing Trends, 1416 Sare Road, Bloomington, Indiana 47401 USA; Chris Kcmerer (p. 284), for information from 'How the learning curve affects CASE tool adoption', published in IEEE Software, May 1992, IEEE Service Center, 445 Hoes Lane, Piscataway, NJ 08855-1331 USA. The section supplied by Susan Windsor and Bob Bartlett is gratefully received from SIM Group Ltd as a small representation of the many fascinating success stories SIM Group has achieved with automated testing over the years. The fact that SIM Group have consistently made significant differences to projects through the use of automated testing is reason enough for this book to exist. The Publishers and the Authors wish to thank Angela Smale (nee McAuley) for permission to include details of her experience as a Test Manager at Microsoft Corporation in Chapter 28.
At first glance, it seems easy to automate testing: just buy one of the popular test execution tools, record the manual tests, and play them back whenever you want to. Unfortunately, as those who tried it have discovered, it doesn't work like that in practice. Just as there is more to software design than knowing a programming language, there is more to automating testing than knowing a testing tool.
Software must be tested to have confidence that it will work as it should in its intended environment. Software testing needs to be effective at finding any defects which are there, but it should also be efficient, performing the tests as quickly and cheaply as possible. Automating software testing can significantly reduce the effort required for adequate testing, or significantly increase the testing which can be done in limited time. Tests can be run in minutes that would take hours to run manually. The case studies included in this book show how different organizations have been able to automate testing, some saving significant amounts of money. Savings as high as 80% of manual testing effort have been achieved. Some organizations have not saved money or effort directly but their test automation has enabled them to produce better quality software more quickly than would have been possible by manual testing alone. A mature test automation regime will allow testing at the 'touch of a button' with tests run overnight when machines would otherwise be idle. Automated tests are repeatable, using exactly the same inputs in the same sequence time and again, something that cannot be guaranteed with manual testing. Automated testing enables even the smallest of maintenance changes to be fully tested with minimal effort. Test automation also
eliminates many menial chores. The more boring testing seems, the greater the need for tool support. This book will explain the issues involved in successfully automating software testing. The emphasis is on technical design issues for automated testware. Testware is the set of files needed for ('automated') testing, including scripts, inputs, expected outcomes, set-up and clear-up procedures, files, databases, environments, and any additional software or utilities used in automated testing. (See the Glossary for definitions of terms used in this book, which appear in bold the first time they are used.) In this introductory chapter we look at testing in general and the automation of (parts of) testing. We explain why we think test execution and result comparison is more appropriate to automate than test design, and describe the benefits, problems, and limitations of test automation. A regime is a system of government. This book is about how to set up a regime for test automation. A test automation regime determines, among other things, how test automation is managed, the approaches used in implementing automated tests, and how testware is organized.
1.2 Testing and test automation are different 1.2.1 Testing
Testing is a skill. While this may come as a surprise to some people it is a simple fact. For any system there is an astronomical number of possible test cases and yet practically we have time to run only a very small number of them. Yet this small number of test cases is expected to find most of the defects in the software, so the job of selecting which test cases to build and run is an important one. Both experiment and experience have told us that selecting test cases at random is not an effective approach to testing. A more thoughtful approach is required if good test cases are to be developed. What exactly is a good test case? There are four attributes that describe the quality of a test case; that is, how good it is. Perhaps the most important of these is its defect detection effectiveness, whether or not it finds defects, or at least whether or not it is likely to find defects. A good test case should also be exemplary. An exemplary test case should test more than one thing, thereby reducing the total number of test cases required. The other two attributes are both cost considerations: how economical a test case is to perform, analyze, and debug; and how evolvable it is, i.e. how much maintenance effort is required on the test case each time the software changes. These four attributes must often be balanced one against another. For example, a single test case that tests a lot of things is likely to cost a lot to perform, analyze, and debug. It may also require a lot of maintenance each time the software changes. Thus a high measure on the exemplary scale is likely to result in low measures on the economic and evolvable scales. So the skill of testing is not only in ensuring that test cases will find a high proportion of defects, but also ensuring that the test cases are well designed to avoid excessive costs.
1.2.2 Test automation Automating tests is also a skill but a very different skill from testing. Many organizations are surprised to find that it is more expensive to automate a test than to perform it once manually. In order to gain benefits from test automation, the tests to be automated need to be carefully selected and implemented. Automated quality is independent of test quality. Whether a test is automated or performed manually affects neither its effectiveness nor how exemplary it is. It doesn't matter how clever you are at automating a test or how well you do it, if the test itself achieves nothing then the end result is a test that achieves nothing faster. Automating a test affects only how economic and evolvable it is. Once implemented, an automated test is generally much more economic, the cost of running it being a mere fraction of the effort to perform it manually. However, automated tests generally cost more to create and maintain. The better the approach to automating tests the cheaper it will be to implement them in the long term. If no thought is given to maintenance when tests are automated, updating an entire automated test suite can cost as much, if not more, than the cost of performing all of the tests manually. Figure 1.1 shows the four quality attributes of a test case in a Keviat diagram. A test case performed manually is shown by the solid lines. When that same test is automated for the first time, it will have become less evolvable and less economic (since it has taken more effort to automate it). After the automated test has been run a number of times it will become much more economic than the same test performed manually. For an effective and efficient suite of automated tests you have to start with the raw ingredient of a good test suite, a set of tests skillfully designed by a tester to exercise the most important things. You then have to apply automation skills to automate the tests in such a way that they can be created and maintained at a reasonable cost.
The person who builds and maintains the artifacts associated with the use of a test execution tool is the test automator. A test automator may or may not also be a tester; he or she may or may not be a member of a test team. For example, there may be a test team consisting of user testers with business knowledge and no technical software development skills. A developer may have the responsibility of supporting the test team in the construction and maintenance of the automated implementation of the tests designed by the test team. This developer is the test automator. It is possible to have either good or poor quality testing. It is the skill of the tester which determines the quality of the testing. It is also possible to have either good or poor quality automation. It is the skill of the test automator which determines how easy it will be to add new automated tests, how maintainable the automated tests will be, and ultimately what benefits test automation will provide.
The V-model
Having made the important distinction between testing and automation, we return to the topic of testing in more detail. Testing is often considered something which is done after software has been written; after all, the argument runs, you can't test something that doesn't exist, can you? This idea makes the assumption that testing is merely test execution, the running of tests. Of course, tests cannot be executed without having software that actually works. But testing activities include more than just running tests. The V-model of software development illustrates when testing activities should take place. The V-modcl shows that each development activity has a corresponding test activity. The tests at each level exercise the corresponding development activity. The same principles apply no matter what software life cycle model is used. For example, Rapid Application Development (RAD) is a series of small Vs. The simplified V-model in Figure 1.2 shows four levels of development and testing activity. Different organizations may have different names for each stage; it is important that each stage on the left has a partner on the right, whatever each is called. The most important factor for successful application of the V-model is the issue of when the test cases are designed. The test design activity always finds defects in whatever the tests are designed against. For example, designing acceptance test cases will find defects in the requirements, designing system test cases will find defects in the functional specification, designing integration test cases will find defects in the design, and designing unit test cases will find defects in the code. If test design is left until the last possible moment, these defects will only be found immediately before those tests would be run, when it is more expensive to fix them. Test design does not have to wait until just before tests are run; it can be done at any time after the information which those tests are based on becomes available. Then the effect of finding defects is actually beneficial rather than destructive, because the defects can be corrected before they are propagated.
Of course, the tests cannot be run until the software has been written, but they can be written early. The tests are actually run in the reverse order to their writing, e.g. unit tests are written last but are run first.
1.4 Tool support for life-cycle testing Tool support is available for testing in every stage of the software development life cycle; the different types of tools and their position within the life cycle are shown in Figure 1.3, using alternative names for development stages.
Test design tools help to derive test inputs or test data. Logical design tools work from the logic of a specification, an interface or from code, and are sometimes referred to as test case generators. Physical design tools manipulate existing data or generate test data. For example, a tool that can extract random records from a database would be a physical design tool. A tool that can derive test inputs from a specification would be a logical design tool. We discuss logical design tools more fully in Section 1.8. Test management tools include tools to assist in test planning, keeping track of what tests have been run, and so on. This category also includes tools to aid traceability of tests to requirements, designs, and code, as well as defect tracking tools. Static analysis tools analyze code without executing it. This type of tool detects certain types of defect much more effectively and cheaply than can be achieved by any other means. Such tools also calculate various metrics for the code such as McCabe's cyclomatic complexity, Halstead metrics, and many more. Coverage tools assess how much of the software under test has been exercised by a set of tests. Coverage tools are most commonly used at unit test level. For example, branch coverage is often a requirement lor testing safety-critical or safety-related systems. Coverage tools can also measure the coverage of design level constructs such as call trees. Debugging tools are not really testing tools, since debugging is not part of testing. (Testing identifies defects, debugging removes them and is therefore a development activity, not a testing activity.) However, debugging tools are often used in testing, especially when trying to isolate a low-level defect. Debugging tools enable the developer to step through the code by executing one instruction at a time and looking at the contents of data locations. Dynamic analysis tools assess the system while the software is running. For example, tools that can detect memory leaks are dynamic analysis tools. A memory leak occurs if a program does not release blocks of memory when it should, so the block has 'leaked' out of the pool of memory blocks available to all programs. Eventually the faulty program will end up 'owning' all of the memory; nothing can run, the system 'hangs up' and must be rebooted (in a non-protected mode operating system). Simulators are tools that enable parts of a system to be tested in ways which would not be possible in the real world. For example, the meltdown procedures for a nuclear power plant can be tested in a simulator. Another class of tools have to do with what we could call capacity testing. Performance testing tools measure the time taken for various events. For example, they can measure response times under typical or load conditions. Load testing tools generate system traffic. For example, they may generate a number of transactions which represent typical or maximum levels. This type of tool may be used for volume and stress testing. Test execution and comparison tools enable tests to be executed automatically and the test outcomes to be compared to expected outcomes. These tools are applicable to test execution at any level: unit, integration,
system, or acceptance testing. Capture replay tools are test execution and comparison tools. This is the most popular type of testing tool in use, and is the focus of this book.
1.5 The promise of test automation Test automation can enable some testing tasks to be performed far more efficiently than could ever be done by testing manually. There are also other benefits, including those listed below. 1. Run existing (regression) tests on a new version of a program. This is perhaps the most obvious task, particularly in an environment where many programs are frequently modified. The effort involved in perform ing a set of regression tests should be minimal. Given that the tests already exist and have been automated to run on an earlier version of the program, it should be possible to select the tests and initiate their execution with just a few minutes of manual effort. 2. Run more tests more often. A clear benefit of automation is the ability to run more tests in less time and therefore to make it possible to run them more often. This will lead to greater confidence in the system. Most people assume that they will run the same tests faster with automation. In fact they tend to run more tests, and those tests are run more often. 3. Perform tests which would be difficult or impossible to do manually. Attempting to perform a full-scale live test of an online system with say 200 users may be impossible, but the input from 200 users can be simu lated using automated tests. By having end users define tests that can be replayed automatically, user scenario tests can be run at any time even by technical staff who do not understand the intricacies of the full busi ness application. When testing manually, expected outcomes typically include the obvious things that are visible to the tester. However, there are attributes that should be tested which are not easy to verify manually. For example a graphical user interface (GUI) object may trigger some event that does not produce any immediate output. A test execution tool may be able to check that the event has been, triggered, which would not be possible to check without using a tool. 4. Better use of resources. Automating menial and boring tasks, such as repeatedly entering the same test inputs, gives greater accuracy as well as improved staff morale, and frees skilled testers to put more effort into designing better test cases to be run. There will always be some testing which is best done manually; the testers can do a better job of manual testing if there are far fewer tests to be run manually. Machines that would otherwise lie idle overnight or at the weekend can be used to run automated tests. 5. Consistency and repeatability of tests. Tests that are repeated automati cally will be repeated exactly every time (at least the inputs will be; the
outputs may differ due to timing, for example). This gives a level of consistency to the tests which is very difficult to achieve manually. The same tests can be executed on different hardware configurations, using different operating systems, or using different databases. This gives a consistency of cross-platform quality for multi-platform products which is virtually impossible to achieve with manual testing. The imposition of a good automated testing regime can also insure consistent standards both in testing and in development. For example, the tool can check that the same type of feature has been implemented in the same way in every application or program. 6. Reuse of tests. The effort put into deciding what to test, designing the tests, and building the tests can be distributed over many executions of those tests. Tests which will be reused are worth spending time on to make sure they are reliable. This is also true of manual tests, but an automated test would be reused many more times than the same test repeated manually. 7. Earlier time to market. Once a set of tests has been automated, it can be repeated far more quickly than it would be manually, so the testing elapsed time can be shortened (subject to other factors such as avail ability of developers to fix defects). 8. Increased confidence. Knowing that an extensive set of automated tests has run successfully, there can be greater confidence that there won't be any unpleasant surprises when the system is released (providing that the tests being run are good tests!). In summary, more thorough testing can be achieved with less effort, giving increases in both quality and productivity.
Common problems of test automation
There are a number of problems that may be encountered in trying to automate testing. Problems which come as a complete surprise are usually more difficult to deal with, so having some idea of the type of problems you may encounter should help you in implementing your own automation regime. Most problems can be overcome, and this book is intended to help you deal with them. We describe some of the more common problems below. 1. Unrealistic expectations. Our industry is known for latching onto any new technical solution and thinking it will solve all of our current problems. Testing tools are no exception. There is a tendency to be optimistic about what can be achieved by a new tool. It is human nature to hope that this solution will at last solve all of the problems we are currently experiencing. Vendors naturally emphasize the benefits and successes, and may play down the amount of effort needed to achieve lasting benefits. The effect of optimism and salesmanship together is to encourage unrealistic expectations. If management expectations are unrealistic,
then no matter how well the tool is implemented from a technical point of view, it will not meet expectations. 2. Poor testing practice. If testing practice is poor, with poorly organized tests, little or inconsistent documentation, and tests that are not very good at finding defects, automating testing is not a good idea. It is far better to improve the effectiveness of testing first than to improve the efficiency of poor testing. Automating chaos just gives faster chaos.
3. Expectation that automated tests will find a lot of new defects. A test is most likely to find a defect the first time it is run. If a test has already run and passed, running the same test again is much less likely to find a new defect, unless the test is exercising code that has been changed or could be affected by a change made in a different part of the software, or is being run in a different environment. Test execution tools are 'replay' tools, i.e. regression testing tools. Their use is in repeating tests that have already run. This is a very useful thing to do, but it is not likely to find a large number of new defects, particularly when run in the same hardware and software environment as before. Tests that do not find defects are not worthless, even though good test design should be directed at trying to find defects. Knowing that a set of tests has passed again gives confidence that the software is still working as well as it was before, and that changes elsewhere have not had unforeseen effects. 4. False sense of security. Just because a test suite runs without finding any defects, it does not mean that there are no defects in the software. The tests may be incomplete, or may contain defects themselves. If the expected outcomes are incorrect, automated tests will simply preserve those defective results indefinitely. 5. Maintenance of automated tests. When software is changed it is often nec essary to update some, or even all, of the tests so they can be re-run successfully. This is particularly true for automated tests. Test maintenance effort has been the death of many test automation initiatives. When it takes more effort to update the tests than it would take to re-run those tests manually, test automation will be abandoned. One of the purposes of this book is to help you make sure that your test automation initia tive does not fall victim to high maintenance costs. 6. Technical problems. Commercial test execution tools are software prod ucts, sold by vendor companies. As third-party software products, they are not immune from defects or problems of support. It is perhaps a double disappointment to find that a testing tool has not been well tested, but unfortunately, it does happen. Interoperability of the tool with other software, either your own applications or third-party products, can be a serious problem. The technological environment changes so rapidly that it is hard for the
vendors to keep up. Many tools have looked ideal on paper, but have simply failed to work in some environments. The commercial test execution tools are large and complex products, and detailed technical knowledge is required in order to gain the best from the tool. Training supplied by the vendor or distributor is essential for all those who will use the tool directly, particularly the test automa-tor(s) (the people who automate the tests). In addition to technical problems with the tools themselves, you may experience technical problems with the software you are trying to test. If software is not designed and built with testability in mind, it can be very difficult to test, either manually or automatically. Trying to use tools to test such software is an added complication which can only make test automation even more difficult. 7. Organizational issues. Automating testing is not a trivial exercise, and it needs to be well supported by management and implemented into the culture of the organization. Time must be allocated for choosing tools, for training, for experimenting and learning what works best, and for promoting tool use within the organization. An automation effort is unlikely to be successful unless there is one person who is the focal point for the use of the tool, the tool 'champion.' Typically, the champion is a person who is excited about automating testing, and will communicate his or her enthusiasm within the company. This person may be involved in selecting what tool to buy, and will be very active in promoting its use internally. More detail on the role of the champion is given in Chapters 10 and 11. Test automation is an infrastructure issue, not just a project issue. In larger organizations, test automation can rarely be justified on the basis of a single project, since the project will bear all of the start-up costs and teething problems and may reap little of the benefits. If the scope of test automation is only for one project, people will then be assigned to new projects, and the impetus will be lost. Test automation often falls into decay at precisely the time it could provide the most value, i.e. when the software is updated. Standards are needed to insure consistent ways of using the tools throughout the organization. Otherwise every group may develop different approaches to test automation, making it difficult to _ transfer or share automated tests and testers between groups. Even a seemingly minor administrative issue such as having too few licenses for the people who want to use the tool can seriously impact the success and the cost of a test automation effort. Perceptions of work effort may also change. If a test is run overnight, then when the testers arrive in the morning, they will need to spend some time looking through the results of the tests. This test analysis time is now clearly visible as a separate activity. When those tests were run manually, this test analysis time was embedded in the test execution activity, and was therefore not visible. Whenever a new tool (or indeed any new process) is implemented, there are inevitably adjustments that need to be made to adapt to new
ways of working, which must be managed. Chapter 11 discusses ways in which you can insure successful implementation of test automation within an organization.
Test activities
In this section, we describe testing activities, since these are the activities that we may want to automate. There is wide variation in the way in which these activities are carried out in different organizations. Some organizations will perform all of these activities formally. Others may be informal to the point of being almost chaotic. In any case, the core activities are still carried out more or less in the sequence described in Figure 1.4.
In an ideal world, testing should start with the setting of organizational test objectives and test policy, the setting of test strategies to meet test objectives, and policies and strategies for individual projects. Test planning at the management level would include estimating the time required for all test activities, scheduling and resourcing of test activities, monitoring the progress of testing, and taking any actions required to keep the entire test effort on track. These high-level activities should be done at the beginning of a project and continued throughout its development. Test cases will typically be developed for various functional areas of the system to be tested. Each of these test cases will go through five distinct development activities (not including re-testing). The five test development activities are sequential for any one test case, i.e. the test conditions must be identified before a test case for those conditions can be designed, a test case must be designed before it can be built, built before it can be run, and run before its results can be compared. The five steps may be done formally, with documentation at each step, or all five steps may be done informally when the tester sits down to test. Note that there arc many variations of terminology in testing. We have defined what we mean by each term in the Glossary. 1.7.1 Identify test conditions The first activity is to determine 'what' can be tested and ideally to prioritize these test conditions. A test condition is an item or event that could be verified by a test. There will be many different test conditions for a system, and for different categories of test, such as functionality tests, performance tests, security tests, etc. Testing techniques help testers derive test conditions in a rigorous and systematic way. A number of books on testing describe testing techniques such as equivalence partitioning, boundary value analysis, cause-effect graphing, and others. A bibliography about books on testing and other topics can be found on the authors' web site (http://www.grove.co.uk). These include Kit (1995), Marick (1995), Beizer (1990, 1995), Kaner et al. (1993), Myers (1979), and Hetzel (1988). Test conditions are descriptions of the circumstances that could be examined. They may be documented in different ways, including brief sentences, entries in tables, or in diagrams such as flow graphs. Note that the activity of identifying test conditions is best done in parallel with the associated development activities, i.e. on the left-hand side of the V-model. 1.7.2 Design test cases Test case design determines how the 'what' will be tested. A test case is a set of tests performed in a sequence and related to a test objective, i.e. the reason or purpose for the tests. Test case design will produce a number of tests comprising specific input values, expected outcomes, and any other information needed for the test to run, such as environment prerequisites.
Note that the expected outcomes include things that should be output or created, things that should be changed or updated (in a database, for example), things that should not be changed, and things that should be deleted. The set of expected outcomes could be of considerable size. An example test case is given in Table 1.1. Note that the tester performing this test case would need to understand the purchase order system at least to the extent that he or she would know how to create a new order, verify a purchase order, print a new orders report, and so on. The following three test conditions are exercised by this test case: • • e
order created for a single item (VB10); order quantity of 100 (VB23); order cancelled (V8).
The tags in parentheses at the end of each condition are used for cross-referencing between test conditions and test cases. The tags used here represent test conditions derived using equivalence partitioning and boundary value analysis. VB10 is the 10th Valid Boundary, VB23 is the 23rd Valid Boundary, and V8 is the 8th Valid equivalence partition. Table 1.1 An example test case. This comprises five steps (each of which may be considered a single 'test') and exercises three different test conditions.
Test case: POS1036
Prerequisites: • logged into the purchase order system as a data entry clerk with the main menu displayed; • database system must contain the standard Data Set; • there must be no other new purchase order activity on the system.
Create a new order for any one standard order item, setting order quantity to
Order confirmation message displayed
Jest conditions VB10 VB23
exactly 100 2
Confirm the order
Purchase order printed with correct details
VB10 VB23
Print a new orders report
New orders report printed showing just this one new order
Cancel the order
Purchase order cancellation notice printed with correct details
Report printed showing no outstanding purchase orders
This example test case is taken out of a larger set of test cases. It is assumed that we have already tested other aspects such as the correct printing of purchase orders. In this example test case, we are therefore using some 'trusted' functionality in order to test different aspects. In the last column we have noted the condition tags covered. Steps 2 and 3 also exercise the same tags as step 1, and step 4 and step 5 exercise V8. Note that this style of test case is what we will define in Chapter 2 as a Vague manual test script.' Each test should specify the expected outcome. If the expected outcome is not specified in advance of it being run, then in order to check whether or not the software is correct, the first actual outcome should be carefully examined and verified. This will, of course, require a tester with adequate knowledge of the software under test to make a correct assessment of the outcome. If correct, it can then become the future expected outcome, i.e. the outcome to which future actual outcomes from this test can be automatically compared. This approach is referred to as reference testing. The validated expected outcome is sometimes referred to as the golden version. Test case design (ideally with expected outcomes predicted in advance) is best done in parallel with the associated development activities on the left-hand side of the V-model, i.e. before the software to be tested has been built.
1.7.3 Build the test cases The test cases are implemented by preparing test scripts, test inputs, test data, and expected outcomes. A test script is the data and/or instructions with a formal syntax, used by a test execution automation tool, typically held in a file. A test script can implement one or more test cases, navigation, setup or clear-up procedures, or verification. A test script may or may not be in a form that can be used to run a test manually (a manual test script is a test procedure). The test inputs and expected outcome may be included as part of a script, or may be outside the script in a separate file or database. The preconditions for the test cases must be implemented so that the tests can be executed. For example, if a test uses some data from a file or database, that file or database must be initialized to contain the information that the test expects to find. A test case may require special hardware or software to be available, for example a network connection or a printer. This would also form part of the environment needed to be set up before the test case could be run. The expected outcomes may be organized into files for automation tools to use. For manual testing, they may simply be notes on the manual test procedure or script. Setting up expected outcomes for automated comparison may be considerably more complex than setting up expected outcomes for manual testing. The tools require everything to be spelled out in great detail, so much more rigor is required than for manual testing. Any aspects of the test building activity that can be prepared in advance, i.e. on the left-hand side of the V-model, will save time later.
1.7.4 Execute the test cases
The software under test is executed using the test cases. For manual testing, this may consist of the testers sitting down and possibly following a printed manual procedure. They would enter inputs, observe outcomes, and make notes about any problems as they go. For automated testing, this may involve starting the test tool and telling it which test cases to execute. Test execution can only be done after the software exists, i.e. it is an activity on the right-hand side of the V-model. 1.7.5 Compare test outcomes to expected outcomes
The actual outcome of each test must be investigated to see if the software being tested worked correctly. This may be informal confirmation of what the tester expects to see, or it may be a rigorous and detailed comparison of the exact actual outcomes with expected outcomes. The comparison of some outcomes such as messages sent to a screen can be performed while the test is being executed. Other outcomes, such as a change to database records, can only be compared after the test case execution has completed. An automated test may need to use a combination of these two approaches. See Chapter 4 for more about comparison techniques. The assumption is that if the actual and expected outcomes are the same, then the software has passed the test; if they are different, then the software has failed the test. This is actually an oversimplification. All we can say is that if the actual and expected outcomes do not match, then something needs to be investigated. It may be that the software is incorrect, or it could be that the test was run in the wrong sequence, the expected outcomes were incorrect, the test environment was not set up correctly, or the test was incorrectly specified. There is a difference between comparing and verifying; a tool can compare but cannot verify. A tool can compare one set of test outcomes to another, and can flag any differences between the two. But the tool cannot say whether or not the outcomes are correct - this is verification, and is normally done by testers. It is the testers who confirm or insure that the results being compared arc in fact correct. In some special circumstances, it is possible to automate the generation of expected outcomes but this is not the case for most of the industrial testing done using commercial test execution tools. See Poston (1996) for a discussion of automated oracles, reversers, and referencers.
1.8 Automate test design? 1.8.1 Activities amenable to automation
As shown in Figure 1.5, the first two test activities, identify test conditions and design test cases, are mainly intellectual in nature. The last two activities, execute test cases and compare test outcomes, are more clerical in nature. It is the intellectual activities that govern the quality of the test cases. The clerical activities are particularly labor intensive and are therefore well worth automating.
In addition, the activities of test execution and comparison are repeated many times, while the activities of identifying test conditions and designing test cases are performed only once (except for rework due to errors in those activities). For example, if a test finds an error in the software, the repeated activities after the fix will be test execution and comparison. If a test fails for an environmental reason such as incorrect test data being used, the repeated test activities would be test building, execution, and comparison. If tests are to be run on different platforms, then those same three activities would be repeated for each platform. When software is changed, regression tests are run to insure that there are no side effects. A regression test will repeat the test execution and comparison activities (and possibly also test building). Activities that are repeated often are particularly good candidates for automation. All of the test activities can be performed manually, as human testers have been doing for many years. All of the test activities can also benefit from tool support to some extent, but we believe it is in automating the latter test activities where there is most to gain. The focus of this book is on the automation of the test execution and comparison activities. However, we cannot ignore the automation of test design activities in a book on test automation, since the output of such tools may (or may not) be in a format that can easily be used by a test execution tool. The next section discusses different types of test design automation tools. (Skip to Section 1.9 if this topic does not interest you.)
1.8.2 Automating test case design
Can the activities of test case design be automated? There are a number of ways in which testing tools can automate parts of test case design. These tools are sometimes called test input generation tools and their approach is useful in some contexts, but they will never completely replace the intellectual testing activities. One problem with all test case design approaches is that the tool may generate a very large number of tests. Some tools include ways of minimizing the tests generated against the tester's specified criteria. However the tool may still generate far too many tests to be run in a reasonable time. The tool cannot distinguish which tests are the most important; this requires creative intelligence only available from human testers. A tool will never be able to answer questions such as: 'If we only have time to test 30% of what we could test, which are the most important test cases to run?' Even if the testing is automated, there may still be insufficient time to run 100% of the automated tests. All test generation tools rely on algorithms to generate the tests. The tools will be more thorough and more accurate than a human tester using the same algorithm, so this is an advantage. However, a human being will think of additional tests to try, may identify aspects or requirements that are missing, or may be able to identify where the specification is incorrect based on personal knowledge. The best use of test generation tools is when the scope of what can and cannot be done by them is fully understood. (Actually that applies to the use of any tool!) We will look at three types of test input generation tools, based on code, interfaces, and specifications. 1.8,2.1 Code-based test input generation
Code-based test input generation tools, shown in Figure 1.6, generate test inputs by examining the structure of the software code itself. A path through the code is composed of segments determined by branches at each decision point. A profile of the logical conditions required for each path segment can therefore be produced automatically. This is useful in conjunction with coverage measurement. For example, some coverage tools can identify logical path segments that have not been covered.
This approach generates test inputs, but a test also requires expected outcomes to compare against. Code-based test case design cannot tell whether the outcomes produced by the software are the correct values - it is the specification for the code that tells you what it should do. So this approach is incomplete, since it cannot generate expected outcomes. A test oracle is the source of what the correct outcome should be; code-based test input generation has no test oracle. Another problem with this approach is that it only tests code that exists and cannot identify code that is missing. It is also testing that 'the code does what the code does.' This is generally not the most useful kind of testing, since we normally want to test that 'the code does what it should do.' (We once saw a defect report dismissed with the phrase: 'software works as coded' (not 'as specified').) This approach cannot find specification defects or missing specifications. Another type of code-based test design automation can generate tests to satisfy weak mutation testing criteria. Mutation testing is where the code or an input is changed in some small way to see if the system can correctly deal with or detect this slightly mutated version. This is used to assess the fault tolerance of systems and the adequacy of test suites. For more information, see Voas and McGraw (1998). 1.8.2.2 Interface-based test generation
An interface-based test input generation tool, shown in Figure 1.7, is one that can generate tests based on some well-defined interface, such as a GUI or a web application. If a screen contains various menus, buttons, and check boxes, a tool can generate a test case that visits each one. For example, a tool could test that a check box has a cross in it when checked and is empty when not checked (similarly fundamental tests can be automated on other graphical interactors). Other examples include selecting each field and seeing if Help works, trying to edit data in all display-only fields, performing a spell check in help text and legends, and checking that something pops up when each menu item is selected. A similar function is found in tools to test internet and intranet pages. The tool can activate each link on a World Wide Web page, and then do the same for each of the pages linked to, recursively.
An interface-based approach is useful in identifying some types of defect (for example, any web page links that do not work can be identified). An expected outcome can be partially generated, but only in a very general sense and only negatively, i.e. a link should be there (correct result), not broken (incorrect result). This type of automated test generation cannot tell you whether working links are in fact linked to the right place. This approach can therefore perform parts of the test design activity, generating test inputs (one test for each interface element identified by the tool), and can be a partial oracle, which enables some errors to be identified. It can be very useful in performing 'roll-call' testing, i.e. checking that everything which should be there is there. This type of testing is tedious to do manually, but is often very important to do thoroughly. Tool support of this nature will probably increase in the future, and may help to free testers from tedious tasks so that they have more time to perform the intellectual testing activities. 1.8.2.3 Specification-based test generation
Specification-based test tools can generate test inputs and also expected outputs, provided that the specification is in a form that can be analyzed by the tool. This is shown in Figure 1.8. The specification may contain structured natural language constructs, such as business rules, or it may contain technical data such as states and transitions. Tools can derive tests from object-oriented specifications, if they are sufficiently rigorous. Hence these tools do have a test oracle. For example, if the allowable ranges for an input field are rigorously defined, a tool can generate boundary values, as well as sample values in valid and invalid equivalence classes. For more information see Poston (1996). Some specification-based tools can derive tests from structured English specifications, or from cause-effect graphs. This can identify some types of specification defect such as ambiguities and omissions. A benefit of a specification-based approach is that the tests are looking at what the software should do, rather than what it does do, although only within the limited scope of the existing tool-examinable specification. The more tedious it is to derive test cases from a specification, the higher the potential for this type of tool. Expected outcomes can be generated if they are stored in the specification, assuming that the stored specification is actually correct.
1.8.2.4 Summary of test design automation
Summary of the benefits of automated test case generation: » automates tedious aspects of test case design, such as activating every menu item or calculating boundary values from known data ranges; « can generate a complete set of test cases with respect to their source (code, interface, or specification); » can identify some types of defect, such as missing links, non-working window items, or software that does not conform to a stored specification. Summary of the limitations of automated test case generation: • • «
code-based methods do not generate expected outcomes; interface-based methods can only generate partial expected outcomes; code-based and interface-based methods cannot find specification defects; » specification-based methods depend on the quality of the specification; » all methods may generate too many tests to be practical to run; » human expertise is still needed to prioritize tests, to assess the usefulness of the generated tests, and to think of the tests that could never be generated by any tool.
It is our contention that the automation of the intellectual part of testing is much more difficult to do, and cannot be done as fully as automation of the more clerical part of testing. When we refer to 'automating software testing' in the rest of this book, we mean the automation of test execution and comparison activities, not the automation of test design or generation of test inputs.
The limitations of automating software testing
As with all good things, nothing comes without a price. Automated testing is not a panacea, and there are limitations to what it can accomplish. 1.9.1 Does not replace manual testing
It is not possible, nor is it desirable, to automate all testing activities or all tests. There will always be some testing that is much easier to do manually than automatically, or that is so difficult to automate it is not economic to do so. Tests that should probably not be automated include: » tests that are run only rarely. For example if a test is run only once a year, then it is probably not worth automating that test; » where the software is very volatile. For example, if the user interface and functionality change beyond recognition from one version to the next, the effort to change the automated tests to correspond is not likely to be cost effective;
tests where the result is easily verified by a human, but is difficult if not impossible to automate; for example, the suitability of a color scheme, the esthetic appeal of a screen layout, or whether the correct audio plays when a given screen object is selected; tests that involve physical interaction, such as swiping a card through a card reader, disconnecting some equipment, turning power off or on.
Not all manual tests should be automated - only the best ones or the ones that will be re-run most often. A good testing strategy will also include some exploratory or lateral testing,1 which is best done manually, at least at first. When software is unstable, manual testing will find defects very quickly. 1.9.2 Manual tests find more defects than automated tests A test is most likely to reveal a defect the first time it is run. If a test case is to be automated, it first needs to be tested to make sure it is correct. (There is little point in automating defective tests!) The test of the test case is normally done by running the test case manually. If the software being tested has defects that the test case can reveal, it will be revealed at this point, when it is being run manually. James Bach reported that in his (extensive) experience, automated tests found only 15% of the defects while manual testing found 85%. Source: Bach, 1997
Once an automated test suite has been constructed, it is used to re-run tests. By definition, these tests have been run before, and therefore they are much less likely to reveal defects in the software this time. The test execution tools are not 'testing' tools, they are 're-testing' tools, i.e. regression testing tools. 1.9.3 Greater reliance on the quality of the tests
A tool can only identify differences between the actual and expected outcomes (i.e. compare). There is therefore a greater burden on the task of verifying the correctness of the expected outcomes in automated testing. The tool will happily tell you that all your tests have passed, when in fact they have only matched your expected outcomes. It is therefore more important to be confident of the quality of the tests that are to be automated. Testware can be reviewed or inspected to insure 1
Testing should be systematic, rigorous, and thorough in order to be effective at finding defects. However, there is also a valid role in testing for a more intuitive approach to supplement a rigorous approach. This is referred to in most testing books as 'error guessing.' We prefer to call it 'lateral testing,' after the latcrial thinking techniques of Edward DC Bono.
its quality. Inspection is the most powerful review technique, and is very effective when used on test documentation. This technique is described in Gilb and Graham (1993). 1.9.4 Test automation does not improve effectiveness
Automating a set of tests does not make them any more effective (or exemplary) than those same tests run manually. Automation can eventually improve the efficiency of the tests; that is, how much they cost to run and how long they take to run. But it is likely that automation will adversely affect the evolvability of the test, as discussed in Section 1.2 and shown in Figure 1.1.
1.9.5 Test automation may Limit software development Automated tests arc more 'fragile' than manual tests. They may be broken by seemingly innocuous changes to software. The techniques described in this book will help you produce automated tests that are less fragile than they would be otherwise, but they will always be more vulnerable to changes in the application software than manual tests. Because automated tests take mor.e effort to set up than manual tests, and because they require effort to maintain, this in itself may restrict the options for changing or enhancing software systems or applications. Software changes with a high impact on the automated testware may need to be discouraged for economic reasons.
1.9.6 Tools have no imagination A tool is only software, and therefore can only obediently follow instructions. Both a tool and a tester can follow instructions to execute a set of test cases, but a human tester, given the same task, will perform it differently. For example, if a human tester is given the task of running a prepared test procedure, he or she may follow that procedure to begin with, and will check that the actual outcomes are correct. However, the tester may realize that although the software conforms to the expected outcomes, both are wrong. The human tester can also use his or her creativity and imagination to improve the tests as they are performed, either by deviating from the plan or preferably by noting additional things to test afterwards. Another way in which human testers are superior to testing tools is when unexpected events happen that are not a part of the planned sequence of a test case. For example, if a network connection is lost and has to be re-established, a human tester will cope with the problem in the middle of the test, and do whatever is necessary. Sometimes, the tester will do this without even realizing that the test has deviated from the plan. However an unexpected event can stop an automated test in its tracks. Of course, the tools can be programmed to cope with some types of event, but
just as astronauts have discovered, there is nothing like human ingenuity to overcome problems.
Summary Test tools aren't magic - but, properly implemented, they can work wonders! Source: Hayes, 1995
Test automation is not the same as testing, and the skills needed to be a good test automator are not the same skills needed to be a good tester. Testing should fit into the software development process at every stage. Test cases are best identified and designed early (on the left-hand side of the V-model), but can only be executed and compared after the software is available for testing (the right-hand side of the V-model). Tool support is available for all types of test activities throughout the development life cycle, though none of them can (or will ever be able to) make any testing activity completely automatic. The automation of testing holds great promise and can give significant benefits, such as repeatable consistent regression tests that are run more often, testing of attributes that are difficult to test manually, better use of resources, reuse of tests, earlier time to market, and increased confidence. However, many problems typically arise when attempting to automate testing, including unrealistic expectations, poor testing practices, a false sense of security, maintenance costs, and other technical and organizational problems. Although there are ways to support test case design activities, we consider that automating the more clerical and tedious aspects of testing generally gives more benefit than trying to automate the more intellectual test activities. This book therefore concentrates on the test activities of executing test cases and comparing outcomes. This is what we mean by automating software testing. Test automation has its limitations. It does not replace manual testing, and manual testing will find more defects than automated testing. There is a greater reliance on the correctness of expected outcomes. Test automation does not improve test effectiveness, and can limit software development options. The testing tools have no imagination and are not very flexible. However, test automation can significantly increase the quality and productivity of software testing.
If you don't know better, it is tempting to think that the quickest way to automate testing is to simply turn on the record facility of a capture replay tool when the tester sits down to test. The recording can then be replayed by the tool, thereby repeating the test exactly as it was performed manually. Unfortunately, many people also believe that this is all there is to test automation. We will show why this is far from the truth. This chapter describes the way test automation typically evolves when a capture replay tool is brought in for the first time. Using an example application, we examine the manual testing process, which is where the automation will start. The automation of test execution is normally accompanied by the automation of test verification, but even this leaves a lot to be desired in terms of a fully automated testing regime. This chapter shows why automating tests is not the same as automating testing.
2.1 An example application: Scribble Our example application is called Scribble. It is a very simple word processor, for the purpose of illustrating the points we wish to make. Real applications will be far more complex, and that makes the problems of automating their testing correspondingly more complex as well. 2.1.1 Example test case: editing a List in Scribble
A feature of Scribble is that a document can include a structure known as a List. The example test case that we use in this chapter exercises some of the List editing functions. The way it works is illustrated in Figure 2.1. Starting from the initial state with just one item in the List (Netherlands), we add a new item, Belgium (using the Add Item function), which is added to the end of the List. Next we sort the List, which changes
the order of the two items. When we add the third item (Denmark), it is inserted into the List in the correct place, since it is now a sorted rather than an unsorted List. Finally, we delete the first item in the list (Belgium) by selecting Delete item and entering the position number. 2.1.2 The test for a Scribble List Now we are ready to test (manually) our application. We will test the editing of a List in a document called countries.dcm (the suffix 'dcm' stands for 'document'). The starting state is a sorted List of three items. The test case will perform the following: • • • • •
add two new items to the sorted List; move an item (which makes the List unsorted); add an item to the unsorted List; delete an item; try to delete an item which isn't there (invalid position number).
The edited document will be saved as countries2.dcm. This is not a very rigorous test case and of course there will need to be others to adequately test this functionality. However, we have chosen the above test case as being reasonable for our purposes. The execution of the test case is shown in the series of screen shots in Figure 2.2.
Screen 1 Invoke Scribble.
Screen 2 File menu: Open.
Screen 3 Select countries. dcm to open.
Screen 4 Countries file opened.
Screen 5 List menu: Add selected.
Figure 2.2 The screen shots for our example test case for Scribble.
Screen 6 Add Item: Sweden.
Screen 7 Sweden added in order.
Screen 8 List menu: Add Item.
Screen 9 Add Item: USA.
Screen 10 USA added in order.
Screen 11 List menu: Move Item.
Figure 2.2 Continued
Screen 12 Move from position 4 to i.
Screen 13 UK now at top (list unsorted).
Screen 14 List menu: Add Item.
Screen 15 Add Norway to unsorted list.
Screen 16 Norway added at end.
Screen 17 List menu: Delete Item.
Screen 18 Delete item at position 2.
Screen 19 Belgium deleted.
Screen 20 List me nu: Delete I te m.
Screen 21 Try to delete position 7.
Screen 22 Error message: invalid position.
Screen 23 File menu: Close.
Screen 24 Wish to save?
Screen 25 Save as countries2.
Screen 26 Scribble main menu.
Screen 27 File menu: Exit.
2.1.3 What was the test input? In the test case above, we have entered input to take the application from its initial invocation to completion, entering specific data to perform the test case. The specific key presses and/or mouse actions that we have performed are shown in Table 2.1. Note that we have described our actions in terms of the logical elements on the screen rather than their physical locations, for example, 'List menu' rather than 'bit position (445, 120).' Note also that all mouse clicks listed are left mouse button. Table 2.1 What was actually entered to run the Scribble test. Action/input 1 Move mouse to Scribble icon
23 Move mouse to List menu
2 Double click
24 Click
3 Move mouse to File menu
25 Move mouse to Move Item
47 Move mouse to Delete Item
5 Move mouse to Open option
27 Type '4'
49 Type 7'
28 Press TAB key
50 Move mouse to OK button
7 Move mouse to
29 Type T
30 Press Return key
9 Move mouse to List menu
countries.dcm in file list
54 Move mouse to File menu
33 Move mouse to Add Item
56 Move mouse to Close
35 Type 'Norway'
13 Type 'Sweden'
58 Move mouse to Yes button
60 Type 'countries2'
64 Move mouse to Exit
20 Type 'USA'
2,2 The manual test process: what is to be automated? The test case that we have just carried out manually in the example above is the test case that we will now try to automate using a capture replay tool. The amount of effort it takes to automate a single test case depends on a number of things and varies widely. Experienced automators typically report it takes between 2 and 10 times the effort required to run the test manually, and occasional reports have said it is as high as 30 times the manual test effort. Thus, a test case that takes half an hour to perform manually may well take between 1 and 5 hours to automate, but could also take as much as 15 hours. When you start automating, expect it to take at least five times longer to automate a test than to run it manually. Some of the things that affect the amount of effort required to automate a test case include the following: » The tool used. Tools provide a variety of facilities and features designed to make creating automated tests easy, and increasingly allow testers to specify during recording more about how the test should behave when being replayed. « The approach to test automation. There are a number of different approaches we can use to create Automated tests, though the first approach most people use is to record the test being performed manually and then replay this recording. Other approaches require additional effort to modify recorded scripts or prepare scripts manually. While this does take longer initially the idea is to make it easier to implement new tests and reduce maintenance costs. » The test automator's level of experience. Clearly, people who are very familiar with using a testing tool will be able to use it more quickly and with fewer mistakes. They should also be able to avoid implementations that do not work well and concentrate on those that do. » The environment. Where the software to be tested runs in specific environments that are difficult to replicate precisely for testing, it can be more difficult to automate testing. For example, embedded software and real time software are particularly troublesome as these can require specialized tools or features that may not be commercially available. » The software under test. The tests for software applications that have no user interaction, such as batch programs, are much easier to automate providing the environment in which they execute can be reproduced. This is because user interaction has to be 'programmed' and this can be a lot of work. Although this can be recorded it does not result in a cost-effective solution in the long term. A batch program has no user interaction but is controlled from information passed to it when invoked or read from files or databases during execution. There arc also many facets of software applications that can make testing, and in particular automated testing, more difficult. There are many testing issues to consider when designing software applications
and often it is the design of the software itself that will make or break automating testing. • The existing test process. When automating testing we are automating some of the five activities that make up the test process (identification of test conditions, design of test cases, build the tests, execution, and comparison of expected outcomes with actual outcomes) as described in Chapter 1. The consequences of this are our next point of discussion. The effect of the existing test process on the effort required to automate testing is immense. If test cases are not documented but the testers make them up as they go, then automating the test cases will involve designing them as well. At the other extreme, if the test cases are documented in great detail such that every input and comparison is noted, then automating them will require less effort. In the following subsections we describe three broad categories of test process: ad hoc testing, where the test cases have not been designed or documented, vague manual scripts, where the test cases are documented but not all the details have been specified, and detailed manual scripts, where every input and comparison is noted. Your own test processes should fit, more or less, into one or more of these categories. 2.2.1 Ad hoc testing: unscripted
Ad hoc or unscripted testing implies simply sitting down at the computer and trying things. The tester may or may not have a mental plan or checklist of things to test, let alone any specific values to try. He or she thinks up what to test, trying this and that, and thinking 'I wonder what will happen if I do this.' The tester's ideas and actions are probably not logged or documented, so what is done cannot be accurately repeated. This is usually the case when a software development project is running late and little or no thought has been given to testing. Typically there are no specifications, the requirements are still changing, and the manager is saying 'there is no time to document, just test.' This is not a good place to be, but if that is where you are now, you have no choice about it. You have our sympathy, but don't try to automate this kind of testing - it will only slow you down even more. The way in which automation of ad hoc testing often proceeds is described in this section, and illustrated in Figure 2.3. The steps of unscripted testing, illustrated in Figure 2.3, are: 1. 2. 3. 4.
think what to do, what to test; think up specific inputs; enter the inputs that have just been thought up; check that the software worked correctly, by watching the responses that appear on the screen.
It is hard to think of many advantages for unscripted testing. The one aspect that is most often mentioned is that it should save time, since we do not need to spend any time in planning and test design activities, we can just start testing. This is analogous to the 'why isn't Johnny coding yet?' syndrome that characterizes unsophisticated software development. This approach always costs more in the long term (both in writing software and in testing it) as more mistakes will be made and they will cost more to correct when they are found. The disadvantages of unscripted ad hoc testing include: » » « »
important areas that should be tested may be overlooked; other areas may be tested more than is necessary; tests are not repeatable, so fixes cannot be confirmed with certainty (in some cases defects may not be reproducible); it is usually both ineffective and inefficient.
Automating ad hoc testing relies on the automator deciding what is to be tested. This means that the tester must have the necessary skills to automate tests or the automator must have the necessary skills to define good test cases. Either way, it relies on individuals designing and implementing tests without any independent assessment of the quality of the tests.
2.2,2 Vague manual scripts Vague manual scripts contain descriptions of the test cases without going into the detail of specific inputs and comparisons. For example, a vague manual script might say 'try some invalid inputs' or 'add some items to
the list.' The test conditions may be implied (some invalid inputs), rather than stated explicitly (for example invalid inputs that are too large, too small, or the wrong format). Our description of the example test case is also an example of a vague manual script: • 9 • » •
This type of manual script usually includes a vague description of the expected results and a place to tick to indicate when a test has passed (to be filled in each time the test case is run). Therefore, the test script for our test case may look something like that shown in Table 2.2. Table 2.2 Example of a vague manual test script based on our test case for Scribble. Step
Expected result
Run up Scribble
File menu displayed
Open file with sorted list
contents displayed
File Items
Add some items to List
added in order
Item moved,
Move an item
List now unsorted
added at end of List
Delete item from List
Use invalid position number delete an item Save changes in new file
Item Item
Error message displayed End of test
The steps of manual testing from a vague script, illustrated in Figure 2.4, are: 1. 2. 3. 4.
read what to do; think up specific inputs; enter the inputs that have just been thought up; check that the software worked correctly, by watching the responses that appear on the screen.
Vague manual scripts have many advantages over unscripted ad hoc testing: different testers have a reasonable 6hance of finding similar defects following the same script; • the conditions identified will all be tested if the script is followed; • the script documents what is to be tested; • the test cases can be reviewed or inspected; • the testing performed is likely to be more effective and more efficient than ad hoc testing (depending on how well the test design process is carried out).
However, vague manual scripts also have a number of disadvantages: • • •
the test input is not precisely defined; different testers will perform slightly different tests using the same script; it may not be possible to reproduce problems reliably.
When a test is run from a vague script, the tester still has to decide exactly what input to use in order to test the identified conditions. For example, in our example test case there are many different ways to have an invalid input: a number could be out of range, either above or below, it could be alpha instead of numeric, it could be a negative number or a space. Automating vague manual test scripts relies on the automator deciding what specific inputs to use and possibly being able to decide whether or not the actual results are correct. This means that the automator does not have to invent the test conditions but must have an adequate understanding of
the application and the business to insure that the implementation of the test cases does not denigrate their quality. 2.2.3 Detailed manual scripts
A detailed manual script contains exactly what will be input to the software under test and exactly what is expected as a test outcome for that input. All the tester has to do is what the script says. This is the level that is the closest to what the test tool does, so automation is easiest in many ways from this level. However, this is also the most tedious and boring for human testers; they have no scope for creativity. Using a vague manual script, at least they can choose what inputs to use for each test. If the vague script said 'enter some invalid input' or, slightly less vague, 'enter an invalid position number' or 'enter a position number too large,' the detailed manual script would say 'enter invalid position number 7.' Here, 7 is invalid based on the context of the test. Our detailed manual script might look like Table 2.3. Table 2.3 Example of a detailed manual test script based on our test case for Scribble. Step Input
Click on Scribble icon Move mouse to File menu, click Move mouse to Open option, click Move mouse to countries. dcm, click
Enter 'Sweden' Enter 'T
Expected result Pass Scribble opened, File menu enabled Options available: Open, New, Exit Filenames displayed, including countries. dcm, filename prompt displayed Text plus List of three countries: Belgium, Netherlands, UK, File and List menus displayed Item added as number 3 in List Position not valid message displayed
Detailed scripts come in many 'flavours.' The example shown in Table 2.3 is typical of a very thorough manual script that can be performed by staff with relatively little knowledge of the application or its business use. The script's expected results are shown here as exact (as the most detailed form of detailed script). In this case, if the software is relatively stable, the test script could actually show the screen shots as expected results. The detailed script would then look like Figure 2.2. A slightly less detailed format for the expected results might say 'error message displayed' instead of giving the exact text of the expected error message, for example. The steps of manual testing with a detailed script, illustrated in Figure 2.5, are: 1. read exactly what to do; 2. enter the exact inputs in the script; 3. check that the software worked correctly, by watching the response that appears on the screen. The advantages of detailed manual scripts are: » testers will run exactly the same tests (i.e. as exact as manual regression testing can be) from the same scripts (subject to human error, of course - which is not insignificant when people are bored); » software failures revealed by the tests are much more likely to be reproducible;
anyone can run the test, since the instructions are full and detailed;
» it is easier to automate since all the information about inputs and expected outcomes is given in the script.
The disadvantages of detailed manual scripts are: • • • • •
they are expensive to create (requiring a lot of effort); there is often a lot of redundant text (e.g. the word 'Enter' appears many times) though strictly there need not be so; scripts tend not to lend themselves to reuse of common actions; they are verbose, making it hard to find information and hard to maintain; they are very boring to run, since the tester has no scope to think or be creative, therefore mistakes are more likely.
Because a detailed test script contains detailed information about how to perform each test case, the tester does not need any knowledge of the application. Test tools have no knowledge of the applications they test; in fact test tools have no intelligence at all. They are, however, superb workhorses. They never complain, never become bored or distracted, and never want a holiday or sick leave, but will work all day and all night throughout the year. Unfortunately, they do need to be told in painstaking detail everything that they are required to do.
A detailed script is, therefore, in theory a good starting point for automation because all of the details are specified. However, detailed manual scripts are not usually written in a form that any test tool can understand. There is then an overhead associated in translating the manual scripts into automated scripts that a test tool can process. The information is therefore documented twice, once in the manual scripts and again in the automated scripts. Although unavoidable when automating existing detailed tests, this is a duplication that would be wasteful if new tests were documented in the same way.
For efficiency, a new form of test documentation is required, one that can be read and understood by humans and used directly by a test tool. Automating detailed manual test scripts frees the automator from responsibility for the quality of test case design, allowing him or her to focus on how best to automate the tests. The automator does not have to understand the application, the business or the test cases because all the information is documented.
Automating test execution: inputs
It is natural to assume that automating test execution must involve the use of a test execution tool, but in fact this is not the only way to achieve at least some test execution automation. For example, batch programs and other programs that do not involve user interaction are perhaps the easiest to automate. A simple command file can be used to set up data, invoke the program, and compare the outcomes. Although it will lack most of the additional facilities offered by modern testing tools it will automate the essential chores. Other options may be applicable to those for whom a commercial tool does not exist, is not suitable, or is not available; for example, post-execution comparison, described in Chapter 4, pre- and postprocessing, described in Chapter 6, or changing the application so it can run in 'test mode.' 2.3.1 Automating test input
In the rest of this section, we will assume that a commercial test execution tool will be used to automate testing, since this is what most people will do. We turn on the record or capture facility of our test tool while we perform all of the actions for the manual test case shown in Table 2.1. The tool will record all of the actions made by the tester and will write them to a script in a form that the tool can read. Our recorded script will contain the test inputs (including text and mouse movements). The tool can then repeat the tester's actions by reading the script and carrying out the instructions in it. The script will be held in a file that can be accessed and edited. Scripts can also be created manually, but because they are generally written in a formal language that the tool can understand, writing (or editing) scripts is best done by people with programming knowledge. This makes a test tool's capture facilities appear very attractive indeed since the script generated during the recording of a test case performed manually is the same script needed by the tool to perform exactly the same test case.
2.3.2 Replaying the recorded script
Let us assume that we have recorded our example test case being performed manually and now wish to replay it. Figure 2.6 depicts what will happen. The test script (that we have named countries.scp) is read by the tool, which then invokes Scribble and drives it as though it were a real person at the computer keyboard. The actions the test tool takes and the information it effectively types into Scribble are exactly as described in the test script. During execution of the test case, Scribble is caused to read the initial document countries.dcm, output information to the computer screen, and finally output the edited document as a file called countries2.dcm. The test tool creates a log file countries.log containing information about what happened as the test case was run. Logs usually include details such as the time it was run, who ran it, the results of any comparisons performed, and any messages that the test tool was required to output by instructions within the scripts. 2.3.3 Automated scripts are not Like manual scripts
Exactly how the script looks will depend on the test tool being used and the implementation of the application. Table 2.4 gives an idea of what a recorded script may look like for our Scribble test. What is listed here is a pseudo-code version of the minimum information that a tool would produce, but this should give you an idea of the complexity of a script for a rather simple test. The scripting languages for the commercial tools do basically the same thing, but often in different ways. To give you an idea of what some scripting languages look like, Figure 2.7 shows a portion of the Scribble test in a commercial scripting language. Actually, this may not be exactly correct, as
Table 2.4 Pseudo-code recorded script for the Scribble test.
LeftMouseClick 'Scribble' FocusOn 'Scribble' SelectOption 'File/Open' FocusOn 'Open' Type 'countries' LeftMouseClick 'Open' FocusOn 'Scribble' SelectOption 'List/Add Item' FocusOn 'Add Item1 Type 'Sweden' LeftMouseClick 'OK' FocusOn 'Scribble' SelectOption 'List/Add Item'
FocusOn 'Add Item' Type 'USA' LeftMouseClick 'OK1 FocusOn 'Scribble' SelectOption 'List/Move Item'
FocusOn
'Move
Item'
Type ' 4 ' Type Type '!' LeftMouseClick 'OK' FocusOn 'Scribble'
SelectOption 'List/Add Item' FocusOn 'Add Item' Type 'Norway' LeftMouseClick 'OK1 FocusOn 'Scribble' SelectOption 'List/Delete Item' FocusOn 'Delete Item' Type '2' LeftMouseClick 'OK' FocusOn 'Scribble' SelectOption 'List/Delete Item1 FocusOn 'Delete Item1 Type '7' LeftMouseClick 'OK1 FocusOn 'Delete Error' LeftMouseClick 'OK' FocusOn 'Scribble' ' SelectOption 'File/Close1 FocusOn 'Close' LeftMouseClick 'Yes' FocusOn 'Save As' Type 'countries2' LeftMouseClick 'Save' FocusOn 'Scribble' SelectOption 'File/Exit'
the example has been constructed rather than recorded. Also, the tools may have changed their scripting languages since this book was written. However, it does give an idea of what a script might actually look like. Some scripts may look quite different, but regardless of what our script language looks like, each is automating only one thing: the actions performed. Depending on the format of the recorded test, there may also be a great deal of redundant information contained in the captured script, such as the pauses between entering data (while reading the manual script, for example), and any typing mistakes that were corrected (backspacing over incorrect characters before typing the correct ones). In order to make a recorded script usable, or indeed even recognizable, comments should be inserted in the script. Despite some vendor claims, no recorded scripts 'document themselves.'1 We expand on these matters in Chapter 3. 1
We feel that the comments produced in 'self-documenting' scripts are about as useful as an ashtray on a motorbike.
All scripting languages allow you to insert comments into the scripts. However, just as when commenting code, you must conform to the syntax or the test tool will try to use your comment as a test input (just like a compiler will try to compile your comment in source code if it does not conform to comment syntax). 2.3.4 Benefits and uses of automating only test input
A raw recorded script (of what a tester did) does have its place within a test automation regime, but it is a much more minor place than most novices to test automation give it. One advantage of recording manual tests is that you end up with a form of replayable test comparatively quickly. Little or no planning is required and the tool can be seen to provide benefit more or less right away (well, at least in theory). However, recording ad hoc testing is a bit like writing software without a specification. You may end up with something similar to what is actually required but is unlikely to be any better than unspecified software. The end product will probably do some things correctly, some things incorrectly, not do some things, and do others that are not required. One benefit of capturing and recording test inputs is that this can automatically provide documentation of what tests were executed. This provides an audit trail, which is useful if you need to know exactly what was done. This audit trail does not necessarily make a good basis for an effective and
efficient automated testing regime, but it has its place as a way of getting started and for special tasks. For example, if you have invited users in for 'playtime' and they manage to crash the system, you can at least see what was typed in. The audit trail may also contain a lot of useful information that is not normally available from manual tests, for example detailed statistics on timing or performance. The set-up of test data is often a long and tedious task and for this reason is sometimes avoided, resulting in fewer runs of a set of test cases than there should be. If the data set-up can be recorded the first time it is performed then, providing the software's user interface does not change, the set-up can be replayed much more reliably and usually a lot faster by the tool. For example, adding the details of one new client isn't too bad, but adding the details of 100 new clients is best automated. Even if the next version of software has user interface changes that invalidate the recording, it may still be worth doing, since the additional effort to record the data setup the first time will soon be repaid by the effort saved with the first or second replay. This is only true if the recording does not need editing; where editing is necessary the costs are much greater. There are some other uses of recording manual tests, or at least recording of user interaction, such as making the same maintenance change across large numbers of data files or database(s). A recording can also serve as a demonstration. For multi-platform applications a script may be able to be recorded on one platform and played back on a number of other platforms with no or only minor changes. If complicated sequences need to be typed accurately, and this is error-prone if done manually, replaying them as one step in a manual test can save time. Automated execution is much more accurate than manual execution, and therefore the test input is repeatablc. Exact reproduction of inputs is particularly useful in reproducing bugs. If the cause of the bug has been recorded, playing it back should reproduce it, and playing it back after it has been fixed should confirm that it was fixed correctly (or not). However, in most circumstances, automating only test execution has little benefit. Manual verification is error prone, wasteful, and very tedious. Yet some people end up with a test execution tool which produces stacks of paper that has to be checked by hand - this is nonsense if we are talking about automating testing. In order to claim any real test automation, we should therefore also automate comparison of the test outcomes. It is important to appreciate that we are not suggesting that test result comparison for all test cases should be automated. As we have already discussed in Chapter 1, not all test cases should be automated, and not all comparisons should be automated either. 2.3.5 Disadvantages of recording manual tests The disadvantages of record and playback only become apparent as you begin to use the tool over time. Capture replay always looks very impressive when first demonstrated, but is not a good basis for a productive long-term test automation regime.
The script, as recorded, may not be very readable to someone picking it up afterwards. The only value of an automated test is in its reuse. A raw recorded script explains nothing about what is being tested or what the purpose of the test is. Such commentary has to be inserted by the tester, either as the recording is made (not all tools allow this) or by editing the script after recording has finished. Without this information any maintenance task is likely to be difficult at best. A raw recorded script is also tied very tightly to the specifics of what was recorded. Depending on the tool, it may be bound to objects on the screen, specific character strings, or even screen bitmap positions. If the software changes - correction: when the software changes - the original script will no longer work correctly if anything to which it is tightly bound has changed. Often the effort involved in updating the script itself is much greater than re-recording the script while running the test manually again. This usually does not give any test automation benefit. For example, the values of the inputs recorded are the exact and detailed values as entered, but these are now 'hard-coded' into the script. The recording is simply of actions and test inputs. But usually the reason for running a test is to look at the test outcome to see whether the application does the right thing. Simply recording test inputs does not include any verification of the results. Verification must be added in to any recorded script in order to make it a test. Depending on the tool, it may be possible to do this additional work during recording (but it takes additional time and effort) or during the first replay, otherwise it will be necessary to edit the recorded script. This is described in more detail in Section 2.4. 2.3.6 Recommendation: don't automate testing by simply recording
It should be the aim of every professional testing organization to implement an efficient and effective test automation regime appropriate for their objectives. Simply recording manual tests will not achieve this for the following reasons: •
Unscripted (ad hoc) testing is not usually very effective (it can be effec tive in some cases if you have a person who either knows the system well and has experienced the weaknesses of previous versions, or has a good understanding of how the software works and is able to identify likely defective areas). Automating ad hoc testing will at best result in faster, but nonetheless not very effective, testing. Recording only input does not result in an automated test. The out comes of a test have to be checked to insure they are as expected; if this is not automated, this is not an automated test, only automated input. Re-recording when the software changed is inefficient. Almost any change to the user interface of software will result in changes to the test inputs or their order or both. Editing recorded scripts is neither easy nor pleasant. It is often easier and quicker to simply re-record the test but this usually incurs an unacceptably high cost anyway.
We recommend that if you currently perform only ad hoc manual testing, you will achieve far more benefit from improving your testing process than from attempting to automate it. The use of testing techniques, for example, may well double your test effectiveness. (See the threefold improvement in Chapter 12.) This will save you much more money than trying to run ineffective tests faster and will lead to better quality software. 2.3.7 Automated execution, with manual verification?
As it stands we have a script that was generated by recording our example test case being performed manually, and this can now be replayed by our test tool as often as we wish. However, all we have automated are the test inputs. In order to determine if the test case produced the correct results, we still have to check the expected outcomes manually. The tool will not do any checking for us yet because we have not instructed it to do so; so far, it knows only how to enter one set of test inputs, the inputs of our one test case. There is a certain novelty value in having a tool type the inputs in for you, especially at first. There is a tendency for 'coffee parties' to gather around the screen. Remarks such as 'I wish I could type that fast' may be overheard. However, the novelty will soon wear off when the testers realize that they still have to sit there watching the test in order to verify that it worked (or not). The idea of overnight and weekend testing will not be popular with testers if automation has only reached this stage as yet. Manually checking that our test case has worked correctly could involve having to watch the screen as the tool replays the script. It would also be a good idea to take a look at the edited document (countries2.dcm) after test execution to insure that the data was saved as it had appeared on the screen. (See the Experience Report in Section 2.5.2.) So do we have automated testing? Well, we have some automation: the inputting has been automated. However, we still have very much a manual process in checking that the software did the right thing.
2,4 Automating test result comparison It is unlikely that the entire outcome of a test case will be compared (including not only what has changed but also everything that has not changed), since it is often impractical and unnecessary. Usually, only the most important or most significant aspects need to be compared. Some outcomes such as the outputs to the screen can be performed while the test is being executed, this is known as dynamic comparison. Other outcomes such as some outputs to a file or database can only be compared after the test case execution has completed, this is known as post-execution comparison. An automated test may need to use a combination of dynamic and post-execution comparisons. This topic is discussed in more detail in Chapter 4.
There are a number of design decisions that need to be taken when deciding how to implement automated comparison. We will illustrate with an example. 2.4.1 Deciding when to compare the outcome of a test case
The first design decision is to decide when in a test run a comparison should be done. As an example, take a single input from our Scribble test, to add an item (Sweden) into a sorted List. Let us assume that we are recording the manual test once again but this time we will insert a few dynamic comparison instructions as we go. We arrived at the point in the test case where we are going to add the country 'Sweden' to the list. Figure 2.8 shows the screen as it might appear at this stage, before and after entering 'Sweden'. At this point, we should check the screen as it now appears (Screen 7) whenever this test is run in the future, so we need to add a comparison to the test script now. The first step is to manually verify that this screen is indeed correct for the input of 'Sweden'. Next we will want to capture what is on the screen to compare against the next time this test is run. This will insure that the application performs in the same way at this stage of the test case each time it is run. The next step is to decide how much to compare. 2.4.2 How much should be compared? We now have some options for what to capture as the future expected output: • • •
the whole screen; the absolute minimum; something between these two extremes.
Figure 2.8 Screen images at the point when the list item 'Sweden' is added.
Capturing the whole screen is often the easiest to do. However, if there is any information on the screen which is likely to have changed the next time the test is run, then the easiest choice now will cause us significant grief later. Sometimes a screen will be displaying the current date or time. The next time the test case is run, we certainly do not want the test to fail because the test was not run on exactly the same date or at the same time it was recorded. In our example, we may have changed the text outside the List, but that is not important for this test, which is concerned only with whether an item can be added in the correct order to the List. Capturing whole screens can be quite greedy of disk space for tests. Particularly when graphics are involved, the space needed to store a whole screen can run into tens of megabytes. What about other options? We could perhaps capture only a single character, say the letter 'S.' Or we could capture the line containing the new entry, which would make sure that all of the new entry had gone in correctly. In Figure 2.9, we show this option as the shaded area. Our first try at capturing an expected outcome seems sensible: it is a fairly minimal set. However, there is one error that may occur which this option will not find. Suppose the next version of the software ends up overwriting the third entry instead of moving UK down and inserting Sweden as the new third entry. The screen would then appear as shown in Figure 2.10. The tool will pass this test, since all it is checking for is the line containing Sweden, and that looks exactly as it was told to expect it to look. So by making our comparison more robust (from things we are not interested in), it has become less sensitive to unexpected errors. (These terms are explained more fully in Chapter 4.)
A better option may be to compare not only the newly inserted entry, but also the entry that was 'pushed down.' This will catch the error shown (but may well miss still others). Our improved test comparison area is shown in Figure 2.11. We have looked at the choice between comparing a little versus comparing a lot at a time. There are a number of other choices for comparison, which are discussed in more detail in Chapter 4.
2.4.3 Dynamic comparison
Let us now assume that we have included some dynamic comparison instructions as we recorded our example test case being performed manually, including the comparison for Sweden outlined above. Figure 2.12 depicts what will happen. The test script now contains additional instructions that tell the tool which outputs are to be compared and the expected result to which they arc to be compared. At each comparison point, the tool will capture the actual output from the software as it executes the tests and it will then compare that with the corresponding expected output. Every time a comparison is performed a message is written to the log file indicating whether or not differences were found. The test script may now look something like the example shown in Figure 2.13. Note that even if a comparison reveals differences, the tool will continue to run the test case. This is both sensible and useful since not all differences imply catastrophic failure so it usually is worth running a test case right to the end to sec if any other problems can be revealed. However, this characteristic is something of a double-edged sword. If a detected difference really docs imply catastrophic failure, the tool will continue to run the test case anyway, unaware of the potential havoc doing so may cause. It may be that for a more complex system than our example word processor, test cases that do not go according to plan are best aborted to prevent undesirable outcomes such as data being incorrectly changed or deleted, large volumes of data being created or printed, or just hours of machine time being wasted. Fortunately, where such potential damage could occur, it is usually possible to instruct the test tool to abort the test case. It will be necessary to edit the script though, inserting appropriate instructions to detect an undesirable situation (or perhaps more easily, not a specific desired situation)
; Select "&List~&Add Item" from the Menu MenuSelect "&List~&Add Item" Pause 3 seconds ; Use the dialog window Attach "Add Item ChildWindow-1 " Type " SWE {Backspace } { Backspace } " Pause 2 seconds Type "weden" Button "OK" SingleClick ; Use -the parent window Attach "Scribble MainWindow" ; SCRIBBLE. CB",
Text check on "ADD_1" )
Scribble Check ("
; Use the parent window Attach "Scribble MainWindow" ; Select "&List~&Add Item" from the Menu MenuSelect "&List-&Add Item" Pause 2 seconds ; Use the dialog window Attach "Add Item ChildWindow-1" Type "USA" Pause 1 seconds Button "OK" SingleClick
Fi( |ure 2.13
Script segment from a sample commercial testing tool showing a dynamic mparison instruction in bold. This instructs the test tool to perform a comparison ac cording to instructions stored in the file SCRIBBLE. CB under the label ADD_1. These in structions would have been previously set up in the tool's dynamic comparison database. CO
and then the action to take. This is 'programming' the script, and brings with it not only endless possibilities of tailoring test cases to detect all sorts of situations and deal with them accordingly, but also unconsciously to make errors that will cause the test case to fail through no fault of the software under test. This can lead to much wasted effort, instead of the intended saved effort. 2.4.4 Post-execution comparison
In the previous subsection we looked at how the use of dynamic comparison affects our example test case. Here we will look at the effect post-execution comparison would have on it as an alternative to dynamic comparison. A comparator tool for post-execution comparison is sometimes supplied bundled with a capture/replay tool and in any case most computer systems offer some utility program or other that can perform simple independent comparisons.
Figure 2.14 depicts what happens with our example test case when we use post-execution comparison. The test script is back to its simplest form: a straight recording of the inputs. The log file contains just the basic information including start and end times, who ran it, etc. but no information about the results of comparisons (though this will depend on the implementation). The expected outcomes are now held in a separate file called countries2.dcm, the same name as the output file with which it has to be compared, but in a different directory, rather than being embedded in the script. We could have used a naming convention such as Expcountries2.dcm to distinguish our expected results file from the actual results file. Using the same name is what we recommend, for reasons outlined in Chapter 5. After the test case has been executed the comparison process can begin. This will take the actual outcome of the test case and compare it with the expected outcome, possibly generating another log file (not shown in the figure) and/or a report of the differences found. Here we have shown the edited output file (countries2.dcm) as the only outcome being compared. Whether or not this is sufficient depends on the purpose of the test case. This may be all that we consider necessary to compare, as it insures that the edits to the input file are reflected correctly in the new version of the file. While this may be a reasonable approach for positive testing, i.e. testing valid inputs such as adding Sweden correctly, it would not be appropriate for testing invalid inputs such as trying to enter an invalid position number. Showing that the screen display is updated correctly is more difficult to do in post-execution comparison, but it is not impossible. For these kinds of test, other outcomes would need to be captured in another file or files for later comparison.
Note that the diagram in Figure 2.14 implies two separate processes; the first executes the test case while the second process performs a comparison. It is this aspect that makes post-execution comparison a more difficult facility to automate well (Chapter 4 shows how to overcome these problems). Commercial testing tools usually provide much better support for dynamic comparison than they do for post-execution comparison. 2.4.5 Automated comparison messages have to be manually checked So far we have described the automation of our example test case starting with a simple recording and then adding dynamic comparison and post-execution comparison to verify the actual outcome. Now, in order to determine whether or not our test case is successful every time it is run, there are some additional tasks we may have to do, depending on the tool and the implementation of post-execution comparison when used. First we should look at the log file to make sure that the test case was executed right through to the end. It is quite possible for automated test cases to fail to start or be aborted part way through (for example, due to insufficient disk space). Where dynamic comparison has been used we may also need to check the log file for any 'failed' comparison messages. Where we have used post-execution comparison, we may have to look at one or more other files for information about any differences between the actual and expected outcomes. Clearly, this is a manually intensive task. Having to repeat it for only a few test cases will not be too arduous, but it will be impractical where there are tens, hundreds, or thousands of test cases. Of course, it may be a relatively simple matter to write a small utility program to search through all the log files, doing a text match on the word 'fail,' wouldn't it? That utility program would need to know the names of all the log files, and where to find them. It may also give some spurious results, such as a test that writes text to the log file containing the word 'fail,' e.g. 'This is test 325B.43 Communication Link Failure Test.' This additional utility should be produced if we want testing to be automated, but this does represent an additional task that is normally not anticipated. At the time of writing, some commercial test tools do provide an acceptable summary of the information, or at least can be made to do so. However, where post-execution comparison has not been integrated well with the execution of the test cases, obtaining a report that takes into account the results of post-execution comparisons can be far more difficult. When we invoke a set of automated test cases we would really like to be presented with a single report at the end that takes into account all of the comparisons and simply states how many test cases ran successfully, how many failed, and then which test cases failed. (Our recommendations for the content of such a report are discussed in Chapter 9.)
2.4.6 Automating test comparison is non-trivial
2.4.6.1 There are many choices to be made
There are a number of aspects to automating comparison that must be designed into the automated testing regime. Whether and when to do dynamic comparison and post-execution comparison is one example. It is not a case of one alternative being better than another; each alternative has advantages and disadvantages, and each will be more suitable in some circumstances than in others. Usually a combination of the two should be used to give the best results. Other choices include comparing a lot of information at once versus comparing only a little piece of information each time, and performing many comparisons versus performing only a few. (These and other issues are discussed further in Chapter 4.) Many of the choices come down to trading off the resilience of the tests to changes in the software, with the ease of finding defects when the tests find a discrepancy. 2.4.6.2 Scripts can soon become very complex
Incorporating comparison into test cases is essential in order to be able to fully automate testing. If dynamic comparison is embedded in the script, as we have seen in the example, this can make the script more complex, since the comparison instructions and possibly the expected output will now be contained within the script. The more information the script contains, the more susceptible it will be to changes, cither changes in the software being tested, or changes in the test cases themselves. For example, if the error messages changed their wording slightly, all expected outputs embedded in scripts would need to be edited. This can increase the cost of maintaining the scripts considerably. Ways to reduce such script maintenance costs are addressed in Chapter 3.
2.4.6.3 There is a lot of work involved Tool support is essential, not only to automate testing, but also to help automate the automation! In order to produce an effective and efficient automated testing regime, effort needs to be invested upfront, so that effort is continually saved later on. The speed and accuracy of use of the testing tools is important. The effort involved in setting up this regime will be paid back many times on all of the numerous occasions when the automated tests arc re-run. The more reuse of automated tests you need, the more important it is to build them correctly.
2.5 The next steps in evolving test automation Surely having put all this effort into automating test execution and comparison, we must be ready to tell the test tool to run our test cases so we can then put our feet up, right? Unfortunately, we have only just begun. What happens next? Typically, what is shown in Figure 2.15.
2.5.1 Why tests fail the second time (environmental trip-ups)
The first time our test ran, it used as its input the file countries.dcm. It created the file countries2.dcm as the edited document file. This is no problem when running the test for the first time, either manually or automatically. The final steps of our test script are shown in Figure 2.16.
Figure 2.16 The end of our original test.
Screen 27 File menu: Exit. Figure 2.16 Continued
What happens the second time we run this exact test? Screen 25 will actually be different, because both countries.dcm and countrics2.dcm will be shown in the file list. The tool, however, will not 'notice' this! The next input is to type in countrics2. The next screen that appears is now not the one shown on Screen 26, but a new one containing a dialog box that was not seen the first time the test was run. This is shown in Figure 2.17. If this happens when you arc testing manually, you would naturally put in the additional step of answering 'Yes' (and you would also probably have noticed the file in the list on Screen 25), and then select Exit from the File menu. You may not even realize that you had put an extra step into the test.
However, when the tool comes to replay the exact input, after sending countries2, the next thing it sends is an attempt to select the File menu. Since this is not a valid input to this screen, Scribble will beep and redisplay the same screen. The automated test then tries to select the Exit option, causing Scribble to beep again and redisplay the same screen. The tool now thinks it is finished and exited from Scribble, so it may go on to start the next test case in the sequence. You can see how the automated testing will soon reach a state in which it will achieve nothing useful and might actually do some damage by deleting or changing data files that it should not. The test tool is essentially 'blind' to what is really happening. All it can know about is what it has been told. Anything you want the automated test to know about, you have to tell it explicitly. Again, the problem outlined here is but one of many possible ways in which a test can be tripped up. As with all such things, the problem is not insurmountable, but it takes time and effort to surmount it. There are a number of alternative ways to overcome this problem. Here are three: •
Alter the script to respond to the extra prompt. The test case will now run the second and subsequent times, but will fail the first time, or if countries2.dcm has been deleted for any reason. Alter the script to check for the extra prompt and respond whenever it occurs. This enables us to have a script which will run regardless of whether countries2.dcm exists or not. Our script will contain an addi tional 'if statement along the lines of: 'if countries2.dcm exists, hit "Y".' Note that this will make our script more complex again. Alter the script to check for the file, and delete it if it exists before run ning the test case. Rather than 'hard-coding' the check for the existence of this file into the script at the point where the problem occurs, another possibility is to anticipate the problem at the beginning of the script. This may be better from a maintenance point of view, since something buried at the end of the script is more easily overlooked. In this case, we could put the check for the existence of the file at the beginning of the test script, and delete the file if it exists, so that the rest of the script will now run correctly. Now we don't have to check for the extra screen because we know it will not come up. Our script may now contain something like: 'if countries2.dcm exists, delete file coun-tries2.dcm.'
This example is typical of a number of things that can occur to trip up a test. It may be more efficient to collect all such similar things for a set of test cases into one place, where all the environment factors can be dealt with either for one test case or for a set of tests. This could be done as a separate script in the testing tool language, or it could be done as a completely separate exercise, possibly implemented in a command file or whatever is most familiar to the software engineers or testers. This is called pre-processing and is discussed in Chapter 6.
Which solution is best? This is another area where there are no answers, but choices to be made. The chosen solution will be a trade-off of many factors, including: • • » « • » »
implementation effort; future maintainability; test case failure analysis effort; debugging effort; this test case's ability to handle similar situations; robustness; what is done for other automated test cases.
2.5.2 Other verification requirements (often overlooked) Having taken the environment considerations into account, our test is now finished, right? Well, what we now have is certainly a long way forward from our first attempt of simply capturing inputs. The next question to ask is: is it a good test case? Actually, this is the very first question we should have asked before we started automating it. As we discussed in Chapter 1, there is no point in automating poor test cases. However, the point we wish to make now concerns the comparisons we have implemented. Have we checked everything that we should? Will they reveal all the defects that could be found by this test case? Often there are many facets to the outcome of a test case that we could check, which go beyond what we could illustrate with our simple Scribble example. Testers performing test cases manually will be making a multitude of checks, some consciously and probably many unconsciously. Automated tests will only check what they are programmed to check so it is important that we consider exactly what is programmed in and what can be left out. Some of the outcomes we could consider for a lot of systems include: » files that may have been created or changed (Were the correct files created? Were the correct files changed? Were they changed in the right way?); • databases that may have been altered (Were the correct records altered? Were any alterations made to other records which should not have been touched?); » other outputs, such as to printers, networks, or to other communication equipment (Were the right things sent to the right places? How can you be sure?); « screen attributes may have been changed, possibly ones that are not visible such as whether a field is protected or not (Have the correct attributes been changed to the right new values?);
• internal data structures may have been created or altered, perhaps stored briefly before they are used by another program (Has the right information been put into that temporary storage? How can you check it?).
Reports of a potentially serious bug, which corrupts database records in the Microsoft, Access application, have caused concern among its millions of users, writes Tom Forenski. The bug is activated when editing database records and causes the edits to be posted to a record other than the one being viewed. The bug can be created simply by running one of Microsoft's own ivi/ardi. The hug is particularly devious in that everything appears to work correctly', reports Allen Browne. 'It is only when a record is checked later that the results become apparent. In addition, it only occurs when the form contains more than 262 records, so that the database works correctly initially, and the bug only surfaces as more data is added.' The steps needed to reproduce the bug are-delete a record on a form without closing ihe form, search tor a different record using the bookmark properties of the form and recordset clone objects using the combo box wizard option 'Find a record on my form based on the value I selected in my combo box' make data changes in the found record The changes are then saved to a different database record than the intended one. Microsoft has posted information on a workaround, and a fix would be released in the next service pack tot Access, said a Microsoft representative. Source: Computrr Weekly September 10 1998
2.5.3 Ways of verifying file or database changes
How can we verify that these additional items have been correctly handled by the software? There are some choices for how we handle this. One option is to add more verification to the script. We could check data values stored in a file or database by doing an additional read after we have modified something, to see whether the right information has been stored. This would be checked against the way we would expect to see that data displayed. This does make the script more complex (again), and also more vulnerable to changes. If the layout of the display from the database were changed, all scripts that used this method would need to be updated, increasing the test maintenance burden.
Another possibility would be to use a comparison tool to search for differences between the correct version of the file and the actual file. This means that we would need to save a copy of the file as it should appear, in order to do the comparison. If this were a database, this may not be feasible. As with many aspects of test automation, there are choices to be made, and the choice will affect many things. An effective test automation regime will have a good balance of checking things in a way that will be resistant if not immune to changes. 2.5.4 Where will all the files go?
There is one last thing to consider in implementing our example automated test case. In the process of creating the automated test case for Scribble, we have created several files. For example: » » » »
countries.scp, our test script; countrics2.dcm, our expected output for post-execution comparison; countries2.dcm, our actual output; countries.dif, the list of differences produced by the comparator (if not in log); « countries.log, the audit trail of what happened when the test ran.
All of these files must be given a home. Where should we put them? This is yet another decision to be made, and the results of that decision will affect the future maintainability of the tests. These issues are discussed in Chapter 5.
2,6 Conclusion: automated is not automatic When you start implementing automated tests, you will find that you are running the (supposedly automated) tests manually. Automating some part of test execution docs not immediately give automatic testing; it is but the first step along a long road. There arc many different approaches to automating testing, and generally speaking, the more elaborate the approach, the greater the end productivity (quicker to add new automated tests, less maintenance involved, etc.). Conversely, the simpler the approach, the less the end productivity. However, simple approaches have the advantage of comparatively low start-up costs and some benefits can be achieved fairly quickly, while elaborate approaches incur much larger start-up costs and the benefits are usually a much longer time coming. It is important to choose an approach (or approaches) appropriate for the objectives of test automation. For example, if the tests are short term (perhaps because the software is to be used once and then thrown away) there is no point in using an approach that is designed to minimize long-term maintenance costs at the expense of upfront effort.
There is more to a test than just running it. Often there is some set-up and clear-up involved. This additional work also needs automating. Unfortunately, the easiest solution is often not the best solution. A standard approach is required in order to get the best balance between many alternative ways of solving the problems. There is usually more verification to be done than first meets the eye. Automation can lead to better testing, if a comparator is used to compare things that might otherwise be overlooked if testing was done manually. However, this is by no means guaranteed. The 'testware' must be designed to be maintainable and of high quality in order to achieve effective and efficient test automation, just as software must be designed to be maintainable and of high quality for effective and efficient use. This testware design process involves balancing many decisions concerning comparison, scripting, where files are stored, etc. The commercial test execution tools are generic; one size fits all. However, each individual user is unique, and some parts of the generic solution may fit well, some not so well, and some may be downright damaging. In order to build an automated testing regime, you must tailor the generic tools to suit your own situation. The key characteristics of a good automated regime are: • it is very easy to select sets of tests to be run (the proverbial 'touch of a . button'); • those tests take care of all their own housekeeping such as environmen tal set-up and clear-down, i.e. the tests are self-sufficient; • it is easier to add a new test to the automated pack than to run that test manually. This can only be achieved through continuous improvement of the entire regime.
Summary We have taken a very simple example test case for Scribble, our primitive word processor. We looked at the different alternative starting points for automating this test, in terms of the current type of test documentation: ad hoc or unscripted, a vague manual test script, or a detailed manual test script. Testing can be automated from any of these starting points, but is easiest from the detailed script. Recording is one way of getting the detailed test inputs into a form that a test execution tool can use, and can be used from any of the starting points. However, we do not recommend that you attempt to automate ad hoc testing, as it will not give you effective testing. Automating a chaotic process will just give you faster chaos. We looked at the stages that you will go through in beginning to automate testing. The first step, especially if you have a capture replay tool, will
be to capture a test. What you actually capture is only the test inputs, however. Although this does give some advantages over typing the input manually, the test process still includes checking the screen manually as the test runs in order to see if the software is working correctly, as well as checking other things such as the file that was created. Test comparison is normally also automated. This can be done by dynamic comparison within the script, or by post-execution comparison after the test has completed. With dynamic comparison, there are a number of choices to be made. The decisions made will affect how easy the tests are to maintain, how easy it will be to identify defects found by the test, and how likely the test is to miss defects that could have been found (unexpected changes). Automating comparison still does not provide a good automated test, however. Other aspects must be taken into consideration. In our example, the file that was created by the test caused the test to fail the second time it was run automatically. This can be overcome, but this must also be built in to the test automation. There may be other things that need to be verified in addition to what we can see on the screen, such as files or databases which have been altered by the test. We also need to decide where the files used and produced by the automated test will go. . In a good test automation regime, tests are easy to run and self-sufficient, and it is easier to add a new automated test than to run that same test manually.
Much of this chapter may seem familiar to anyone who has ever read a 'How to write maintainable programs' book. The techniques for producing maintainable scripts have many similarities to those for producing maintainable programs. Yet it seems that people who abandoned 'spaghetti code' many years ago end up producing 'spaghetti test scripts.' This chapter aims to insure that any test scripts that you produce, if they are not simply to be thrown away after a single use, are properly engineered. 3.1.1 Similarities with programming
Test scripts are a necessary part of test automation for interactive applications and, in some cases, non-interactive applications. As we demonstrated in Chapter 2, the information contained within a script can be extensive, and the more information there is the more there is to go wrong, update, and manage. Writing scripts is much like writing a computer program. Most test execution tools provide a scripting language that is in effect a programming language; thus, automating tests is a case of programming tests. Of course programming tests correctly is no less difficult than programming software applications correctly and is usually about as successful. This means that no matter how clever we are at programming or testing there will be defects in the automated tests. The more programming, the more defects there will be. For the tests to work properly it is necessary to spend time testing the tests, debugging, and fixing them. This can become very time consuming, particularly because it is not limited to the first time the tests are automated. Changing the software usually forces some of the tests to be changed, for example, to cope with new options in the user interface, menu changes, user interactions, and changes to the expected results.
Test automation would be so much easier and quicker if it were not for the need to produce test scripts. This is a bit like saying that programming would be much easier if we did not have to write source code! However, this is exactly what we have been heading for during the past three or four decades. Third generation languages (3GLs) save us having to write a lot of assembler code, and fourth generation languages (4GLs) save us having to write as much 3GL code. We don't really want to have to write the code; rather we would prefer to only say what the system has to do and let it go ahead and do it (not having to tell it how to do the job). So it is with automated tests. We do not want to have to tell the tool down to every last keystroke how to run each test case, at least not all the time. Rather, we wish only to tell the tool what to do by describing the test case and not have to tell it how to execute it (a descriptive approach, not prescriptive). However, in the same way that 4GLs have not replaced 3GLs, and 3GLs have not entirely replaced assembler code, there are occasions when it is appropriate and necessary to write a script that specifies each individual keystroke. For example, when testing a real-time application, it can be useful to specify specific time delays between particular keystrokes. The purpose of 3GLs and 4GLs is to increase productivity and make programming easier. There are different scripting techniques that seek to do the same (increase productivity, make test automation easier). Although test scripts cannot be done away with altogether, using different scripting techniques can reduce the size and number of scripts and their complexity. This chapter describes a number of different approaches to scripting, explaining the advantages and disadvantages of each technique and when it may be appropriate to use one in favor of the others.
3.1.2 Scripting issues in general 3.1.2.1 What test scripts are used for
Recording a test case being performed manually results in one (usually long) linear script that can be used to replay the actions performed by the manual tester. Doing the same for a number of test cases will result in one script for each test case. So if you have thousands of test cases you will end up with thousands of scripts. The script is really a form of computer program, a set of instructions for the test tool to act upon. Having one such program for every test case is not efficient since many test cases share common actions (such as 'add new client,' 'query client details,' etc.). This will lead to higher maintenance costs than the equivalent manual testing effort because every copy of a set of instructions to perform a particular action will need changing when some aspect of that action changes. Most tools use a scripting language that offers far more power and flexibility than would ever be used by recording, but to benefit from it you have to edit the recorded scripts or write scripts (or rather, code scripts) from scratch. One of the benefits of editing and coding scripts is to reduce the amount of scripting necessary to automate a set of test cases. This is
achieved principally in two ways. One way is to code relatively small pieces of script that each perform a specific action or task that is common to several test cases. Each test case that needs to perform one of the common actions can then use the same script. The other way to reduce scripting is to insert control structures into the scripts to make the tool repeat sequences of instructions without having to code multiple copies of the instructions. Although these approaches inevitably cause us to code several more scripts initially, they are much smaller and therefore easier to maintain. Eventually, however, once a reasonably comprehensive set of scripts has been coded, new test cases can be added without the need to add more scripts so we enter a stage where thousands of test cases are implemented by hundreds of scripts. Scripts may contain data and instructions for the test tool, including: • • • • •
synchronization (when to enter the next input); comparison information (what and how to compare, and what to com pare with); what screen data to capture and where to store it; when to read input data from another source, and where to read it from (file, database, device); control information (for example, to repeat a set of inputs or make a decision based on the value of an output).
The actual content of a script will depend on the test tool being used and the scripting techniques employed. Like software, scripts are very flexible. There will usually be many ways of coding a script to perform a given task. The way a script is written usually depends on the skill of the person coding it but should also depend on its objective. A 'quick and dirty' approach may be to record as much as possible, or perhaps to copy parts of other scripts and cobble them together. A more thoughtful approach may involve some design work and coding from scratch. Some scripting techniques involve elaborate constructs and logic while others are much simpler. The more elaborate the scripting technique used, the more upfront work there will be and the more effort will be needed on debugging the scripts. However, there will also be greater end productivity because there will be more reuse of scripts and they will involve less maintenance. The more tests you automate, the more worthwhile it is to put the effort into the more elaborate scripting techniques. This is illustrated in Figure 3.1. However the scripts are created, what should concern us most is the cost of producing and maintaining them and the benefits we can obtain from using them. If a script is going to be reused by a lot of different tests that are expected to have a long life, then it will be worth ensuring that the script works well and is easy to maintain. If, however, the script is to be used for only one test case that will be discarded as soon as the testing has been completed, then there is little point in spending much effort creating it.
It is worth considering which scripting techniques you arc likely to use when you are choosing a tool so you can check for appropriate support (see Chapter 10). 3.1.2.2 Good versus bad scripts
Since scripts form such a vital part of most test automation regimes, it seems sensible that we should strive to insure that they are good. Certainly we can be sure that nobody would wish to be associated with bad scripts. So what is a good script? The easy answer to this question is 'a script that is fit for purpose' but that doesn't amount to a very comprehensive answer. Does this mean that a good script is one that does what it is supposed to do reliably and is easy to use and maintain? Often yes, but there are circumstances when scripts do not have to be particularly easy to use or maintain (such as the one-off automated test cases described earlier) though it is difficult to think of any circumstances when scripts need not do what they are supposed to or be unreliable. If you arc not concerned with ease of use or maintainability for any of your scripts then much of what we have to say in this section will be of little interest to you. Given that good scripts should be easy to use and maintain we can describe a few characteristics or attributes that will have a significant bearing on how easy to use or maintain a script really is. Rather than consider individual scripts, we will compare two sets of scripts that perform the same set of test cases in Table 3.1. When test automation begins, you will start out with a small number of scripts and it will not be difficult to keep track of them, but this task will become more difficult as the number of scripts increases. Ways of organizing scripts are described in Chapter 5.
Table 3.1 Comparison of good and poor sets of test scripts that perform the same set of test cases. Attribute
Good set of test scripts
Poor set of test scripts
Number of scripts
Fewer (Less than one script for each test case)
More (at least one script for each test case)
Size of scripts
Small - with annotation, no more than two pages
Large - many pages
Each script has a clear, single purpose
Individual scripts perform a number of functions, typically the whole test case
Specific documentation for users and maintainers, clear, succinct and up-to-date
No documentation or out-of-date; general points, no detail, not informative
Many scripts reused by different test cases
No reuse; each script implements a single test case
Easy to see and understand the structure and therefore to make changes; following good programming practices, well-organized control constructs
An amorphous mass, difficult to make changes with confidence; spaghetti code
Easy to maintain; changes to software only require minor changes to a few scripts
Minor software changes still need major changes to scripts; scripts difficult to change correctly
3.1.2.3 Principles for good scripts
What is it that makes a script 'easy to use' or 'easy to maintain'? There is bound to be a subjective element to the answers to these questions, as different people will have varying preferences as to the style, layout, and content of scripts. However, in our view the following principles provide a guide. Scripts should be: • • • • •
annotated, to guide both the user and the maintainer; functional, performing a single task, encouraging reuse; structured, for ease of reading, understanding, and maintenance; understandable, for ease of maintenance; documented, to aid reuse and maintenance.
These basic principles apply whatever scripting technique is used, but they may be implemented in different ways. For example, all scripts should be annotated, but the annotation may differ in style and format from one regime to another. 3.1.2.4 'Easy to read' scripts?
Occasionally a tool vendor will claim that its tool generates recorded scripts that arc 'easy to read' or even 'self documenting.' Such claims are misleading and very short-sighted. Let us deal with these claims once and for all. A 'raw' recorded script consists of a whole sequence of inputs for the test and may also include some verification. Some tools under user instruction can insert the verification instructions as the recording takes place. The end result is usually a long script, perhaps hundreds of lines covering several pages, that does not have a useful structure. It could be likened to a book that has no chapters or section headings but just page after page of text. Finding a particular topic in such a book would be tiresome to say the least, as you would have to read through it until you found the required text. So it is with a recorded script. The reason we would wish to look at a recorded script anyway is usually because we need to make a change to it, perhaps to insert some verification or control instructions, or to change a particular sequence of actions to reflect changes in the software under test. In order to make these changes correctly it will be necessary for us to find the relevant part of it, and the longer the script is, the more difficult this will become. It would also be wise for us to gain an understanding of the script as a whole, to help insure that any changes we make will not have adverse affects on other parts of the script or indeed any other scripts that use this one. Of course, finding things in a script and gaining an understanding of it will be easier for us if we are familiar with the scripting language. It will also be easier if there is some useful documentation in the script telling us what it does and how it does it. Script annotation, comments embedded throughout the script that say what is happening at each stage, will be the most helpful. Some tools automatically embed comments in the scripts they generate while recording and this is sometimes what the tool vendors allude to when they claim their tools' scripts are 'easy to read.' However, 'easy to read' can be taken to mean different things. Scripts usually comprise keywords that are the same as they appear in the English language, such as 'Type,' 'Button,' and 'Click.' Fair enough, but is this 'ease to read' what we want? Certainly we do not want 'difficult to read' scripts (perhaps using acronyms and symbols rather than proper words, although this would depend on the person doing the reading, since an experienced author may prefer familiar abbreviations and acronyms for ease and speed of typing and reading). When we wish to make changes to the script, its readability becomes very important, but readability in this sense means easy to understand. This leads us to the second common claim.
3.1.2.5 'Self-documenting' scripts?
'Self documenting' is a rather mythical term. To document a script means to give written information supporting or detailing it. We interpret this as written information that is useful and in addition to what is already there. The information that can usefully be written down somewhere includes the following: • • •
the raw content of the script (inputs and sometimes expected outputs); the purpose of the script (what this script does, the actions it performs); user information (what information has to be passed to the script, what information it returns, what state the software under test has to be in when the script is called, and what state the software will be left in when the script ends); implementation information (additional information helpful to maintainers, such as an explanation of why it was implemented in a particular way or references to similar scripts that may also need changing); annotation (comments embedded throughout the script to say what is happening at each logical step in terms of the actions being performed on or by the software under test).
It is only the first item above that a tool can generate. The only annotation that can be generated 'automatically' is limited to 'click the OK button,' 'focus on window "Payments'" and 'input the string "John Doe" in the field "name".' Such information is often rather obvious anyway, so the annotation is generally not adding any value. This type of annotation certainly is not sufficient if the script is to be used and maintained effectively and efficiently. None of the other information can be generated automatically. But if you want understandable scripts, someone must produce this information, generally a job for the script's author. To add this information to the script, this person needs to be able to edit the script itself so he or she needs to have some technical skills (unless the tool supports easy insertion of comments during script creation). If the people recording the scripts are not technical, then adequate support must be provided to them. Simply recording a long test is not by any means the end of the story; there is a lot more work to be done. However, a recording is often the place where test automation starts and is sufficient in a few instances.
3.1.3 Test case design and implementation 3.1.3.1 Test case design
There is not always a direct relationship between an automated script and a test case. In fact, what is taken to be a test case can vary enormously. For some people a single test case may last only a few seconds or minutes but for others a test case can last for several hours. Long test cases can usually be considered as a series of individual tests, as shown in Figure 3.2. The rectangles in this figure each represent a single test case and include 'in' and 'out' activities such as invoking the software under test and terminating its
execution. In Figure 3.2(a) each test is implemented as a separate test case, whereas in Figure 3.2(b) a single test case executes all four tests. It is important to realize that tests 2, 3, and 4 are performed under different conditions, so, strictly speaking, they are different tests. However, the inputs and expected outcomes would be the same for the tests, whichever way they were performed. We use the term 'test case' to mean a scries of one or more tests that can be meaningfully distinguished from other such series. For example, running one test case on our Scribble program may involve starting the program, opening a particular document, performing some edits, saving the document, and exiting the program. However, some people's perception of a test case would not include starting and exiting the program. Thus, if a set of test cases were performed, the program could be started, all the test cases run and then the program terminated. It may be helpful to think of a single automated test case as being the shortest sequence of tests that collectively are assigned a single status. Commercial test tools typically assign a 'passed' or 'failed' status to some amount of testing but they are not so consistent when it comes to naming this unit of testing. For example, test case, test procedure, and test script are used by different tools to mean the same thing. We will use the term test case. 3.1.3.2 Jest case implementation
Regardless of how long or short, complex or simple test cases are, there is not necessarily a direct relationship between the test cases and the scripts used by the test tool in performing them. Although a few tools force their users into defining separate 'scripts' for each test case, this is not generally helpful when implementing a test automation regime of any substance. At first it may seem sensible to implement each test case using a single script. Indeed, this is actually encouraged by some tools. However, as we shall show, this is not going to lead to an effective and efficient test automation regime. Implementing automated tests in this way will always be costly, and the cost of maintaining them will continue to grow and probably become greater than the cost of performing the same tests manually. The following section describes a number of scripting techniques that take us into script programming. It is only by breaking the 'one test case one test script' relationship that we will ever achieve a good automated testing regime.
3.1.4 Recommendations for script documentation
We recommend that the documentation for each script is placed in the header of the script itself and that it should be as concise as possible. These two points will help whenever the script is changed, since whoever is making the change will be more likely to update the documentation as well as the body of the script. The layout of the script documentation is a matter of style that may already be governed by existing coding standards or conventions (if these work well then use them; if not then change them). In our view it is important that everyone who writes or edits scripts conforms to the same conventions. Everyone will know what information to include in the documentation, where to put it, and how to present it. They will also know where to look for particular information. Another advantage of everyone conforming to the same standards or conventions is that it makes it easy to copy the information from each script into a separate document such as a catalog of all shared scripts. Such a task can be automated easily using one or two suitable text manipulation tools, and indeed it is best automated since it can be run 'at the touch of a button' to produce an up-to-the-minute catalog. We suggest a script header layout like that shown in Figure 3.3. This can be used as a template for all scripts or it can be adapted for different types of scripts (though we do prefer to see one common header for all scripts). The actual layout is not as important as the content but we do recommend all our scripts are laid out in a consistent way. Note that the semicolon at the start of each line in Figure 3.3 is used here as a comment marker to tell the test tool to ignore the whole line. How comments are identified in your scripts will depend on the tool you use. ; Test Automation Script ; SCRIPT: ; AUTHOR: ; DATE : ; PURPOSE : ; PARAMETERS : ; PRE- AND POSTCONDITIONS: ; MAINTENANCE ; AMENDMENTS : ; <what & why>
Figure 3.3 Our suggestion for a script header. This contains all the information necessary to understand what a script does and how to use it. It also contains any information that would benefit someone who has to maintain the script.
Everything in this template has a purpose but they will not all be relevant to everyone. The template contains a series of keywords which serve to remind the script writer what information to document (and where to put it) and make it easy to automate the task of copying the information into a separate file. The title Test Automation Script' simply tells us what this is. It may seem like overkill but it can be useful in environments where there are a lot of different types of file and all with numerous uses. It would be improved if it included the name of the test tool (particularly if the scripting language is unique to the tool). Similarly, the keyword 'SCRIPT' should be followed by the name of the script. This will be redundant if printouts automatically have the filename included. The purpose is to avoid the problem of finding a printout without the filename on it - it can be time consuming, if not difficult, to find out the script's name. The 'AUTHOR' and 'DATE' keywords should be followed by the name of the scriptwriter and the date when it is written. Having the author's name clearly makes it possible to identify who wrote the script, something that can be useful to know (to ask questions or to ask for help, for example). The date may be redundant, particularly if there is a good configuration management system in place that can provide this information. A brief statement as to the purpose of the script should follow the 'PURPOSE' keyword. Usually this will not need to be more than a single, short sentence. If it is any more then it is likely that the script is performing too much and may be better divided into two or more smaller (and possibly more reusable) scripts. We prefer the keyword 'purpose' rather than the ubiquitous 'description' since it discourages totally worthless statements like 'This is a script.' The 'PARAMETERS' keyword heads up a section of the header that describes any parameters that arc accepted or returned by this script. It may be helpful to distinguish between parameters that are passed in and those that are passed out or returned. The 'PRE- AND POSTCONDITIONS' section informs users of the script what state the software under test has to be in at the time the script is called and what state the software will be left in when the script has completed. This is particularly important information if users of the script are going to be able to use it correctly first time, every time. For example, the script may expect the software application to have a specific dialog box displayed but will leave a different one displayed when it exits. If the person using this script did not know this, the script may be called when the required dialog box was not displayed. This could cause the test case to fail (but not necessarily at the point the shared script was called, thereby making it more difficult to identify and correct the problem). The 'MAINTENANCE' section contains any information that would be useful to people who will be maintaining the script. Most of the time this will be blank (rather than removed altogether) since the user information given in the rest of the header together with the script annotation will be sufficient. However, sometimes scripts have to be implemented in a strange or unusual way in order to avoid some problem or other (such as a tool feature that does not work correctly or an idiosyncrasy of the software application).
The 'AMENDMENTS' section contains details of all changes made to the script since it was first completed. The 'id' can be used to mark all the lines in the script that are altered or added in order to make the amendment. Again, this section may be redundant if there is a good configuration management system in place that can provide this information.
3.2 Scripting techniques We now look at some different scripting techniques and their uses. These techniques are not mutually exclusive. In fact, the opposite is true - they can, and most likely will, be used together. Each technique has its own advantages and disadvantages that affect the time and effort it takes to implement and maintain the test cases that the scripts support. However, it is not which techniques are used that is most significant; rather, it is the overall approach taken by the whole regime in implementing test cases supported by the scripts. This has the greatest impact. There arc two fundamental approaches to test case implementation, prescriptive and descriptive. These are discussed later in this chapter, after we have seen what different scripting techniques look like. In the rest of this section, we use simple example scripts to illustrate the points we wish to make, using a pseudo-scripting language which should be understandable to all readers, whether or not you have actually used a tool. In reality, the actual tool scripts would be more complex than the examples we show. For simplicity, we show only the minimum script features that allow us to explain the different scripting techniques. The scripting techniques described are: • • • • •
linear scripts; structured scripting; shared scripts; data-driven scripts; keyword-driven scripts.
3.2.1 Linear scripts
A linear script is what you end up with when you record a test case performed manually. It contains all the keystrokes, including function keys, arrow keys, and the like, that control the software under test, and the alphanumeric keys that make up the input data. If you use only the linear scripting technique - that is, if you record the whole of each test case -each test case will be replayed in its entirety by a single script. A linear script may also include comparisons, such as 'check that the error message Position not valid is displayed.' Adding the comparison instructions may be done while the test case is being recorded (if the test tool allows this) or it may be done in a separate step afterwards, perhaps while replaying the recorded inputs from the script.
Note that a test case that takes 10 minutes to run manually may take anywhere from 20 minutes to 2 hours to automate with comparison. The reason for this is that once it is recorded, it should be tested to make sure it will play back - it is surprising how often this is not the case! Then it may need to be played back again while the specific comparison instructions are added, and the new script with comparison embedded should also be tested. If it is not correct, the test script then needs to be debugged and tested again. The more complex the application and test case, the longer this process is likely to take. 3.2.1.1 Advantages of linear scripts
Linear scripts have advantages that make them ideal for some tasks. The advantages are: »
no upfront work or planning is required; you can just sit down and record any manual task; » you can quickly start automating; • it provides an audit trail of what was actually done; » the user doesn't need to be a programmer (providing no changes are required to the recorded script, the script itself need not be seen by the user); • good for demonstrations (of the software or of the tool).
3.2.1.2 When to use linear scripts
Almost any repetitive action can be automated using a linear script. There are some situations where a simple linear script is the best scripting technique to use. If a test case will only be used once, for example, to investigate whether a test execution tool works in a given environment, then there is no point in investing any more effort than necessary in such a script since it will be thrown away. Linear scripts can be used for demonstrations or training. When you want to show the features of the software to a potential customer, and don't want to have to be concerned with typing in exactly the right keystrokes when you are feeling a little nervous anyway, replaying a recorded script will reproduce the keystrokes exactly. Linear scripts can be used to automate edits to update automated tests. Any given update will probably only be done once, so a throwaway script is all that is needed. Linear scripts can be used to automate set-up and clear-up for tests, or to populate a file or database by replaying an input sequence. Linear scripts can be useful for conversions. If some part of the system has been changed but without changing the working of the system from the user's perspective, recording live data one day, replacing the software or hardware, and then replaying the day's traffic can give an initial level of confidence that the new system generally works. This approach has been used successfully for benchmark testing for Year 2000 conversion.
3.2.1.3 Disadvantages of linear scripts Linear scripts do have a number of disadvantages, particularly with respect to the building of a long-term test automation regime: •
the process is labor-intensive: typically it can take 2 to 10 times longer to produce a working automated test (including comparisons) than run ning the test manually; • everything tends to be done 'from scratch' each time; • the test inputs and comparisons are 'hard-wired' into the script; • there is no sharing or reuse of scripts; • linear scripts are vulnerable to software changes; • linear scripts are expensive to change (they have a high maintenance cost); • if anything happens when the script is being replayed that did not happen when it was recorded, such as an unexpected error message from the network, the script can easily become out of step with the soft. ware under test, causing the whole test to fail. These disadvantages make the sole use of linear scripts to automate testing an impractical approach for long-term and large numbers of tests. Every test to be automated will take as much effort as the first, and most scripts will need some maintenance effort every time the software under test changes.
3.2.2 Structured scripting Structured scripting is parallel to structured programming, in that certain special instructions are used to control the execution of the script. These special instructions can either be control structures or a calling structure. There are three basic control structures supported by probably all test tool scripting languages. The first of these is called 'sequence' and is exactly equivalent to the linear scripting approach we described earlier. The first instruction is performed first, then the second, and so on. The other two control structures are 'selection' and 'iteration.' The selection control structure gives a script the ability to make a decision. The most common form is an 'if statement that evaluates a condition to see if it is true or false. For example, a script may need to check that a particular message has been displayed on the screen. If it has it can continue; if it has not it has to abort. In this example the condition is whether or not a particular message has been displayed. The iteration control structure gives a script the ability to repeat a sequence of one or more instructions as many times as required. Sometimes referred to as a 'loop,' the sequence of instructions can be repeated a specific number of times or until some condition has been met. For example, if a script were required to read records containing data from a file, the sequence of instructions would perform the read and process the information in some
way. This sequence can then be repeated until all the records in the file have been read and processed. In addition to the control structures, one script can call another script, i.e. transfer control from a point in one script to the start of another sub-script, which executes and then returns to the point in the first script immediately after where the sub-script was called. This mechanism can be used to divide large scripts into smaller, and hopefully more manageable, scripts. Introducing other instructions for changing the control structure gives even more opportunities for not only increasing the amount of reuse we can make of scripts but also increasing the power and flexibility of the scripts. Making good use of different control structures leads to maintainable and adaptable scripts that will in turn support an effective and efficient automated testing regime. Making good use of different structured scripting techniques does require programming skills. It is not necessary to have years of programming experience or indeed knowledge of numerous programming languages. We would suggest that the minimum requirement is someone who is interested in learning and is given both the time and resources (such as training) to learn. If experienced programmers can be brought into the test automation project, so much the better. Figure 3.4 shows a script for part of our Scribble test. After entering the filename and clicking the OK button in the Save As dialog box, the script then checks to see if there has been a Replace existing file? message output. If there has, it will click the OK button, but if not it will continue in the normal way. This example has been simplified. In practice a script may have to wait a few seconds to give Scribble time to display the message. The script probably would also need to move the focus to the message box before it
Part of the Scribble test script SelectOption 'File/Close' FocusOn ' Close ' LeftMouseClick 'Yes' FocusOn 'Save As' Type countries2 LeftMouseClick 'Save' If Message = 'Replace existing file?' LeftMouseClick 'Yes' End if FocusOn 'Scribble' SelectOption 'File/Exit'
Figure 3.4 This script fragment contains a check for a Replace existing file? message using an 'If instruction (shown in bold). If this message is displayed the OK button will be clicked. If the message is not displayed the script will continue as usual.
could read the message. These considerations further complicate the script but this may be well worth doing since it makes the script more flexible and robust. The main advantage of structured scripting is that the script can be made more robust and can check for specific things which would otherwise cause the test to fail, even though the software was working correctly as shown in Figure 3.4. A structured script can also deal with a number of similar things that need to be repeated in the script, using a loop. A structured script can also be made modular by calling other scripts. However the script has now become a more complex program and the test data is still 'hard-wired' into the script. 3.2.3 Shared scripts
Shared scripts, as the name implies, are scripts that are used (or shared) by more than one test case. Of course, this implies that we require a scripting language that allows one script to be 'called' by another but this is more or less standard across all test execution automation tools. The idea of this is to produce one script that performs some task that has to be repeated for different tests and then whenever that task has to be done we simply call this script at the appropriate point in each test case. This gives two distinct advantages: first, we do not have to spend time scripting (writing or recording the actions required); and second, we will have only one script to change in the event that something concerning the repeated task changes. One of the features of current development tools is the ease with which graphical development environments can change the user interface to a system. However, the aspects that make this so attractive to users and developers are also the aspects that can be most destabilizing to automated testing. The use of shared scripts is one step towards building automated tests that can keep up with rapidly changing software, i.e. that will not require extensive maintenance. For example, rather than have the navigation repeated in a number of scripts, when the commands to navigate to a particular place in the application are identical, there can be a single shared script that does the navigation for all tests. The shared script contains the inputs to the application that cause it to navigate to a particular screen which is the starting point for a number of tests. Each of the tests calls the navigation script and then runs the detailed test. When the tests are completed, a common script would be called to navigate back out to the main menu.
3.2.3.1 Going from a linear to a shared script: example An example of shared scripts for our example Scribble test case is shown in Figure 3.5. A shortened linear script Scribblel shown on the left has been divided into the three separate scripts shown on the right-hand side. The first of these new scripts, ScribbleOpen, invokes the Scribble application and causes it to open a document, the name of which is passed into the script at the time it is called. Similarly, the last of these new scripts, ScribbleSaveAs, causes
Shared script: ScribbleOpen (FILENAME)
A shortened original linear script: Scribblel
LeftMouseClick 'Scribble' FocusOn ' Scribble ' SelectOption 'File/Open' FocusOn ' Open ' Type ' countries ' LeftMouseClick ' Open ' FocusOn ' Scribble ' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' Sweden ' LeftMouseClick 'OK' FocusOn ' Scribble ' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' USA ' LeftMouseClick 'OK' FocusOn 'Scribble' SelectOption 'File/Close' FocusOn 'Close' LeftMouseClick ' Yes ' FocusOn ' Save As ' Type ' countries2 ' LeftMouseClick ' Save ' FocusOn ' Scribble ' SelectOption 'File/Exit'
LeftMouseClick 'Scribble' FocusOn 'Scribble' SelectOption 'File/Open' FocusOn ' Open ' Type FILENAME LeftMouseClick 'Open' A
New script: Scribblel
Call ScribbleOpen ('countries') FocusOn ' Scribble ' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' Sweden ' LeftMouseClick 'OK' FocusOn 'Scribble' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' USA ' LeftMouseClick 'OK' FocusOn ' Scribble ' Call ScribbleSaveAs ( ' countries2 ' )
Shared script: ScribbleSaveAs (FILENAME)
FocusOn ' Scribble ' ' ' SelectOption ' File/Close ' FocusOn 'Close' LeftMouseClick 'Yes' FocusOn ' Save As ' Type FILENAME LeftMouseClick 'Save' FocusOn ' Scribble ' SelectOption 'File/Exit'
Figure 3.5 A shortened version of the original linear script Scribblel shown on the left has been divided into the three separate scripts shown on the right-hand side.
Scribble to save the current document using a name that is passed into it at the time it is called. The third script (the new Scribblel) first calls ScribbleOpen then performs the testing actions before calling ScribbleSaveAs to finish. Of course it will take longer to implement the shared scripts version of the test case since we have to create three scripts instead of just the one. If we create them by editing a recorded script, the two shared scripts will need to be changed so the filename they enter is not the one used at the time they were recorded but can be specified at the time the script is called. This is usually achieved by replacing the literal filename with a variable name (here we have used the variable name FILENAME), which can be thought of as a place marker that will be substituted for the real filename by the test tool when the script is called. The new test script Scribblel will also have to be edited to insert the calls to the two shared scripts.
Scribble2 (linear)
Lef tMouseClick ' Scribble ' FocusOn ' Scribble ' SelectOption 'File/Open' FocusOn 'Open' Type ' countries ' Lef tMouseClick 'Open' FocusOn ' Scribble ' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' France ' Lef tMouseClick 'OK1 FocusOn ' Scribble ' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' Germany ' Lef tMouseClick 'OK' FocusOn ' Scribble ' SelectOption 'File/Close' FocusOn 'Close' Lef tMouseClick ' Yes ' FocusOn ' Save As ' Type 'test2' Lef tMouseClick ' Save ' FocusOn 'Scribble' SelectOption 'File/Exit'
ScribbleZ (using shared scripts)
Call ScribbleOpen( countries ) FocusOn 'Scribble1 SelectOption 'List/Add Item' FocusOn 'Add Item' Type 'France1 Lef tMouseClick 'OK' FocusOn 'Scribble' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' Germany ' Lef tMouseClick 'OK' FocusOn 'Scribble' Call ScribbleSaveAs ('test2')
Figure 3.6 The second and subsequent test cases can be implemented much more easily since the shared scripts can be reused.
Actually, calling the two shared scripts 'shared' is a bit misleading at this time since they are not shared at all! Only one script calls them. However, as soon as we start to implement another similar test case we can use them a second time. Figure 3.6 shows a new control script, Scribble2, that implements a slightly different test. This is much shorter than the linear script for this test case so it should not take as long to implement. We can carry on implementing more test cases that each call these two shared scripts and others beside. If the user interface of Scribble changes such that one of the shared scripts needs changing we will have only the one script to change. Had we used different linear scripts to implement the whole of each test case then we would have to change every one. This approach is useful for any actions that are done often or that are susceptible to change. Navigation is one example, but any scripted activity that is repeated often may well be better in a common script, particularly if it is a complex or lengthy sequence. 3.2.3.2 Types of shared scripts
There are two broad categories of shared script, those that can be shared between tests of different software applications or systems, and those that can only be shared between tests of one software application or system. Some examples of these two categories are given in Table 3.2. Note that application-independent scripts may be more useful long term, and are worth putting additional effort into.
Table 3.2 Types of shared scripts, Application-specific scripts
Application-independent scripts
Menus Individual screen/window routines Non-standard controls Navigation
Login and logout Synchronization Logging Input retrieval Results storage Error recovery Data-driven shell Checking or comparison
3.2.3.3 Advantages and disadvantages of shared scripts
The advantages of shared scripts are: » » » »
similar tests will take less effort to implement; maintenance costs are lower than for linear scripts; eliminates obvious repetitions; can afford to put more intelligence into the shared scripts. For example, on login if the network is busy, wait 2 minutes and try again. It wouldn't be worth doing that in hundreds of scripts, but is well worth doing in one.
The shared scripting approach is good for small systems (for example, simple PC applications and utilities) or where only a small part of a large and stable application is to be tested using relatively few tests (a few tens of tests, certainly no more than a few hundred). There are also some disadvantages to shared scripts: « « »
there are more scripts to keep track of, document, name, and store, and if not well managed it ma^ be hard to find an appropriate script; test-specific scripts are si ill required for every test so the maintenance costs will still be high; shared scripts are often specific to one part of the software under test.
3.2.3.4 How to get the best out of shared scripts
In order to reap the benefits of shared scripts, you have to be disciplined. You have to insure that all tests actually do use the shared scripts where they arc appropriate. We were once told that programmers will look for a reusable function for up to two minutes before deciding to implement their own version. We are sure this is much the same for automated test script writers. Knowing that there is, or at least should be, a reusable script to do a particular job is one thing; being able to find it is another. If it cannot be found quickly people will write their own version of it and then we will have a much more difficult task with maintenance updates. When the script
needs changing the person undertaking the maintenance will believe that it is only the shared script that needs changing. The fact that there is another script that needs editing may not be realized until the tests are run. Even then it may not be obvious what the problem is. Some form of reusable script library will help matters considerably. This has to be set up and managed, and although it will not be a full-time job, it is likely to take a significant amount of effort in the early days. Script libraries are an aspect of testware architecture, which is covered by Chapter 5. Another aspect of shared scripts that needs careful attention is their documentation. The scripts need to be documented in such a way that makes it easy for testers to determine what each one does (to tell whether this is really what they need) and how to use it. Software documentation in general is notoriously poor. Where it exists it is often out of date or just plain wrong. If these traits are carried into the documentation of our scripts then automation will suffer from unnecessarily high implementation and maintenance costs. A good way to try to avoid these problems is to adopt conventions and define standards for scripts. These will form a part of the overall test automation regime. They will not only help insure documentation is considered but also will guide new script writers as to how to go about creating scripts (and how to make new shared scripts available for others to use). 3.2.4 Data-driven scripts A data-driven scripting technique stores test inputs in a separate (data) file rather than in the script itself. This leaves the control information (e.g. menu navigation) in the script. When the test is executed the test input is read from the file rather than being taken directly from the script. A significant advantage of this approach is that the same script can be used to run different tests. For example, one test for an insurance system will enter the details of a new insurance policy and verify that the database has been updated correctly. A second test would do the same thing except it would use a different insurance policy. It therefore requires the same instructions but different input and different expected outcomes (the values that describe a different insurance policy). These two tests can be implemented using a single test script and a data file. 3.2.4.1 Data-driven example 1: using the same script with different data Figure 3.7 shows how this could work with our Scribble test case at a basic level. (Figure 3.8 shows a more sophisticated approach.) Rather than having one script for each test case we can now implement numerous test cases with a single script. We will refer to this single script as the control script because it controls the execution of a number of test cases. Note that each of the test cases we are showing here only adds two names to the list of names in the file 'countries.' This is because we have shortened the original
Control script: ScribbleControl
Original script: Scribblel
Call ScribbleOpen ('countries1) FocusOn 'Scribble' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' Sweden ' LeftMouseClick 'OK' FocusOn ' Scribble ' SelectOption 'List/Add Item' FocusOn 'Add Item' Type ' USA ' LeftMouseClick 'OK' FocusOn 'Scribble' Call ScribbleSaveAs ( 'countries2 ' )
OpenFile ' ScribbleData ' For each record in ScribbleData Read INPUTFILE Read NAME1 Read NAME2 -* --------Read OUTPUTFILE Call ScribbleOpen (INPUTFILE) FocusOn ' Scribble ' SelectOption 'List/Add Item1 FocusOn 'Add Item' Type NAMEl LeftMouseClick 'OK' FocusOn 'Scribble' SelectOption 'List/Add Item1 FocusOn 'Add Item1 Type NAME 2 LeftMouseClick 'OK1 FocusOn ' Scribble ' Call ScribbleSaveAs (OUTPUTFILE) EndFor Data file: ScribbleData
countries, countries, countries, countries,
Sweden, USA, countries2 France, Germany, test2 Austria, Italy, test3 Spain, Finland, test4
Figure 3.7 The Scribble test case implemented using the data-driven technique. Note that the data file ScribbleData actually contains the input of four test cases. These are all implemented using just the one control script (here called ScribbleControl) and the one data file.
script to accommodate it in the example. Whether the four test cases we have defined here would be useful is not the point of the example; rather it is to demonstrate the technique of data-driven scripts. The control script shown in Figure 3.7 contains an almost exact copy of the script for a single test case. The only differences are that instead of literal data in the script we have used variable names. (You will remember from our discussion of shared scripts that a variable name can be thought of as a place marker that will be substituted for the real data by the test tool when the script is executed.) In addition to these changes we also have to insert some additional instructions, which are shown in bold type. The first instruction OpenFile basically tells the test tool that it will be reading data from the file ScribbleData. The second instruction is actually one of a pair of instructions that implement an iteration control structure. The other half of this pair is the EndFor, the very last statement in the script. All the instructions in between this pair arc executed once for every record in the data file ScribbleData. The next four instructions each read one value from the current record in ScribbleData and store the value in a different variable name (the variable names used are the same as those used in the next part of the script).
3.2.4.2 Data-driven example 2: more sophisticated data-driven script
Figure 3.8 shows a more sophisticated approach to using data-driven scripts. Here we are building in some knowledge of our application into our control script. Each column of the data table now represents a type of input. The first column is the filename (to open or save to), the second column is the data to add to a list, the third and fourth columns are the location in the list to move from and to, respectively, and the fifth column is the position number to delete. We have two data files. The first is the complete test we performed in Chapter 2. (This form of scripting is a very concise way of showing what our test was.) The second script adds a couple of different countries, does a few more tests of the 'move' function, and deletes the first item of the list, saving to the file 'test2.' We can see that our control script now contains 'if statements that check each column to see if it is blank. If not, then it processes the data in a
Data file: ScribbleData 1 Control script: ScribbleControl
OpenFile ' ScribbleDataX ' Read INPUTFILE Call ScribbleOpen (INPUTFILE) Go to next record (ie row) For each record in ScribbleData Ignore first field if blank Read ADDNAME IF ADDNAME not = Blank THEN FocusOn 'Scribble' SelectOption 'List/Add Item' FocusOn 'List Add Item' Type ADDNAME LeftMouseClick 'OK' Read MOVEFROM Read MOVETO IF MOVEFROM not = Blank THEN FocusOn 'Scribble' SelectOption 'List/Move Item' FocusOn 'Move Item' Type MOVEFROM Type Type MOVETO LeftMouseClick 'OK' Etc. EndFor
INPUTFILE countries
ADDNAME
MOVEF ^OM/T DELPOS
Sweden USA
2 7 countries2 Data file: ScribbleData2
MOVEF ROM/T DELPOS
France Germany
Figure 3.8 A more sophisticated data-driven script.
specific way depending on the column position in the table. So the script 'knows' that column 2 contains things to add to a list, that column 5 contains the position number to delete, etc. This makes the control script more complex. (Note that you can't put 'Etc.' in a real script!) In fact, the control script needs to be designed as the small software module that it has now become. There are a number of design decisions that need to be made. For example, should the two filenames be in the single data file, or would it be better to have another data file containing only filenames, with the main data file containing only the input data? Should the processing of the filename be inside or outside the main control loop (for each record)? Should the read of 'moveto' be done inside the 'if statement when 'movefrom' is not blank? Should the column headings be included in the data file? (Yes, they definitely should!) But then the control script needs to ignore the first record. If one column is not blank, should the script check that all other columns are blank? What if they aren't? (The control script would actually handle a data file that contained a list item to be added and a 'move item' test in the same row.) These design decisions are not difficult (for an experienced programmer) but they all do need to be made. Whatever design decisions arc made about the control script, the data file must correspond to it. This means that if we change either the control script or the format of the data table, we need to make sure they are still 'in synch.' Note also that because different columns represent different types of data, our table has a lot of blank spaces. Our last scripting technique, keyword-driven, overcomes these problems.
3.2.4.3 Why make things so complicated? These additional instructions do make the script more complicated to implement and maintain, and it is definitely a task that requires programming skills. In using this approach we are opening ourselves up to a vast array of errors that can be easy to make but very difficult to find. It is extremely unlikely that we will always write the scripts correctly the first time around so it will become necessary to test the tests and debug them before we can actually use them to test the software. For all this additional difficulty, it is often well worth the effort since the benefits can greatly outweigh the costs. Once the control script has been implemented, new test cases, similar to the first one, can be added much more quickly and without any additional scripting. To add new test cases we simply have to add new data records into the data file, or add new data files in the same format that can be read by the control script.
3.2.4.4 Advantages of data-driven scripts At the data-driven scripting level we can now really start to benefit from test automation. Using this technique it is possible to implement many more test cases with very little extra effort. This is because all we have to do is specify a new set of input data (and expected results) for each additional test case. We will not have to implement any more scripts. For example, Figure 3.9 shows a set of regression tests (represented by the crosses) each exercising a different
part of the software under test. Let us assume that these are all the regression tests that we could afford to run manually. They would clearly be a good target for automation. If we automated them using linear or shared scripts then initially these are all we may automate. However, using the data-driven technique we could easily add many more test cases around each of the original regression tests. Because they would be using exactly the same script instructions, the only aspects that we can readily change are the input data and the expected outcomes. However, this is sufficient to enable us to produce numerous other test cases. They are unlikely to be test cases that we would necessarily consider performing if they had to be done manually but because they can now be implemented and run so cheaply, we can justify the effort. A major advantage of the data-driven technique is that the format of the data file can be tailored to suit the testers. For example, with a little more sophistication in the scripting, the data file can be allowed to contain comments that the script will ignore but that will make the data file much more understandable and, therefore, maintainable. Another approach to this is for the testers to use a different format altogether to specify the test input. For example, it is common for testers to use a spreadsheet package. Once the spreadsheet has been completed it is converted to a more neutral format (typically a comma-separated text file, as used for the data file in Figure 3.7). The spreadsheet is kept as the master version and any changes required are made directly to the spreadsheet rather than the data file. Whenever changes are made the data file is regenerated from the spreadsheet. The benefits of this ability for you to choose the format and layout of your test data should not be underestimated. Much effort will be spent in implementing automated tests and maintaining them. It is well worth investing a little time experimenting with different formats and layouts in order to find one that makes it really easy for your testers (not necessarily the automators) to edit the test data. The easier it is, the quicker and less error prone it will be - a goal worth striving for.
Software under test Key automated regression test cases Additional automated regression test cases made possible by data-driven scripting technique
Figure 3.9 An advantage of the data-driven scripting technique is that many additional test cases (represented here by •) can be used. These would not be undertaken without the data-driven technique since the cost of implementing and running them would be too high. The data-driven technique makes them cheap to implement and maintain and therefore worthwhile.
In addition to the test input, the expected results are also removed from the script and put into the data file. Each expected result is directly associated with a particular test input, so if the inputs are in the data file, the results to compare to must also be in the data file. A lot of test execution automation tools encourage this by providing mechanisms for capturing information on the screen and storing it somewhere as expected results for comparison with new results generated by a later run of the test.
One company needed some maintenance effort tor its automated scripts before they could be run. However, the company was unable to bring in rho programming effort in time (due to pressure of other work on the programmers). Unable to USP the automated tests, it had to test the new release of software manually.
Summarizing the advantages of the data-driven approach: » « »
similar tests can be added very quickly; adding new tests can be done by testers without technical or programming knowledge about the tool scripting language; there is no additional script maintenance effort for the second and subsequent tests.
3.2.4.5 Disadvantages of data-driven scripts
Writing these control scripts does need to be done by someone with a technical (programming) background and this is often a stumbling block. If your testers are not comfortable with programming automated test scripts then the skill has to be brought into the team, though not necessarily full time. If the programming skill is not available full time it is important to insure that it can be called on at very short notice. The initial set-up will take some time but the benefits gained (faster to add new tests and less maintenance) will vastly outweigh this upfront cost when you have hundreds rather than dozens of tests. When a reasonably comprehensive set of test scripts is available, many more tests can be implemented and run. In practice, organizations that have done this find themselves implementing considerably more tests than they would have even thought about running manually. They also run these tests many more times within a single software release cycle, mostly as regression tests. If you don't have many tests, this approach will entail more work, and will seem excessive. So for small systems this may not be appropriate. However, for large systems that arc expected to live a long time and change frequently, you will appreciate this approach and gain far more in saved effort than you put in.
The disadvantages of the data-driven approach are: • • •
initial set-up takes of lot of effort; specialized (programming) support is required; it must be well managed.
3.2.5 Keyword-driven scripts 3.2.5.1 Keyword-driven scripts incorporate application knowledge
'Keyword-driven scripts' is the name we have given to what is really a logical extension of the more sophisticated data-driven technique. A limitation of the data-driven technique is that the navigation and actions performed have to be the same for each test case, and the logical 'knowledge' of what the tests are is built into both the data file and the control script, so they need to be synchronized. However, there is nothing to say that we cannot take out some of the intelligence from the script and put it into the data file. Taking a literal approach to this would permit a single control script to support a wider variation in what the associated test cases could do but the vastly increased complexity of the data file (due to the scripting instructions it would now contain) would most likely outweigh any benefits. Furthermore, the job of debugging an automated test case implemented in this way could be seriously more difficult. As we explained in Chapter 2, one of the reasons scripts can be so complex is that every single action has to be specified in the finest detail. For example, to specify an automated test using a linear script we would say: Enter 'John Smith' into the first field, press the tab key, enter '38 Yellow Brick Road' into the second field, press the tab key, etc. To specify the same test using a data-driven approach we would say: Enter 'John Smith' into the name field, enter '38 Yellow Brick Road' into the street field, etc. If we were writing the instructions for a human tester rather than a test tool, we could simply state the action: 'Enter the following client details: John Smith, 38 Yellow Brick Road.' We do not have to tell the human tester exactly how to enter the client details. In other words, we can assume that the human tester has some knowledge about the system under test or at least how to navigate a computer program. The keyword-driven technique combines the data-driven technique with the desire to be able to specify automated test cases without having to specify all the excruciating detail. We expand the data file so it becomes a description of the test case we wish to automate using a set of keywords to indicate the tasks to be performed. The control script then has to be able to interpret the keywords but this is implemented outside of the control script itself. This additional level of separation from the implementation (tool) level does require an additional layer of technical implementation. Although this sounds as though it would be more difficult, we believe that it is actually much easier in the long run. The trick is to identify the right keywords.
An example of a keyword-driven script is shown in Figure 3.10. Rather than a data file we now have what we can call a test file since it describes the test case. The control script reads each keyword in the test file in turn and calls the associated supporting script. The supporting script may require more information from the test file, and this can either be read directly or passed on by the controlling script. The control script is no longer tied to a particular feature of the software under test, nor indeed to a particular application or system. Figure 3.10 also shows two test files associated with a different application, a drawing package called Doodle. Note that we said the test file describes the test case; that is, it states what the test case does, not how it does it. At the start of this section on scripting techniques we said that there are two fundamental approaches to test case implementation, prescriptive and descriptive. Up until now all the scripting techniques we have described are used for a prescriptive approach to implementation. Keyword-driven scripting allows us to take a descriptive approach. To implement an automated test case we have only to provide a description of the test case more or less as we would do for a knowledgeable human tester. The effect of this descriptive approach is that we build knowledge of the software under test into our test automation environment. This knowledge is contained in the supporting scripts. They 'know' about the software under test but they do not know anything about our test cases.
Thus it is possible to develop the test cases separately from the test scripts and vice versa. People with business knowledge and tester skills can concentrate on the test files while people with technical knowledge can concentrate on the supporting scripts. Of course they cannot work completely independently since the supporting scripts have to support the keywords used in the test files. 3.2.5.2 Advantages of keyword-driven scripts
The advantages of this approach are immense. Generally the number of scripts required for this approach is a function of the size of the software under test rather than the number of tests. Thus, many more tests can be implemented without increasing the number of scripts, once the basic application supporting scripts are in place. This greatly reduces the script maintenance cost and not only speeds up the implementation of automated tests, but also makes it possible to use non-programming testers to implement them. We should be able to implement thousands of test cases with only a few hundred scripts. The automated tests can be implemented in a way that is tool independent (and platform independent). So if we have to change the test tool (tool vendor goes bust, political pressure from parent company, or whatever) we can do so without losing any of our investment in the test cases. We would have to re-implement the supporting scripts, but that is all. Similarly, if the software under test has to be tested on different hardware platforms that are not all supported by the same test tool, we will not have to change our tests, merely the supporting scripts. The way in which tests are implemented can be tailored to suit the testers rather than the test tool, using the format and tools that the testers are most comfortable with (e.g. text editor, spreadsheet, or word processor). It is then possible to optimize the format so that new automated tests can be implemented as quickly as possible and yet in the safest way (i.e. least prone to error), avoiding many of the mistakes that can cause excessive debugging of tests. Furthermore, simple tools can be implemented to perform static analysis on the automated test definitions. While this facility is not unique to programmed scripts, it is perhaps more easily implemented on them. 3.2.5.3 Example implementations of keyword-driven scripting
This book contains two extensive examples of good implementations of the keyword-driven scripting technique. Hans Buwalda from CMC has developed a method of scripting using Action Words, which are what we call keywords. He calls the supporting scripts 'navigation scripts' (although they are not concerned with navigation to specific points in the system menu structure, rather they interpret the Action Words). This approach has enabled the users of the TestFrame' method to separate out the business-level test concerns (the business users construct test files called 'clusters' and the technical people program the scripts). This also
gives independence from any specific commercial tool, since a different navigation script, i.e. supporting script, can implement the Action Words in different tool scripting languages. This method has been very successful, and we recommend that you read Hans Buwalda's chapter, Chapter 22, which describes the method very clearly, and also Chapter 23, Iris Pinkster's case history of using Action Words. The second example is a slightly different approach to implementing the keywords, described by Graham Freeburn. The approach taken here is to use additional data tables to implement the keywords. This means that the supporting scripts arc standardized rather than being specific to an application. These standardized supporting scripts are bundled into the tool called RadSTAR. This approach also provides the benefits of separating tester concerns from technical concerns, and has been implemented using a number of different commercial test execution tools. This method is described in Chapter 24, and Chapter 25 contains a case history using the RadSTAR tool and its associated methods. If there are additional methods or tools that also implement a keyword-driven approach, we apologize for not being aware of them at the time this book was written. The authors would like to be informed of any other implementations. 3.2.5.4 Implementing keyword-driven scripting
Some tools provide support for reading data from some other source, such as a spreadsheet (usually in the form of a comma-separated file). If you have this facility, you can use it directly. If you do not, you will need to develop your own approach. This initial development only needs to be done once, and will then become part of your overall regime. You may want to develop your own approach even if your tool provides it, since you will then be independent of any tool. The overall aim is to provide the easiest possible way of entering the test input without introducing unnecessary repetition or detail. Further support of this kind can be gained by using script pre-processing to converter translate from a high-level language (4GL-like?) into the tool-specific language.
3.3 Script pre-processing Script pre-processing is a term we use to describe any of a number of different script manipulation techniques that strive to make the process ot writing and maintaining scripts easier and therefore less error prone. Preprocessing is one or more prc-compilation functions (where scripts have to be compiled before they can be executed by the test tool). Some testing tools, or rather their scripting languages, provide facilities for some types ol manipulation though it may not be called script pre-processing. There are a
number of script pre-processing functions that can benefit script writers including beautifier, static analysis, and general substitution. These are described in the following subsection. 3.3.1 Script pre-processing functions
An important aspect of any pre-processing is that it is tool supported, that is, it is more or less automated. It may be necessary for the script writer to invoke a specific tool or utility to perform a pre-processing function. Ideally, the test execution tool will be able to run pre-processing functions automatically, but at the time of writing this was rarely the case. 3.3.1.1 Beautifier
A beautifier checks the layout and format of scripts and if necessary edits them to make them conform to some standard. Having all scripts conforming to a standard layout helps make them easier to read and understand for different people. If only one person were to write and maintain a set of scripts then there is not so much advantage in using a beautifier. However, it is unlikely that any scripts used over the lifetime of most software products will be written and maintained solely by one person. In any case, a beautifier can take over the cosmetic chores, leaving script editors to concentrate on the technical accuracy of their work. For example, Figure 3.11 shows two versions of the same script segment. The first one is as a script writer might first produce it, and the second version is the result of it having been 'beautified.' This has inserted blank lines before each comment line and indented the instructions within each control construct. 3.3.1.2 Static analysis
Static analysis facilities take a more critical look at scripts or tables, checking for actual and possible scripting defects. Of course the testing tools themselves will find and report some script defects, for example a misspelled or incomplete instruction. However, they tend not to do any more than is really necessary and in any case they cannot assume any knowledge of the script semantics. A static analysis facility has as its only goal the detection of all the defects and anomalies it is able to find. For example, if Type "Fl" appeared in a script rather than the correct version Type "{Fl}", the effect would be that the characters 'F' and '!' would be entered rather than the Fl function key. A static analysis facility could highlight this as a potential problem whereas the test tool would not pick this up since the incorrect version is syntactically correct. We are not aware of any commercial tools that perform static analysis on test automation scripts. However, the most useful static analysis functions are best provided by in-house tools since these can concentrate on the defects actually made by your script writers.
While CURRENT RECORD LAST RECORD ; Invoke new client option. Type "{F2}" ; Wait for the data entry screen. Wait "Maintenance" in "-CMAINT.EXE-CMDE-Client Maintenance V2.1 Data Entry" ; Enter client surname. Type "{=.!}{Tab}" ; Enter remainder of client details. While CURRENT_FIELD LAST_FIELD Type "{=.+} {Tab}" EndWhile \ ; Confirm details OK and wait for completion. v. ..,• ^ Type "{Fl}" Wait "New client added successfully" in "-CMAINT.EXE-CMDE-Client Maintenance V2 . 1 Data Entry" EndWhile
While CURRENT_RECORD LAST RECORD ; Invoke new client option. Type "{F2}" ; Wait for the data entry screen. Wait "Maintenance" in — "-CMAINT.EXE-CMDE-Client Maintenance V2 . 1 Data Entry" ; Enter client surname. Type "{=.!}{Tab}" ; Enter remainder of client details. While CURRENT_FIELD LAST_FIELD Type "{=.+}{Tab}" EndWhile ; Confirm details OK and wait for completion. Type "{Fl}" Wait "New client added successfully" in — "-CMAINT.EXE-CMDE-Client Maintenance V2.1 Data Entry". EndWhile
Figure 3.11 The script segment at the top is as it might be produced by the scriptwriter, the one at the bottom is the same script segment having been 'beautified'.
3.3.1.3 General substitution
General substitution offers some big advantages though it is possible to go too far. The idea is to hide some of the complication and intricate detail of scripts by substituting simple but meaningful alternatives. Some scripting languages support substitutions to varying degrees and where there is such support we recommend it be used, wisely. Two main purposes for substitution are to replace cryptic character sequences with more simple and meaningful ones, and to replace long and complicated sequences with more simple and meaningful ones. For example, Figure 3.12 shows a short segment of script taken from the example in Figure 3.11 with two instructions highlighted in bold. These
use a special notation {=.1} and {=.+} to read data from a data file. These mean 'take the first field from the current record' and 'take the next field from the current record,' respectively. However, this is not an obvious interpretation and the notations could easily be confused with each other or with other similar notations. This is a good case for using a substitution. Figure 3.13 shows an improved version of our script segment. Here we have used the keyword FIRST_FIELD as a substitution for "{=.1}{Tab}" and NEXT_FIELD as a substitution for "{=.+}{Tab}". We believe these are more understandable and much less likely to be confused. An example of a long and complicated text string being substituted for a short keyword is shown in Figure 3.14. This type of substitution is particularly useful when the string appears several times throughout a script. It is
Figu keyvv ;
Wait for the data entry screen. Wait "Maintenance" in — "-CMAINT.EXE-CMDE-Client Maintenance V2.1 Data Entry"
; Wait
Wait for the data entry screen. "Maintenance" in MAINT_DE
re 3.14 An example of a long and complicated text string being substituted by a short ord.
also most useful in cases where the string itself can change between different versions of the software under test. For example, in Figure 3.14 the string contains a version number V2.1, which could well change. It would be much more efficient to change just one occurrence of it (the definition of the keyword) rather than every occurrence of its use throughout a set of scripts. 3.3.3.4 Test-specific substitution \ / The idea of being able to perform automated substitutions in scripts can be exploited further. Take a script or set of scripts that perform a test case and that have the input data embedded in the script(s). Using substitution, we can easily generate another script (or set of scripts) that implement a slightly different test case, that is, one that uses different input data. This is perhaps most practical where it is only a few key inputs that need changing from one test case to another. For example, if a test case specifies a date that is used during processing (such as in calculating an interest payment), generate another script by substituting a different date. Of course this can be done as many times as you wish. The important point to keep in mind, however, is not to maintain the generated scripts. Only ever maintain the original script and regenerate the others whenever they are required. A problem with this approach can be the verification of the new test cases. Different input values imply different expected outcomes. It may be possible to substitute the expected output values or it may be sensible to generate additional test cases that are less sensitive (i.e. perform fewer comparisons between actual and expected outcomes). This approach is not a panacea but it may be helpful in some circumstances. The idea of substituting text strings in scripts can be carried too far. Depending on how it is implemented just about anything in a script can be substituted though doing so is not generally recommended. We discuss this further in the following section. 3.3.1.5 Things to be careful of when using substitutions Don't get carried away with unnecessary substitutions. There will be some that are clearly excellent candidates for pre-processing, but it is all too easy to find yourself substituting things which are no less difficult to remember or error prone to enter than the tool equivalent. Remember that the tool recognizes only the processed version of the script. This means that all scripts need to be pre-processed before the test tool can use them. When you come to debug the script (and this will happen) by having the tool step through the script under your control one instruction at a time, the script you see is the tool version, not the more readable version. If you have adopted too many or too frivolous substitutions debugging the script may be similar to debugging the 3GL code generated by a 4GL; it will bear little resemblance to the original. Also, when you debug keep in mind the fact that the defect could be in the definition of what is substituted rather than in the original script.
We wanted to make our scripts able to cope when new fields were added to any screen, without the need to change them. The tool we had did not allow us to directly access a field by name, but it could tell us the name of the field the cursor was in. We were able to make the scripts do what we wanted by writing our own special script to search for the field we wanted. What we did was to tab around the whole screen until the cursor had returned to the place it started from. At each field, we checked its name. If we couldn't find the field, then we would back out of that test and run the next test, This meant chat all of our scripts could cope when fields were moved or were in a different order, provided they were still on the same screen. Moral: if your tool doesn't provide a facility you need, don't give up; use what the tool does provide to achieve your aim another way. Source; Herb Isonherg, 'Flexible testing systems', Dr Dobb's Journal, June 1995, pp. 88-95.
3.3,1.6 Implementing pre-processing
All of the pre-processing functions we have described can be implemented using standard text manipulation tools (providing the scripts are held in text files). Describing in detail how these could work is beyond the scope of this book but one simple approach is described below. In some cases the implementation of a script pre-processor will be similar to that of the filters described in Chapter 4. What is needed for substitutions is a substitution table that contains the definition of all of the shorthand terms we have used in our master scripts. For general definitions the substitution table should be made available to all of the scripts using the same conventions. You may have several different substitution tables, with a pre-processing pass for each relevant table. One way to implement this is to use a non-interactive editor, and a command file to drive the editor; this is your pre-processor. This command file is run immediately before the scripts are compiled. Your command file may also contain the compilation instructions, if the tool permits compilation from the command line. Alternatively, if the tool you have allows you to call other command files, you can make use of that feature. At the time of writing this is a feature we have yet to see test tools provide, but one we would certainly encourage.
Summary Scripting techniques are similar to programming techniques. Good programming produces software that is easy to maintain. Good scripting produces tcstware that is easy to maintain. The scripts need to be
engineered, and the scripts are written in scripting languages which are programming languages. Scripts contain data and instructions for the test tool, including synchronization, comparison information, where to read data from and where to store data, and control information, such as 'if statements or loops. The simpler the script is, the less effort it will take to create it, but the more effort it will take to maintain it. So to minimize maintenance effort requires investing effort in script creation. A good set of scripts will be well structured, rather than simply being one script per test. A good script will be annotated with comments, will perform a single task, will be well structured, understandable, documented, and likely to be reused. The way in which test cases are designed has an impact on the test scripts, but the structure of the scripts may be different from the structure of the tests. Vendors sometimes describe the raw tool scripts as being 'easy to read' or 'self documenting.' What is important is that the script can be understood (not just the words able to be read) and that the documentation is meaningful. We recommend that the documentation for each script is placed in the header of the script. This should include the name of the script, the author, the date it was created/edited, the purpose of the script, any parameters it requires or produces, any pre- and postconditions before it can be run, any other information that would help someone who is maintaining the script, and the history of all amendments made to the script. We considered five scripting techniques. Each technique has its strengths and weaknesses, and is best used in particular situations. Table 3.3 shows a summary of the different scripting techniques. Table 3.3 Summary of scripting techniques.
Structured or unstructured?
Script contains
Script Approach intelligence
Test cases defined by
Ifs and loops
Structured or unstructured
KeywordStructured driven
Structured Variables
Variables and keywords
Ifs, loops, and Script and Prescriptive data reading Ifs, loops, data reading, and keyword interpreter
data Descriptive
A linear script is what a recording produces. It is a quick way to get started and doesn't require programming knowledge to produce it. A linear script is useful for one-off repetitive actions, conversions, editing, or demonstrations. Linear scripts are not useful for long-term maintainable automation. They are inefficient, expensive to change and very vulnerable to minor software changes, and 'fragile' - easily broken by unexpected events occurring in a test. Test inputs and expected outcomes are 'hardwired' into the script. Structured scripting, like structured programming, uses control structures. 'If statements increase robustness as they allow the test to do different things when something happens. Loops allow a script to perform many repeated actions. Calling other scripts helps to make scripts more modular. Structured scripts still contain 'hard-wired' test information. The script is now more complex but it is also more powerful. Shared scripts are reused in more than one test case. This enables common actions to be in only one place rather than in every script. This means that maintenance effort is significantly reduced. It is worth making a shared script more robust because it will be used more often. Shared scripts can be application specific or application independent. Shared scripts still contain 'hard-wired' test information and tend to be specific to one part of the software under test, but there are more scripts to keep track of. In order to benefit from shared scripts, it is important to be disciplined and have a good configuration management system. Data-driven scripts store the test inputs and expected outcomes in a data file that is then read by a more general control script. This enables new tests to be added much more easily, since it is only the data table that is updated. A more sophisticated data-driven approach may have columns in the data file relating to logical entities in the software being tested. Significant benefits can be gained in test automation using data-driven scripts. New tests can be added easily, and many more tests of a similar nature can be performed, and the script does not need to be changed when new tests are added. In addition, testers can concentrate on the tests without being distracted by the technical programming issues of scripting. The disadvantages of this approach are that the initial set-up does take a fair amount of effort, technical programmers are needed to implement the scripts, and it must be well managed. The scripts and the data tables need to be consistent. The keyword-driven scripting technique takes the generalization into the realm of the application as well as the data. The keywords are stored in the data table, representing application functions. This method is descriptive rather than prescriptive; we say what the test should do rather than having to prescribe the detail that was necessary with the other scripting techniques. This additional level of sophistication also requires an additional implementation level, but now it actually gets simpler rather than more complex. The control scripts and the supporting scripts that interpret the keywords are now very generic, so there are fewer of them, and they are
worth making very robust. All of the information about what to test is now contained in the data table, so the separation of test information from implementation is the greatest in this technique. Two implementations of the keyword-driven technique arc described in Chapters 22-25. Pre-processing can be applied to any scripts. This may include a beauti-fier, static analysis, general substitution, or test-specific substitutions
Automated comparison
4.1 Verification, comparison, and automation 4.1.1 Verification by comparison
Test verification is the process of checking whether or not the software has produced the correct outcome. This is achieved by performing one or more comparisons between an actual outcome of a test and the expected outcome of that test (i.e. the outcome when the software is performing correctly). Some tests require only a single comparison to verify their outcome while other tests may require several comparisons. For example, a test case that has entered new information into a database may require at least two comparisons, one to check that the information is displayed on the screen correctly and the other to check that the information is written to the database successfully. There are several important decisions to be made when planning automated comparisons that have a significant impact on both the effectiveness and efficiency of your automated testing. The information you decide to compare and how much of it you compare affects the test cases' ability to detect defects, the implementation costs, and the maintenance costs. These are discussed in this section. Section 4.2 discusses what comparators can and cannot do. The two key types of comparison, dynamic and post-execution, are described in Sections 4.3 and 4.4. Simple and complex comparisons are described in Sections 4.5 and 4.6, and Section 4.7 discusses test sensitivity (to changes in the software being tested). Section 4.8 describes different types of outcome that can be compared: disk-based, screen-based, and others. Section 4.9 describes a technique of using what we call filters for constructing comparisons that are powerful and flexible, yet relatively simple to implement. We conclude the chapter with some guidelines for effective and efficient automated comparison.
4.1.2 Planned versus ad hoc comparisons
During manual testing it is possible for the human tester simply to look at what the software is producing and decide whether or not those outputs are correct based on an understanding of what the software should produce. In this case the comparison is between the actual outcome (for example, on the screen) and the expected outcome held in the tester's head (or the expected outcome determined by the tester from his or her understanding). Of course, what the tester understands may not always be correct but it is difficult to check this when verification is done so informally. (Systems that are developed using Rapid Application Development (RAD) techniques often have a high degree of informal verification, particularly for newly developed functionality.) At the other end of the scale a planned and formal approach to verification would involve a comparison of specific outcomes carefully chosen to insure that the objectives of the test case are met. These would be compared against rigorously predicted expected outcomes. Once again, though, it cannot be guaranteed that the tester will always be able to predict the exact outcomes. However, this approach does make it easier to have other people check the predicted outcomes to help insure that they are correct. The same is true for automated testing. It is better to have the verification details of each test case carefully thought out in advance so the automator can concentrate on how best to implement the automation without having to worry about the quality of the tests themselves. This is particularly important where the test case designer and the test automator are different people and the automator does not have the same business knowledge as the test case designer. It is possible to automate some specific comparisons, but it is not possible to automate a 'check the output is right' instruction! Designing test cases in advance of automation creates a better opportunity to achieve a good balance between the many issues that affect the quality of both the tests and the automation itself. Unplanned automation can be beneficial, but planned automation is likely to be much more so. 4.1.3 Predicting outcomes versus verifying actual outcomes
When automating test cases, the expected outcomes have either to be prepared in advance or generated by capturing the actual outcomes of a test run. In the latter case the captured outcomes must be verified manually and saved as the expected outcomes for further runs of the automated tests. This is called reference testing. Which approach is the best in any particular situation depends on the following considerations: 1. The magnitude of the expected result. If the expected outcome is a single number or a short text string (such as an error message) then it can be prepared in advance quite easily. However, if it is a multi-page report containing much detailed information then it may be easier to manually verify the result of the first test run.
2. Whether or not the result can be predicted. There are situations in which it is not possible to predict an expected result such as when system tests are performed on 'live' data (e.g. stock market share prices), the details of which cannot be known in advance. This is more difficult to automate, though not impossible. 3. Availability of the software under test. The first set of actual results cannot be generated until the software is available so if we wait until then before implementing the automated tests, there may not be suffi cient time left to automate as many of the test cases as we would like. Of course it will be possible to do some of the work in any case, partic ularly if the scripts are to be written manually (rather than recorded). 4. Quality of verification. Generally speaking, it is better to predict test outcomes in advance than it is to verify the first set of actual outcomes. This is because human beings tend to fall foul of the cognitive disso nance barrier; that is, we will see what we want to see rather than what is actually there. Thus, it is more likely that we will miss defects when verifying test outcomes than when planning them in advance. 4.1.4 Why compare automatically?
Comparison is arguably the most automatable task in software testing, and is often the most beneficial to automate. Comparing extensive lists of numbers, screen outputs, or data of any kind is not something that human testers do very well. It is easy to make a mistake, and we find it very boring, because it is a repetitive and detailed task. This makes it ideal for a computer to do (which will never become bored!). In fact, it is a good idea to use comparators to automate the comparison of the outcome of tests performed manually. This may be the best place to introduce tool support into the testing process. Automated execution can and will generate a lot of outcomes. Usually these outcomes will need to be verified in some way, though not all tests will need detailed comparison of their outcomes. Volume tests, for example, may only need to check that the software is still running.
A client had automated test input and execution, but not the comparison of test outcomes. When we visited, itaff pointed out the three-foot (one-meter) high pile of printout in the corner, which were the test outputs that had been painstakingly checked by the festers, Ihis manual verification took three or four days, and was also somewhat prior prone. If if had been automated, it could probably have been completed in an hour or two, _________________________________ _ .................................. _ ___________
Without automated comparison of outcomes, we will not have automated testing, even if we have automated execution. However, in some situations this is a very sensible thing to do. For example, if inputs are very detailed and tortuous, automating them will save a lot of time and errors, even if the output of the test is verified manually. (See Paul Herzlich's case study in Chapter 16.) If the correctness of a screen output is easy to see at a glance and the automation of that comparison is difficult, then automated execution and manual verification may be a good solution.
4.1.5 What should be compared? Normally we think of checking what is output to the screen as each test case is performed, and sometimes this is all we think of checking. Of course, screen output is something that should be checked, but it may not be all that should be checked. In addition to the visible output to the user, the software execution may have added, altered, or deleted data in a file or database. In order to verify that the test worked correctly, we may need to check that the correct changes occurred in the database. It is possible for a program to update the screen display but erroneously omit to save those updates in the database. If this were the situation and we only.checked the screen display then our test case would not reveal this defect. There arc many other types of output that may need to be checked; for example, data sent to a printer, email messages, messages sent across networks to other machines and processes, signals sent to hardware devices, etc. It is common to find that manual testing does not always verify all of these effects either. However, because manual testing is known to be ad hoc and incomplete, this aspect is often just one more area of incompleteness. If tests are to be automated, we can take the opportunity to improve the quality of the testing by checking more things, particularly if checking can be automated. 4.1.6 Limitations of automated comparison
When testing is performed manually, the tester is likely to undertake many more individual checks on the validity of the outcome of tests than have been prescribed. Many of these may be done subconsciously, but even so they may highlight problems that even the most well-planned set of specific comparisons will miss. However, automated comparisons inevitably stick to exactly the same checks every time and these are likely to be a small subset of the comparisons actually performed by a human tester. Of course, it is possible for an automated test to check 'everything,' but it is rarely practical or desirable. Automated comparisons can only ever be as good as the expected outcomes with which the actual outcomes are compared. If a defect exists in an expected outcome, automated comparison will hide, not highlight, the same defect in the actual outcome.
Furthermore, manual regression testing done manually is more flexible. Testers can vary comparisons undertaken each time the tests are performed based on their understanding of the changes that have been made. Automated testing is not so flexible. Once automated, the same comparisons are performed in precisely the same way every time. If any changes are required the test cases have to be updated, a maintenance cost that may not be acceptable. Comparison is the means to verification and much of it can be automated. Although automation can only compare the actual outcome to an expected outcome, which is not necessarily the correct outcome, it is much faster and far more reliable than manual comparison of those things that are compared.
4.2 What do comparators do? An automated comparison tool, normally referred to as a 'comparator,' is a computer program that detects differences between two sets of data. For test automation this data is usually the outcome of a test run and the expected outcome. The data may be displayed on a screen or held in files or databases, and can be in a variety of formats including standard text files. Where a comparator facility is built into a test execution tool the data is more likely to be screen images. 4.2.1 What can be compared?
The data that can be compared will depend on the capabilities of the comparator tool. Some commercial comparators have extensive capabilities for comparing several different data formats. With the simplest comparators you can compare only standard text files but with more sophisticated comparators you can compare more complex and specialized forms of data, including graphical formats and the content of databases. 4.2.2 What comparators can tell you
All comparators basically tell you whether or not the two sets of compared data are the same but many will also highlight the individual differences in some way. There is a variety of ways of highlighting differences across different comparators, and what is output by any one comparator can vary enormously, depending on what has been asked for. During execution of a series of automated test cases, we only need to know whether or not there are any differences between the actual and expected data. This will enable the test execution automation tool, or us, to determine whether or not each test case passed. After a test case has failed, we will have to investigate the cause of the failure. Now we need additional information from our comparator. It is often helpful to be told how many differences there are, where they occur,
and exactly what the differences are. Ideally, this information will have been reported at the time each comparison was performed. (Examples of comparator outputs arc given in Section 4.8.) The more advanced comparators provide facilities to help you browse the differences; for example, an interactive capability that allows you to see portions of two compared files side by side (or one above the other). In this case the differences may be highlighted in some way, such as with bold type or a different color. Another variation displays only one file at a time but allows you to switch between the two files in rapid succession. Where graphical images are being compared, some comparator tools are able to highlight the differences using various graphical manipulation techniques. For example, where two bitmap images are being compared it is possible to produce a third image that is the result of subtracting one image from the other, leaving the third image blank where the first two are identical. These facilities make the task of analyzing differences much easier and quicker. Some word processors provide useful facilities to compare two versions of text documents. While they probably do not make the best comparators for test automation purposes they may prove useful where differences in textual outputs occur, particularly if the people undertaking the analysis are more familiar with a word processor than a comparison tool. Other information output by dedicated comparator tools may include the time and date the comparison was performed, how long it took, the version of the comparator tool used, etc. This is mostly used for auditing purposes to show that the tests were performed correctly.
4.2.3 What comparators cannot tell you A comparator cannot tell you if a test has passed or failed (although that is how they are used). A comparator can only tell you if there are differences. We often infer a 'test passed' result when a comparison finds no unexpected differences and a 'test failed' result when it does. However, this is not necessarily correct. If the expected outcome is actually incorrect, then we will be inclined to say 'test passed' when the software being tested fails in exactly the same way! It can be very difficult to insure that the golden version, containing the stored expected outcomes, is correct in every detail, and it may not be worth the effort. A golden version that is slightly tarnished can still save a lot of time if it is used within its limitations. It is important to remember that any golden version is not guaranteed to be perfect anyway since human beings are prone to make errors in either constructing it or verifying it the first time.
Dynamic comparison
4.3.1 What it is
Dynamic comparison is the comparison that is performed while a test case is executing. Test execution tools normally include comparator features that are specifically designed for dynamic comparison. Dynamic comparison is perhaps the most popular because it is much better supported by commercial test execution tools, particularly those with capture/replay facilities. Dynamic comparison is best used to check things as they appear on the screen in much the same way as a human tester would do. (Comparing other outputs after the test case has ended is known as post-execution comparison. This is described in Section 4.4.) This means that outputs to the screen during the running of a test case can be checked even if they are overwritten later by further outputs from the same test case. Outputs that are not visible on the screen can also be compared dynamically, such as GUI attributes. 4.3.2 Tool support and implementation
As we saw in Chapter 2, the dynamic comparison instructions must be inserted into the test script. These instructions tell the tool what is to be compared when, and what it is to be compared against. Comparison instructions do not have to be inserted into a script manually. With most tools it is possible to suspend the recording of a test case so that the tool can be shown what to check at that point, saving the current version as the expected outcome. In either case, the tool can be instructed to capture a particular part of a screen or window (or indeed the whole screen, though generally this is not recommended), and save the current instance of it as the expected result. The tool will automatically add instructions to the script that will, whenever the script is replayed, cause the tool to capture the same output and compare it with what has been saved as the expected outcome. Where tools do not allow checks to be added while a script is being recorded, they may allow them to be inserted while the script is being replayed. The test is replayed in 'slow motion,' i.e. one step at a time. When a verification point is reached, the screen output is first verified as correct by the tester, and then if it is acceptable, the tool is instructed to capture the relevant output as the golden version. This means that two passes are necessary, the first to record the inputs, and the second to record the dynamic comparison instructions. For tools that do not support either of these approaches it will be necessary for the test automator to edit the script. This will, of course, require some programming knowledge, since the tool script is written in a programming language. This is why we advise against using simple recording techniques (with or without dynamic comparison) for long-term test automation.
4.3.3 Test case intelligence
Dynamic comparison can be used to help program some intelligence into a test case, to make it act differently depending on the output as it occurs. For example, if an unexpected output occurs it may suggest that the test script has become out of step with the software under test, so the test case can be aborted rather than allowed to continue. Letting test cases continue when the expected outcome has not been achieved can be wasteful. Once a test script is out of step with the software, any further actions are unlikely to replicate the right conditions and may even corrupt data that is to be used by other test cases. Adding intelligence to the test scripts in this way can also help to make the scripts more resilient. For example, if the software under test performs an action that cannot always be guaranteed to work first time (such as logging on to a remote machine over a busy network) then the script can be programmed to retry the action a number of times. 4.3.4 Increased complexity, higher maintenance costs
Dynamic comparison appears at first to provide compelling reasons for using it as much as possible, but th.ere is a downside. Because dynamic comparison involves embedding further commands or instructions into the test scripts, it makes the test scripts more complex. So test cases that use many dynamic comparisons take more effort to create, are more difficult to write correctly (more errors arc likely so more script debugging will be necessary), and will incur a higher maintenance cost. A lot of seemingly trivial changes to the screen output can result in many unimportant differences being highlighted by dynamic comparisons. Although most test execution tools make it easy to update the expected outcomes in such situations, if a lot of comparisons are affected the updates can take considerable time and effort, and this is not the most interesting of work.
Post-execution comparison
4.4.1 What it is Post-execution comparison is the comparison that is performed after a test case has run. It is mostly used to compare outputs other than those that have been sent to the screen, such as files that have been created and the updated content of a database. 4.4.2 Tool support
Test execution tools do not normally include support for this type of comparison directly; rather, a separate tool or tools are used. However, it is possible to design test cases such that other outcomes are displayed on the
screen to enable the dynamic comparison facilities of the test execution tool to be used. However, if the information to be compared after the test case has completed amounts to more than a few screens-full, this approach is not very satisfactory.
A client was evaluating a test execution too! to see how well it supported the testing process. The system under test was a mainframe application accessed via terminal emulation software runninq on PCs, Most of the test verification involved checking large output files at the end of each test case. The tool vendor (presumably to insure fhe sale) was putting quite a lot of effort into writing scripts that •displayed the output files on ihe Pr one page at a lime where the dynamic comparison facilities of the tool were then used to compare each page with the expected result. Apart from being slow, the comparison was limited to a record size shorter than was used in the files and so could not be as accurate as was reguired. We recommended that a more sensible approach would be to do post-execution companson with a standard file comparator and using filters, and not try to use the test execution tool at all for the comparison of the file contents. This would result in an order of magnitude performance improvement in running the comparisons and would also achieve more accurate comparisons.
Because test execution tools generally do not support post-execution comparison as well as dynamic comparison, post-execution comparison often seems to be more work to automate. At the time of writing, there were few commercial post-execution comparison tools on the market. Sometimes these tools are sold together with a test execution tool and may not be available separately. Where an appropriate tool does exist it may be well worth buying it. However, there is much that can be done using in-house tools and utilities to provide a comprehensive and yet easy to use set of comparison tools. One approach to this that has proved successful is described in detail in Section 4.9. 4.4.3 Order and structure of comparisons
Unlike dynamic comparison, where outputs have to be compared as they occur, with post-execution comparison it is possible to be more selective over the order and extent of comparisons performed. Rather than comparing all of the selected outcomes for any one test case we may prefer to divide them into two or more groups of comparisons such that we compare the second and subsequent groups only if the first group was successful. For example, general results may be verified first, since if they have failed, there is no point in spending any time on detailed verification of those results. (The defects should be fixed first so that the general tests pass before the detailed results are checked.)
It may seem a strange idea to try to save time in automated checking because if a tool does it, it doesn't matter how long it takes. However, when a large number of automated test cases are in place or there are a large number of time-consuming complex comparisons, you may run out of time to run and verify all of the tests. It is better to plan ways to be selective at the start even if you initially always run all test cases and comparisons.
During a conference presentation we had said that one difference between manual and automated testing is that with automated testing you can afford to run more regression tests as a final check on a system. Afterwards one delegate totd us that his company's mainframe-based automated regression lest suite took two weeks to run so whenever they needed to run a regression lest park overnight they still had a hard job selecting which test cases to tun.
4.4.4 Active and passive post-execution comparison Post-execution comparison can be done either actively or passively. If we simply look at whatever happens to be available after the test case has been executed, this is a passive approach. In our example test case of Chapter 2 the only thing available to us at the end is the edited document. All the information that was output to the screen has gone and so cannot be looked at. We could have used dynamic comparison to verify the screen outputs but we could also use active post-execution comparison. If we intentionally save particular results that we are interested in during a test case, for the express purpose of comparing them afterwards, this is an active approach to post-execution comparison. In our example test case we could instruct the tool to capture portions of the screen output at particular times (e.g. error messages) and save them in one or more files. In this case the outputs we would capture for post-execution comparison would be the same as those we would choose to use for dynamic comparison. This active approach to post-execution comparison offers only subtle benefits over dynamic comparison that may be valuable in some situations but not in others. The benefits are: 1. The actual outputs are saved. A more detailed record of the outcome of test cases will be retained, giving potentially useful information in the event of test case failure and perhaps to archive for future audits. Where a complex comparison is performed the actual and expected outcomes may differ in expected ways (so they would be deemed to match), so saving the actual outcome could be important. However, where a simple comparison is performed and no differences exist, the exDected and actual outcomes are identical.
2. Comparison can be done offline. Comparison can be processing inten sive and take considerable elapsed time. It may be useful to be able to run comparisons after all the test cases have been executed. The com parisons could be performed on a different machine from that used to execute the test cases, particularly useful where machine resources for testing are available only for a limited time. 3. Different comparators can be used. The sophistication of dynamic com parison is usually limited to the capabilities of the test tool. Post-execution comparison permits a much wider range of tools and techniques for performing more complex comparisons. 4. Other outputs can be saved. Not all captured information has to be compared. It can be useful to capture additional outcomes that are used only in the event of test case failure as an aid to analyzing the cause of the failure. Note that 'simpler scripts' is not listed as a benefit. This is because the instructions required for dynamic comparison are being replaced by similar instructions to capture and save specific outputs. These are unlikely to be much different and will still require 'programming in' to the test script. Although active post-execution comparison can be used in place of dynamic comparison, it is rarely done. Verifying outputs as they occur during a test case run is generally superior to verifying them at the end of a test case run since the test execution tool can be instructed to act differently depending on the results. For example, the script could abort a test case as soon as something goes wrong. 4.4.5 Implementing post-execution comparison 4.4.5.1 Integration of test execution and post-execution comparison
Implementing post-execution comparison is not as straightforward as it may at first appear. When an automated test case is performed we would like to be told whether or not it passed without us having to take any further action. However, when a test case requires one or more post-execution comparisons, it is usually a different tool that performs it. In this situation the test execution tool may not run the post-execution comparator(s) of its own accord so we will have to run the comparator(s) ourselves. Figure 4.1 shows this situation in terms of the manual and automated tasks necessary to complete a set of 'automated' test cases. Figure 4.1 does not look much like efficient automated testing and indeed it is not. It would be nice if the test execution tool were responsible for running the comparator, but unless we tell it to do so, and tell it how to do so, it is not. To make the test execution tool perform the post-execution comparisons we will have to specifically add the necessary instructions to the end of the test script. This can amount to a significant amount of work, particularly if there are a good number of separate comparisons to be performed.
Figure 4.1 When post-execution comparison is not closely integrated with the test execution tool we have to do some of the work ourselves. The diagram illustrates the sequence of tasks from left to right required for post-execution comparison, showing the manual tasks above the line and those that are performed by a tool below the line.
Across a number of test cases we can reduce the amount of work by using shared scripts (see Chapter 3 for a description of scripting techniques). By carefully planning where the actual and expected outcomes will be stored such that they can be located easily and in a consistent manner across many test cases, the additional instructions in each test script can be further simplified. (See Chapter 5 for a discussion of these issues.) Even when we have added the instructions to perform the post-execution comparison we may not have solved the whole problem. Figure 4.2 shows why. The test execution tool will probably be able to tell us that the test case ran successfully (or not) but it may not tell us anything about the results of the post-execution comparisons. Assessing the results of the post-execution comparison is then a manual task. We have to look in two places to determine the final status of the test case run: the execution tool's log or summary report and the output from the comparator tool(s). We would like to be given one all-encompassing status for each test case - in other words, whether or not it was successful. However, enhancing a test
Figure 4.2 When post-execution comparison is invoked by the test execution tool we may still be left with the job of looking at the results of the test execution and, separately, the results of the post-execution comparison.
script so that it runs the post-execution comparisons is one thing; enhancing it so that it understands the results of the comparisons and returns one overall test case status is another. This latter task may not be trivial but there is much to be gained by solving the problem in a way that all test cases can benefit from the solution. 4.4.5.2 Four ways to integrate execution and post-execution comparison In an ideal world the interface between the test execution tool and the post-execution comparators would be seamless, but there is usually a gap that we have to fill ourselves. There are a variety of ways to overcome the problems of running the comparisons and assessing the final test case result. We shall now consider a few of them. The models in Figure 4.3 depict four approaches to the implementation of post-execution comparison. These are not the only alternatives but are perhaps the most common and are the ones which we will now consider. Three of these show a 'harness' around the comparator. This is meant to imply something that is 'homegrown', not a part of any commercial test tool. What this does and the reasons for it will be made clearer later on but for now it is best considered as a means of filling in a gap left by the commercial testing tools. (a)
Figure 4.3 Four models of possible alternative implementations of post-execution comparison: (a) a separate harness (usually home-grown) runs the comparator after the test tool has executed the test cases; (b) the test tool runs the comparator; (c) the execution tool is used to provide a common interface to both the test execution and comparison processes; and (d) the harness provides a common interface to the two processes.
The first model uses the homegrown harness around the comparator but remains separate from the test execution tool and process. With this approach it is necessary for a tester to invoke the comparison process after the test execution process has completed (usually after all the test cases have been executed). While this eliminates the need for a human tester to repeatedly invoke the comparator, it is still a long way from an automated process. However, it is perhaps a good solution where there are benefits in running the post-execution comparison process at a completely separate time or on a different machine. The second model is perhaps the best one in that both the execution and comparison processes are handled by the test tool, but in our experience this is more of a myth than a reality at the time of writing. In practice the post-execution comparison tool is not very well integrated with the execution tool, if at all. For a seamless integration it becomes necessary to build a harness around the comparator, which brings us on to the third model. The third model provides a common interface to both the execution and comparison processes but relies on a harness to interact with the comparator. The fourth model uses the test harness to provide a common interface by driving the testing tool itself. This has been the most common approach by successful large automation projeqts that we have seen. However, we believe that this may become less common as the commercial testing tools are now beginning to provide better overall support. In each case the harness may be implemented either as a software program in its own right, as one or more command files (job files, batch files, shell scripts - whatever the terminology is for the environment you use), as shared test tool scripts, or a combination of two or more of these. Note that where some or all of the harness is implemented by tool scripts, in our view it does not mean that the tool is providing the necessary support. The fact that the test automator has to implement scripts to do a task means that the tool itself does not already provide appropriate support.
Simple comparison
Simple comparison (sometimes called dumb comparison) looks for an identical match between the actual and expected outcomes. Any and every difference will be found. Since a lot of testing can be automated using only simple comparisons, the benefits of simple comparisons should not be ignored. Because they are simple it is easy to specify them correctly so fewer mistakes arc likely to be made, and it is easier for other people to understand exactly what is, and what is not, being compared. Usually much less work is involved in implementing and maintaining simple comparisons (compared with complex comparisons, described in Section 4.6). There will be tests that have outcomes that can legitimately differ each time the test case is run. Simple comparison will cause these test cases to fail even though the differences can be safely ignored. If only a few test
cases are prone to this problem then we can probably live with it. However, if many test cases are affected, the cost of having to trawl through each highlighted difference time and again just to confirm that they can be ignored can seriously impact the benefits of automation. To avoid, or at least reduce, this cost we need a way of comparing outcomes that allows us to specify differences that are to be ignored. Fortunately this exists, and perhaps not surprisingly, we call it complex comparison.
4.6 Complex comparison 4.6.1 Why are complex comparisons needed?
Complex comparison (also known as intelligent comparison) enables us to compare actual and expected outcomes with known differences between them. A complex comparison will ignore certain types of difference (usually those that we expect to see or that are not important to us) and highlight others, providing we specify the comparison requirements correctly. Perhaps the most common complex comparisons ignore dates and times that are usually expected to be different. Some commercial comparison tools have built into them knowledge of several different standard date and time formats which you can choose to enable or disable as your comparison requirements demand. Here are a few more examples of where complex comparisons are required: • different unique identity code or number generated each time; • output in a different order (new version of the software may sort on a different key); • different values within an acceptable range (e.g. temperature sensing); • different text formats (e.g. font, color, size).
A client organization harl formed a spparate fpsl automation team within a test department to automate system tests designed by the manual testers. The manual system testers by and large had a business background whereas the automation team had a technical background. Test automation was not perceived as particularly successful and it turned out that one of the ieasons for this was that the manual system testers disliked having to confirm that many of the differences found by the automated tests were simply different dates that were not otinterpst Unfortunately, the automated testers did not realize that the system testers did not n?ed or want to verify fhese differences, and the system testers did nol realize that it was possible to make the comparison tool ignore such differences. The system testers never asked for an improved comparison process, and the test automators never thought to offer it.
4.6.2 Simple masking
Complex comparisons ignore specific differences by excluding from the comparison those parts of an output that are expected to differ. This is achieved in a variety of ways but most of them come down to specifying a field location or a particular pattern of characters. For example, the sales invoice shown in Figure 4.4 contains an invoice number and two dates that are expected to differ every time the test case is run. A simple approach to masking involves ignoring complete records. In our invoice example we could make the comparator ignore the first two lines and the eleventh line of the invoice. While this would work for this particular output it would not work for other invoice outputs that contained a different number of items, causing the Payment due date to appear on a different line. Of course we could give the comparator a different set of instructions for other invoice outputs but then this involves us in a lot more work. What we really want is one set of comparator instructions that will work for all invoice outputs. One way to do this would be to ignore any line starting with Payment due. A problem with this simple approach to masking is the fact that we are ignoring the whole record. In our example this works fine but it is unlikely to be acceptable in all cases. For example, if the Payment due statement included the total cost (Payment of $5.50 due by 09-Jun-98) we may wish to verify that the total is correct. Ignoring the whole line will preclude us from doing so. An alternative approach is to specify the fields that are to be ignored. In our example we would instruct the comparator to ignore characters 19-26 on line 1, 7-15 on line 2, and 16-24 on line 11. The way in which these are specified will depend on the comparator tool used but may be something like the following: IGNORE(1,19:26) IGNORE(2,7:15) IGNORE(11,16:24)
While this does mean we will be comparing the remaining parts of the lines, this approach does not overcome the problem of having to specify different
instructions for different invoices. Not only could the Payment due statement appear on a different line but if it includes the total cost the date field could be positioned differently depending on the cost. For example: Payment of $5.50 due by 09-Jun-98 Payment of $15.50 due by 09-Jun-98 Payment of $115.50 due by 09-Jun-98 4.6.3 Search technique for masking Both of these problems can be overcome by using a search technique. Rather than specifying a particular location, the idea is to specify a string of characters that it is known will appear adjacent to the field to be ignored. The following would work for our invoice example: IGNORE_AFTER("Invoice No. IGNORE_AFTER("Date:
",9)
IGNORE_AFTER("due by
Our IGNORE_AFTER function tells the comparator to ignore a specified number of characters immediately following the specified string. This approach is more flexible than those we have already described because it will work for different invoices and in some cases will reduce the number of instructions we have to give. Where there are a number of similar fields to be ignored, it may be possible to use just a single instruction. For example, if the Payment due statement appeared as Payment due by date: 9-Jun-98 the same instruction could mask both dates if either the search were case insensitive or we specified IGNORE_AFTER( "ate: ", 9). Using this search technique does help us to specify some reasonably complex criteria but is not sufficient for all cases. For some outputs, it is not always possible to specify an adjacent string either because there is not one, or there are many of them. Consider the version of our invoice shown in Figure 4.5. This has an additional Stock Id, which always comprises four digits followed by two upper-case letters but we shall say the actual values will be different every time the test cases are run. None of the approaches we have
described so far will handle this very well since they will all require a specific set of comparison instructions for each different invoice output. 4.6.4 Search technique using regular expressions
This problem is best handled by a more sophisticated search technique that looks for the fields themselves, rather than something adjacent. This technique uses a description of the fields to be ignored, called a regular expression or pattern. Regular expressions (sometimes abbreviated to 'regexp') describe a pattern of characters by treating particular characters in a special way. These special characters are known as metacharacters or wildcard characters. For example, a period character '.' is taken to mean any character and the question mark '?' is used to indicate an optional character. Different implementations of regular expressions sometimes use different metacharacters or they have different meanings; however, any commercial comparator that implements any form of regular expressions will of course document their implementation. A full description of regular expressions can be found in Friedl (1997). In our invoice example we could use the regular expression [0-9]{4}[A-Z]{2} to specify each of the Stock Id numbers. Regular expressions often look rather complicated but they are surprisingly easy to understand once you understand the basic syntax. In our example [0-9] means any one of the digit characters 0 to 9 inclusive. {4} means match exactly four of the immediately previous characters (or character class, as in this case). So together [0-9] {4} means match a string of any four digits. Similarly, [A-Z] {2} means match a string of any two upper-case letters. Put the two together and we have a description of our Stock Id. The regular expression does not have to be limited to the field to be ignored. In fact, it is often better to include in the expression a few literal characters that will appear adjacent to the fields to help insure that only the target fields arc matched. For example, we could include a space character at the start and end of our regular expression:' [ 0-9 ] {4} [A-z ] {2} '. 4.6.5 Implementing complex comparisons
There tends to be an assumption that the comparison of a test output has to be a single comparison. However, there is no rule that requires any comparison to be performed in only one pass. Using multiple passes gives you the opportunity to compare one aspect at a time. This approach is described in Section 4.9. A commercial comparator may not be as good at performing complex comparisons as it is at performing simple comparisons. (Test tools are not immune from defects, and defects like to congregate in complex areas of software!) The way in which commercial comparator tools implement the masking does vary. Some literally remove the masked fields before performing the
comparison (this is done on a temporary copy of the outcomes rather than your originals). Others replace the field with some standard character to indicate that something has been ignored at that place. This works all right but can make failure analysis a little awkward when differences are highlighted, because the differences are shown using the edited version rather than your original and this can look quite different. Being able easily to relate any differences to the original content is important as it is both annoying and time wasting not to be able to locate the place quickly.
4.7 Test sensitivity 4.7.1 Sensitive and robust tests
At some point we have to decide what information needs to be compared in order to verify the outcome of each test case. How much should we compare and how often should we compare something? Should we try to compare as much as possible as often as possible, or take the opposite view and compare only a minimum right at the end of the test case? We call this the 'sensitivity' of the test (technically, it is the sensitivity of the comparisons). If we compare as much information as possible, for example, comparing the whole screen after each step in a test case, then more or less any change in the output to the screen will cause a mismatch and the test case will fail. This is known as a sensitive test case. However, if we compare only a minimum of information, for example, comparing only the last message output to the screen at the end of a test case, then only if this message differs will a mismatch occur. Any other changes in the output to the screen will not cause the test case to fail. This is known as a robust test case. When using dynamic comparison we have also to decide how often to perform a comparison during the test case. If we compare the outcome after every keystroke, we may be able to detect the instant something is not as expected, but our test cases are likely to take a very long time to complete and cause us a lot of difficulty in updating the expected outcomes when the software under test changes. On the other hand, if we only compare an occasional outcome, it may take us a long time to find out what went wrong when the test case fails. Test sensitivity is affected not only by the amount of information compared but also by the way in which it is compared. For example, if a comparison ignores a date field in an output report file, this makes for a more robust comparison than if it looked for a particular pattern such as mm/dd/yyyy. Similarly, comparisons that compare only content and not the position of screen messages are more robust than comparisons that insist on the message appearing in exactly the same place every time. The difference is in the complexity of the comparison, which was discussed in Sections 4.5 and 4.6.
4.7.2 Trade-offs between sensitive and robust tests
Making the right choices is important since if we compare inappropriate or insufficient outcomes then the value of the test case will be reduced, if not lost altogether. If we compare too much information the cost of implementing and maintaining each automated test case may overwhelm the benefits it can bring. Figure 4.6 highlights a number of different effects test case sensitivity can have. The diagram should not be taken too literally, as it is meant only to highlight possible differences between robust and sensitive tests. The more sensitive a test case^he more likely it will need some updating when the software under test changes. This may be a simple matter of updating the expected outcomes for the test case but there is a difference between doing this for one test case and doing it for 100 test cases (about 100 times as much work?). Naturally, the more comparisons there are to perform, the more time it will take to prescribe them all correctly. Making it easy to implement both dynamic and post-execution comparisons can help reduce the implementation time and reduce the number of implementation errors made. Similarly, the more comparisons there are, the more work will be required to maintain the tests. Sensitive tests take more effort. Many defects do not give themselves up lightly so we have to be on our guard all the time when testing, looking out for the unexpected. This is easier to do when we are testing manually than when we are implementing automated tests. When we implement a robust test we are effectively assuming where a defect will and will not show itself. The more robust our test cases, the more chance there is of a defect escaping our attention. The more data there is available at the end of a failed test case, the easier it will be to analyze and debug. For example, if we know only that a post-execution comparison used to verify a new database entry failed,
Robust tests
Sensitive tests Susceptibility to changes
Implementation effort Miss defects Failure analysis effort Storage space
Figure 4.6 Subjective comparison of the differences between robust and sensitive test cases.
we can only guess why it failed until we investigate it further, possibly by re-running the test case manually. On the other hand, if we had performed a number of dynamic comparisons as the data was entered we might be able to determine where something had gone wrong without any additional investigation. Robust tests are, therefore, prone to more failure analysis effort. Although storage space is not a particularly big issue for a lot of organizations, it may nevertheless be an important consideration. The more comparisons we specify for our automated tests the more storage space will be consumed by the expected and actual outcomes. Sometimes it is the number of outcomes that have to be uniquely identified and stored that causes hassle, rather than the amount of disk space consumed. 4.7.3 Redundancy
Too much sensitivity rather than a lack of it can adversely affect the failure analysis effort for a large number of automated test cases. If we run a set of sensitive test cases there is a good chance that a number of them will fail for the same reason. In this situation each of the failed test cases is highlighting the same defect. While we would wish to be told about such an unexpected difference we would not wish to have more than one test case telling us about it; a single test case failure per defect does very nicely. This is illustrated in Figure 4.7. Of course if we run a set of test cases and several of them fail we will start to analyze each failed test case in turn. After we have looked at a few we may decide to stop there and re-run the test cases on a repaired version of the software. However, we have already wasted some time analyzing test case failures that did not tell us anything we did not already know.
Three test cases, each change a different field
Robust test cases check specific .field only and so miss the unexpected change
Outcome of the test cases
Unexpected change occurs -•"' for every test case
Sensitive test cases check much more of the outcome and so spot the unexpected change
Figure 4.7 The consequence of having too many sensitive test cases is that more of them fail for the same reason, which often results in wasted effort analyzing the failed test cases.
4.7.4 Strategies for test sensitivity
So, which is best? As with many other aspects of testing, there is no absolutely correct answer to this question. Either extreme could be the right thing to do in different circumstances. This is one of the design decisions that you make when you design an automated test. In practice, we are unlikely to take either extreme but do something in between. However, the degree to which a test case is sensitive or robust is an important issue. We can recommend two possible strategies that you can adopt or adapt to your own situation. Our first recommendation is to use sensitive comparison predominantly at a high level where test cases are run as a sanity check whenever a change is made to the software. A high-level breadth test or roll-call would be a standard regression test set that is run at the start of every test cycle. The idea is that we want these test cases to detect any unexpected changes anywhere in the system. These test cases should be predominantly sensitive so that they will pick up any change, no matter how small. Robust comparison should then be used predominantly at the more detailed levels where each test focuses on some specific aspect of the software under test. These tests are better designed to be robust, as there are usually a good many more of them with fewer differences (or more overlap) between them. Our second recommendation is to consider designing sets of test cases such that one or two of them use sensitive comparison while the others use robust comparison. In this situation each set of test cases explores a different aspect of the software so within a set there is a lot of overlap in what they sec of the software. If one or two test cases compare the peripheral information then there is little point in the other test cases within that set doing so again since one unexpected difference in the peripheral information may cause all test cases within the set to fail. A good test automation strategy will plan a combination of sensitive and robust tests, taking advantage of the characteristics of each aspect (and many shades in between) to accomplish the objectives of each set of automated test cases in thq most effective and efficient way.
4.8 Comparing different types of outcome 4.8.1 Disk-based outcomes
We include databases, files, and directories/folders in this disk-based category of outcomes. 4.8. LI Comparing text flies
Text files are perhaps the easiest type of data to compare. Most simple comparators deal with text files (and only text files). In this section we look at an example comparison of two small text files, using the Scribble application that was introduced in Chapter 2. Figure 4.8 shows the output from a simple comparator given two slightly different text files, countriesl and countries2. Comparators should be capable of detecting records that arc different (have different, extra, or missing characters), records that have been added, and records that have
List of differences
countries1
Figure 4.8 An example comparison of two text files. The output from the comparator highlights the differences, identifying which records are different (UK has changed to United Kingdom), which records have been removed (Norway has been removed), and which records have been added (Germany has been added).
been removed. The output from the comparator in Figure 4.8 shows us that each of these three differences occurs between the two files. The comparator identifies sections of the two files that are different and outputs the contents of the corresponding sections in pairs one after the other. How to interpret this output is explained further in Figure 4.9.
Denotes the start of a difference section pair • The name of the first file
—.^--countries! Sweden UK ----- countries2 Sweden United Kingdom
Records from a difference section in the first file The name of the second file ' Records from the corresponding difference section of second file
\ Denotes the end of a difference section pair
Figure 4.9 Explanation of the output of the comparator shown in Figure 4.8. This shows that the record following Sweden is 'UK' in the first file but 'United Kingdom' in the second. (Note that here Sweden is output to help you identify where the difference occurs.)
The format of comparator output varies from comparator to comparator, and many will allow you to specify different options. For example, in our case we have shown the comparator including the record 'Sweden' at the start of each difference section shown in Figure 4.9 despite the fact that it is the same in both files. This is done to help you recognize where the unmatched records (in this case there is only one unmatched record) occur in the two files. Depending on your comparator, it may be possible to specify that more of the preceding matched records are used in this way or that no matched records arc copied to the output. Another option may allow one or more matched records following the unmatched records to be included in the output from the comparator. A sequence number added to each record is another common and useful feature. 4.8.1.2 Comparing non-textual forms of data To compare anything other than standard text files usually requires a specialized comparator. Some test execution automation tool vendors can supply specialized comparators, for example to handle character-based screen images that use escape sequences and graphical characters or that are specifically designed to handle a variety of graphics data formats. If an appropriate comparator cannot be found we recommend considering changing the format of the data into a textual form since this is usually much easier to compare. This is discussed further in the following section. 4.8.1.3 Comparing databases and binary files
Comparators that handle databases and/or binary files tend to be fairly specialized and concentrate on just one particular type of database or binary file format. However, this does not mean that your databases and binary files cannot be compared if you cannot find a suitable commercial comparator tool. In most cases it is the information in the database or binary file that is of interest, rather than the database or binary file itself. This information can usually be converted into a textual form. For example, information in a database can be extracted and written to a text file, perhaps using a report generator. Data held in a binary file can be converted into a textual form if there is not already a textual equivalent. Converting the information into a textual form often makes it much easier to compare and allows a simple comparison tool to be used. Furthermore, you can be much more ^elective over what is compared and what is not compared. If the format of the resulting text file is under your control you can design it to make both comparison and difference analysis easy. For example, consider a binary file that contains a description of a simple line drawing. The format of the file may comprise a header with a format like that shown below, followed by a number of vector records consisting of the starting and ending coordinates of each line in the drawing. (Note that the value for the 'Date last changed' field is expressed as the number of days since the base date of the software.)
Size (bytes)
Format version
'2.1'
Drawing type
Number of vector records
Integer ASCII Integer Integer
'M. Fewster' 3143
As a means of examining binary data, it is common to produce a hexadecimal dump that shows the content of each word (where 'word' means a pair of bytes, or 16 bits of storage) as a hexadecimal number. A hexadecimal dump of a header record containing the example values shown above would look like this: 2E32 0031 0000 4D01 202E 4546 5357 4554 0052 0000 OCOO 0046 0018
For comparison purposes, it would be much better to build a simple utility program that will convert this binary version into a textual equivalent like the following: Format version Drawing type Owner Date last changed Number of vector records
2.1 Schematic "M. Fewster" 10-Aug-89 24
This is much easier to read and understand and much more useful in a comparison. Using one line for each field name and value will make analyzing any differences simple. For example, if the drawing type was found to be different we would see a difference report like the one shown below. ----- filel Format version Drawing type ---- file2
2.1 Schematic
Format version Drawing type
2.1 Draft
Compare this with the difference report from a comparison of the two equivalent hexadecimal dumps shown below. ------filei 2E32 0031 0000 4D01 202E 4546 5357 4554 0052 0000 OCOO 0046 0018 ---- file2 2E32 0031 0000 4D02 202E 4546 5357 4554 0052 0000 OCOO 0046 0018
As you can see it is not particularly easy to spot the difference (it is the last digit of the fourth word reading from left to right), much less say what it means. 4.8.2 Screen-based outcomes 4.8.2.1 Character-based applications
If you are testing a character-based application, then all you have to worry about when comparing screen outputs is text and special graphics characters (an extended character set) and any display attributes such as bold, blinking, and reverse video. It is usually fairly straightforward to specify the location of the characters you want to compare since the screen is already an array of individual characters each addressed by a row and column number. The masking here might be specified by including or excluding specific rows, columns, fields (a consecutive sequence of character positions), or blocks (rectangular areas encompassing more than one row). In each case the masked character positions need not be completely excluded from the comparison. For example, it is possible to specify that the display attributes be excluded while the actual text content is included, or vice versa. 4.8.2.2 GUI applications
Applications that have a GUI can display a much greater range of output styles than a character-based application. Most of these output styles have become the norm for the majority of users as applications have standardized on the use of items such as windows, icons, menu bars, dialog boxes, buttons, and check boxes, to name but a few. Whatever is displayed, it is converted into a bitmap (unless it is already stored as one) before being sent to the screen. Bitmaps are a notoriously troublesome format to compare. For this reason they are best avoided wherever possible. When checking screen output from a GUI application, it helps to know exactly what is being tested (in other words, we must know the test objectives). For example, if the outcome of a test is for a specific text message to appear on the screen, there could be at least three different test objectives: 1. To insure that the application software outputs the correct message. If the wrong message is output it is usually a problem with the applica tion software. 2. To insure that the application software specifies the correct display attributes. For example, the message may be correct, but if the applica tion requests it be displayed as black text on a black background it will not be particularly helpful. 3. To insure that the text string is displayed correctly (that is, the graphics software correctly formats the text string for display). Although the application may send the correct message and display attributes to the graphics software, the latter has to generate a bitmap that displays it correctly. Graphics software is not immune to defects.
Our approach to automating the comparison of these three objectives may be quite different. The text message usually starts off inside the software as a literal text string. By the time it reaches the screen it has been converted into a bitmap. If the objective is to check for the correct message, then it is better to look at the text message while it is still a text string (and before it is converted into a bitmap). This is because problems can occur when trying to bit-match text: • • • • • • •
a different font is used; a different color is used; a word is now in bold or italics; the text is now 12 point instead of 11 point; the background on which the text is displayed is a different color or is now shaded; the box in which the message is written is a different shape, so the words wrap around in a different place; the box in which the text appears is in a different place on the screen.
In all of these examples, the content of the message is exactly the same as before, so the test of whether the right text is shown should show no differences at all, i.e. the test should pass. However, all of these examples (and many more) can cause a bitmap comparison to fail. When it fails the reason for the mismatch needs to be investigated and this takes time, but the point of automating comparison is usually to save time. If the second objective applies (to check for correct display attributes) we would be better off capturing the display attributes as they are passed from the application software to the graphics software. This can be done by some tools but it may also be possible to have the application (or graphics software) report this information in a text form. If the third objective applies (to insure the text is displayed correctly) then we must look at the bitmap sent to the screen. This consideration of the test objectives applies equally to other types of output such as icons representing files and applications, check boxes representing the state of particular flags or switches, and a graphical scale representing a percentage of completion. Some test execution tools are capable of capturing such information at this earlier stage, which is often referred to as the 'logical level' (the bitmap state is referred to as the 'physical level'). The ability of tools to capture information at the logical level will always depend on how the software has been implemented. If non-standard implementations have been used, some test execution tools may not be able to capture the information at the logical level. This is often the case where custom controls (graphical interactors) are used. We know of some organizations whose automated tests have been confined to that subset of their applications that only use standard graphical controls.
We recommend the use of different tests to compare different aspects of a GUI application. Specifically, we recommend testing the graphics software (which governs how information is represented on the screen) separately from the application software (which governs what information is displayed). To test graphics software, we should use a representative sample of data to exercise the many different aspects of the graphics software, such as different colors, text fonts, line widths, shapes, patterns, etc.). To test the application software, use a representative sample of data to exercise the many different aspects of the application. These two sets of data will usually be very different. Combining tests to exercise both pieces of software at the same time is likely to result in poor testing of one or other, or both of them. Furthermore, having more specific tests (which will be more robust) will make failure analysis easier and reduce the likelihood of having a large number of tests fail because of the same problem. Of course, after these tests have been run successfully, it will be necessary to run some tests that check that the application software and the graphics software function correctly together. There will be fewer of these tests though. 4.8.2.3 Graphical images
Graphical images are made up of a fine array of dots called pixels. The more pixels that are used to create the image, the finer the image details appear; that is, the greater the spatial resolution of the image. Computers store graphical images as an array of bits called a bitmap in which one or more bits are used to represent each pixel in the image. The number of bits used per pixel (the bit-depth resolution) governs the maximum number of different colors that can be displayed. For example, if only one bit is used for each pixel only monochrome images are possible whereas with 24 bits per pixel millions of colors are possible. When a graphical image has to be checked it is the bitmaps of the actual and expected images that are compared. Unfortunately, bitmap comparisons can be rather fraught. The bitmap needs to be only one single bit different for a mismatch to occur even though such a difference is unlikely to be noticeable to the human eye. Some bitmap comparators permit you to specify a tolerance with the aim of making the comparison ignore differences that would not be noticeable. Most of the graphical images output by software applications are not permanently stored as bitmaps but in some other, usually more descriptive, form. The bitmap is generated when it is required. Since there are many different algorithms for generating bitmaps and even more implementations of those algorithms in commercial software the same result cannot be guaranteed across different software implementations, nor indeed across different versions of the same implementation. Thus, even if our software under test sends the same graphical description to some 'standard' bitmap creation software, we may not end up with exactly the same bitmap every time.
Another reason we can end up with very different bitmaps for what is essentially the same graphical image is that different screens can have different resolutions. Another problem with bitmap images is their large size. The size of the bitmaps is calculated by multiplying the spatial resolution and the bit-depth resolution. A small toolbar button may take about 1 Kbyte while a full screen image may take somewhere in the range of 2-5 Mbytes. If each test case performs a number of bitmap comparisons the disk space requirements can soon become enormous. This is likely to have a considerable impact on the long-term maintenance costs of your automated tests. The types of masking done for bitmapped images include ignoring a region of the screen or selecting a region (this is like the character screen but on a far finer grain). It may be possible to ignore a preset number of mismatched bits, or mismatches in certain areas, such as at the edges of images. It may also be possible for the bitmap comparator to ignore color. 4.8.3 Other types of outcome 4.8.3.1 Multimedia applications
Multimedia applications involve forms of test outcome that are not readily comparable; for example, sounds that are played, and video clips and animated pictures that are displayed. At the time of writing, no commercial tools known to the authors were capable of comparing video or sound though we anticipate that this is an area where improvements will be made. However, for now all is not lost. It may be possible to enhance the application under test to give the tester access to a useful level of information. This is an aspect of testability that is discussed further in Chapter 9. For example, if the application can output information (preferably in text format) that records when a sound was played and the size of the file containing it, this may be sufficient to give confidence that things are OK, or at least have not gone horribly wrong. Again it is important to consider the objective of the tests so you can automate at least a subset of them. For example, the human tester may listen to sounds to confirm that they are what they are labeled as, so that the one called 'lion roar' doesn't sound like a duck quacking. Once this link has been verified manually, the automated test could check that when the 'lion roar' sound is required, the software plays the sound clip that is labeled as 'lion roar.' 4.8.3.2 Communicating applications
Applications that have outcomes involving communication with other applications/processes or hardware devices (this includes embedded software) are likely to require a specialized testing tool or, more conveniently, a test harness in addition to a test execution automation tool. Such a test harness will be able to send messages to the software under test and/or receive messages from it. The test harness is most useful when it can read its instructions and output the messages it receives in a text format. Once again, this makes the automated comparison of the outcomes simple. The
test harness should also be able to record additional information such as the time when messages were received. We have seen a few examples of such test harnesses and implemented one or two or our own. These have all been homegrown test harnesses, designed specifically for testing one particular application. However, it is always worth looking for any commercial tools that match your needs, as they are likely to offer much more functionality and be better supported.
Comparison filters
4,9.1 Practical approach to building your own post-execution comparison tools: a comparison process
There is not an abundance of comparator tools (used for post-execution comparison) available commercially, which appears to leave a gap in the market. While there is usually at least one simple file comparator tool with each operating system, they offer few, if any, pattern matching facilities to help us with complex comparisons. However, in our experience there is little need for complex comparator tools as it is a relatively easy matter of using whatever simple comparator is available in conjunction with one or more other tools that are also readily available with most operating systems. This section describes an approach to post-execution comparison of text files that uses whatever simple file comparator is available in conjunction with one or more other tools that manipulate the information to be compared. Before the comparison is made the data is edited using one or more filters to extract the data required and mask out expected differences. This creates what we call a comparison process - a series of one or more filters followed by a simple comparison. This process could probably be applied to non-text Tiles though we have never done so. It is our preference to convert the outcomes into text first as this gives us the greatest flexibility and makes the whole process easier to implement, debug, and maintain.
When we were developing the test automation tool described in Chapter 12, we realized that there were a number of fairly complex comparisons that would need to be made in order to automate test comparison. Being well into the idea of writing our own tools, we were keen to write a good comparator. We estimated that it would probably take around six months, but we would then have a very sophisticated comparison tool. Unfortunately (as it seemed to us at the time), resources were scarce, so we were left with only simple and basic comparators. In order to try to automate some complex comparison even with our existing tools, we discovered the power of filters, which are actually a more flexible and better way to automate comparison. Moral: make best use of the tools and utilities that you have available.
4.9.2 What is a filter?
A filter is an editing or translating step that is performed on both an expected outcome file and the corresponding actual outcome file. More than one filtering task can be performed on any expected/actual test outcome before comparison. A comparison process using a single filter is shown in Figure 4.10. Using filters before comparing the files means that the actual comparison can use a much simpler comparator tool. Effectively, a filter removes the legitimate differences from the expected and actual outcomes, thereby ensuring that a simple comparison tool will highlight only unexpected differences; that is, the differences that we do wish to know about. The way in which the filters achieve this task is very much up to you but we recommend that masked fields be substituted by a literal text string that indicates the type of field that has been masked out. This will make failure analysis easier since the reported differences will still look something like the original. Most commonly, therefore, a filter is a text editor with a predefined set of substitution instructions, though it is not restricted to just substitution. Data extraction is another useful task. Rather than comparing the whole file, an extraction filter is used to extract just those parts of the file that can be meaningfully compared, or perhaps that need comparing in a different way to the rest of the file. Sorting is another task that can be usefully performed by a filter (in this case the filter is usually a standard sort utility). Some filter tasks can be more specialized and would involve you in writing a small tool or utility to manipulate your outcome data in a particular way. We have found that regular expressions (which were described in Section 4.6.4) are an invaluable aid to implementing filters. Undoubtedly there is an overlap between some of these filtering tasks and some of the post-processing tasks described in Chapter 6. However, we leave further discussion of this to that chapter. 4.9.3 Implementing a comparison process
In order to automate a comparison process, some form of 'glue' will be required to stick together the filters and comparison tool. This can be shell scripts (in UNIX parlance), batch files (MS-DOS parlance), command
Figure 4.10 Both the expected outcome file and the actual outcome file are processed in the same way and the resulting edited files are then compared using a simple
procedures (VAX/VMS etc.), or a compiled programming language - in fact, anything that will allow you to create a simple comparison utility that, given the expected and actual outcomes, will pass them through the necessary filters and comparator and return an appropriate status (i.e. whether or not there are any differences). The scripting language of a test execution automation tool could be used. This would provide a logical extension to the script that executes the test cases. The script that controls the test case execution could then invoke the post-execution comparison process script, or the comparison process could be implemented as a separate test case. This latter approach has the advantage of allowing the comparison process to be run independently of the test case execution if necessary. (It could therefore be run at a different time, on a different machine, and repeated as required.) How well this approach works will depend on the capabilities of the tool's scripting language and your comparison requirements. If all is well, it will be possible to integrate the post-execution process into the test execution process. Other approaches to implementing post-execution comparison processes use some other scripting or programming language. We recommend using an interpreted language (rather than a compiled language) because it lends itself more to prototyping, trying out one thing, changing it, and trying that. Batch files, command procedures, etc. are eminently suitable for this kind of job and we have found that many testers (including those without a technical background) already use them to implement their own handy utilities.
4.9.4 Advantages and disadvantages of filters There are several advantages of implementing complex comparisons using filters rather than developing or buying sophisticated comparison tools. These are explained below. 1. Availability of text manipulation tools. There are many tools readily available for performing text substitution, extraction, sorting, and the like. The tools we have used most often are sed, awk, grep, and egrep. These and many other such tools originated in the UNIX environment but executables for many different hardware platforms, and the source code, are available (often free of charge) from several sources, including the Free Software Foundation. More recently we have found the programming language Perl (Practical Extraction and Reporting Language) to be a good substitute for those tools we have just mentioned. The scripting language Tel has also been recommended to us though we have no experience of it. Actually, most any programming language for which there is support for regular expressions will do. Python is another suitable language, and there is a C library package for regular expressions.
2. Reuse. Once a filter has been implemented, it can be reused in many situations in addition to the one for which it was first developed. Indeed, the regular expressions themselves can be reused and we rec ommend doing so. Once a regular expression has been implemented and tested (for a date, for example) it should be documented and made available for reuse. There is no value in having different people imple ment their own regular expressions to achieve the same tasks. 3. More stringent comparison criteria. Because filters allow us to work on individual parts of an outcome at a time, we can produce more strin gent comparison criteria than may otherwise be achieved by using a single complex comparison tool. For example, a commercial comparator may provide a means of ignoring a date field but this would ignore any date (presumably any valid date, though this is worth checking when you evaluate any candidate tools). We may wish to insure that the date falls within a certain range or is a specific date relative to the date on which the test case is executed, something we can easily achieve using our own comparison process employing filters. 4. Easier implementation and debugging. Since even the most complex of comparisons is divided into a number of discrete steps, each step can be implemented and tested separately. The series of steps can then be incrementally integrated, each being tested, achieving better confidence in the whole comparison process. Having a complex comparison process is one thing; having confidence that it works correctly is another. It is easy to spot a problem with a complex comparison if it highlights a difference that you intend it to ignore. However, it may not be possible to prove that it will not ignore differences that you intend it to find. So any approach that makes implementation and testing of the comparisons easier has to be welcome. 5. Simple comparison tools can perform complex comparisons. For the final comparison any simple comparison tool will usually suffice (such as the MS-DOS operating system file comparison tool fc, and the UNIX operating system diff utility). The filters enable a series of steps to build up progressively more complex building blocks for simple comparison. Other special-purpose in-house tools can also be developed where more specific comparisons are required, for example, comparing dates or times to insure one is later than another, or checking that a single value falls within a given tolerance. Such tools are relatively simple to build for anyone with reasonable programming skills. There are a few disadvantages of filters. They generally require programming skills to implement them and they need to be tested and debugged before they can be used with confidence. If the format of the output being filtered changes, then the filter will also need to be changed. (This is similar to the effect of software changes on dynamic tests.) Finally, in common with other reusable items, they should be documented and managed so all those who need to use them can quickly find them and easily put them to good use.
4.9.5 Filter examples Figure 4.11 shows how the expected and actual outcomes from a test would be changed by the application of a single filter that substitutes three fields: a job number, a date, and a time. In this case the filter could be implemented using any one of a number of tools that support string substitutions using regular expressions. Three regular expressions are required, one for each type of field. These are shown in bold type within the following Perl script. while ()
s/J[0-9]{5}/<Job No.>/g; s/ [0-9] {2}-[A~Z] [a-z] {2}-[0-9] {2}//g; s/([01]?[l-9] |2[0-3]):[0-5][0-9]/<Time>/g; print;
This is the whole program to implement the required filter, coded in Perl. We are not expecting readers without experience of Perl to understand this, rather marvel at how little work is required to implement a useful filter. Note that different tools and languages have different implementations of regular expressions so these examples will not work for all tools. We have chosen to use a dialect of regular expressions implemented by Perl version 5.002 or later as this offers concise constructs.
Job number: J12345 Run date: 20-Jan-97 Time started: 12:45
Filtered expected outcome Job number: <Job No.> Run date: Time started: <Time>
Compare Job number: <Job No.> Run date: Time started: <Time>
Job number: J15469 Run date: 14-Aug-97 Time started: 13:36
Filtered actual outcome
No differences
Actual outcome Figure 4.11 A comparison process using a single filter. The same filter is used for both the expected and actual outcomes and performs three substitutions. In this case we have chosen to use angle brackets to delimit text that replaces an ignored field. This will help us to distinguish the substituted text from the rest of the original outcome.
The regular expression given in the Perl script above that is attempting to match a date string is perhaps too simple. As it is, it will match an invalid date, e.g. 45-Abc-99 but would not match 6-Apr-99. While this may be sufficient for some outcomes, there may well be occasions when we need to be sure that only valid dates and times are ignored. The regular expression can be extended so that it matches only valid dates within a defined range. 4.9.6 Multiple filters in series When there are many different comparison criteria for a particular test case outcome it is often better to literally dismantle the outcome into discrete pieces and then separately compare each of the pieces. This keeps the filters themselves simpler and makes the whole comparison process easier to understand, implement, and maintain. For example, consider the directory listing shown in Figure 4.12, which is some test output showing files that have been created or changed by the test. We wish to compare this with the expected outcome (the directory listing generated by the first test run, which was verified manually). The purpose of doing this is to insure that all the same files arc present and are of the same size, and that no extra files have appeared. The two directory listings may contain different files or they may have different sizes but this is what we are checking for. However, the two listings may be in a different order and the dates and times will be different, so Volume in drive F is UserDisk Volume Serial Number is 2DF9-8752 Directory of F:\Mark\Doc 18/08/98 14:01 18/08/98 14:01 19/05/98 16:34 253 Actual.txt 17/08/98 17:05 234,677 dates.txt 16/06/98 22:27 967 dir.dat 18/08/98 14:01 0 dirnt.dat 17/08/98 11:21 Examples 17/08/98 16:55 14,400 invdates.txt 17/08/98 13:11 33 invdates2.txt 17/08/98 13:52 430 numbers.txt 10 File(s) 250,760 bytes Directory of F:\Mark\Doc\Examples 17/08/98 11:21 17/08/98 11:21 16/08/98 19:37 26,317 date.txt 17/08/98 11:19 16,764 time.txt 17/08/98 11:21 63,760 dir.txt 5 File(s) 106,841 bytes Total Files Listed: 15 File(s) 357,610 bytes 584,860,160 bytes free
Figure 4.12 A directory listing to be compared using multiple filters.
we will have to cope with these differences but otherwise ignore them. A different disk may be used, so the volume label, serial number, and drive name can all legitimately differ. The other records in the files (directory names, file counts, etc.) are not relevant to the check we are performing and so can safely be ignored. Of course, it would be better to generate a more suitable outcome in the first place (i.e. just a list of files with their sizes). However, we are using this directory listing as an example of an outcome that we cannot change since this will be true for many outcomes that you have to deal with. Since our intent is merely to compare the list of filenames and sizes we can discard all the other information. This can be done with the following filter:
This filter outputs (by means of the Perl print statement) all lines which match the regular expression delimited by the / characters. The first few characters in the regular expression, A\d, match only lines that begin with a digit. This selects only the lines that start with a date, i.e. those that contain filenames and directory names. The next few characters of the regular expression, [" z where a is dissatisfaction with the current state, & is a shared vision of the future, and c is concrete knowledge about the steps to get from a to b. These three things taken together must be greater than z, the psychological or emotional cost to the individual of changing the way they work. This equation explains many things about the change process. There are some people who will jump on any bandwagon that comes along - they have a very low threshold of change, and are easily dissatisfied with the status quo. At the other extreme are people who say 'I've done it like this for 30 years and I'm not about to do it any differently, no matter what.' These people have a very high threshold of change and will be very resistant to any new ideas. 11.9,3 How to persuade people to change the way they work It is very difficult to change someone's psychological personality, i.e. to alter the value of z in the above equation. However, the way to encourage people to change the way they work is to concentrate on the other three things (a, b, and c). Make them more dissatisfied with the current way testing is done ('You mean you're still doing all that testing by hand?'). Give them a fuller vision of the way things could be in the future ('Come and see what we've been able to do in the pilot, and see if some of this might be of interest to you'). Explain the first easy step toward a complete change ('Let us help you automate a few key tests for you to try on the next project'). This is probably the most important thing you can do: to give them more detailed information about the steps they need to take from where they are now to where you want them to be in the future. People don't like taking large steps into the dark, but if you illuminate the way, they can usually be convinced to take a small step forward. Note this is one reason why you need to plan the implementation, so that you have these steps mapped out in advance! 11.9.4 Successful change breeds further change
Once people begin to change the way they work, change breeds further change, provided the experience is a good one. Once they have taken the first step and found that it was beneficial, they will be more willing to take the next step, i.e. their threshold of change will be lower. For example, if someone currently spends too much time in some tedious and error-prone task, such as populating a database before a test can be run, you could set up the test automation tool to do just this one job for them. In the first instance you may need to do it for them if they are not
confident to do it themselves. In any case, they will need your support ('hold their hand') as they have their first experience of using the tool. If you can insure that this experience is both pleasant and beneficial for them, you probably have a convert, who will go on to use the tool in all of the ways it could provide benefits for them. 11.9.5 Categories of changeableness
Your best friends in your change effort are not the 5% of people who will immediately rally to your cause, because when the next bandwagon comes along, they will immediately dump you and go onto the next one. You should concentrate first on the 'early adopters' This is around 15% of the people, who will take a bit of convincing, but are prepared to change if it looks like it could bring benefits. This may include highly respected opinion leaders. These would be the people involved in the pilot project. If there is someone who is very skeptical, and makes no secret about it, it is worth spending some time with him or her. If you can convert a skeptic to your cause, he or she may well become one of your most enthusiastic supporters. It is generally more convincing to other people when a known skeptic now supports test automation. The early majority (around 30-35%) will be the people targeted for the first .roll-out of the phased implementation, followed by the late majority (30-35%). Of course, the decision about who is involved when is not determined simply by their willingness to change - project groups are likely to contain all types. However, look for a project with people who would be more rather than less willing to change, especially at first. Eventually everyone will probably change, although there is also a class called 'laggards' (10-15%) who will be very resistant to change. This group can be very frustrating to the change agent. Resist the temptation to take them on as a challenge, particularly early on; you are better to ignore them. They will eventually fall into line or may even leave.
When test automation was being rolled out, there was one manager who would Siave nothing to do with it. Partly through political factors and personal antagonism to the change agent, he did not 'buy in' to the idea of test automation, but was adamant that manual testing was better for them. Various rational reasons were given for this decision, which the change agent was not able to refute, at least not to this manager's satisfaction. Three years later, when all of the rest of the company had automated testing, which was working very efficiently, saving significant effort, and giving better quality software, this manager was eventually forced to conform, and his group then automated their tests. By this time, it was probably considerably easier for them, since the regime was already established in the rest of the company, but they had wasted a lot of time testing manually in those three years.
11.10 Conclusion 11.10.1 The implementation 'iceberg' The significance of the tool implementation process is shown in the iceberg diagram of Figure 11.2. If you have read this far in this chapter, you will realize that buying a test execution tool is only the first step towards test automation, and is probably the easiest part of the job. The half of organizations that fail at test automation run aground on the part of the iceberg that is not immediately visible. The job of implementing the tool involves three important elements: the infrastructure or automated testing regime (which this book describes), an internal selling job (done by the tool champion), and continuing support, both from management and from the implementation team. The cost of a tool is more than the cost of the tool! The purchase price is a small percentage of what you will have to pay in terms of internal effort in order to succeed. 11.10.2 Evaluating the tool implementation
Remember that business case that was prepared when the tool was originally selected? Once the tool has been rolled out to a reasonable number of users, the business case should be revisited to see whether or not you have achieved your objectives. It is likely that there will be some aspects that have not turned out as well as you had hoped, but you may have realized other benefits that are very valuable. You should re-evaluate the use of the tool in the light of what has happened, and set new goals for continuing automation. If you have not done so already, you should put some means in place to measure your automation regime, as described in Chapter 8.
11.10.3 When does it end? Never. You should now enter a cycle of continuous analysis and improvement of your automation regime that will never stop. If you do not pay
continuous attention to your automation regime, it will decay over time. The work that needs to be done should be minimized, and your automation regime should give you value for time spent on it. The measurements you use should help you to achieve those goals.
Summary Successful tool selection is no guarantee of successful implementation of that tool within the organisation: 40-50% of organizations have test tools that are 'shelfware,' i.e. not used. Implementing a test execution tool is a 'management of change' process that gradually widens the tool's acceptance and use within the organization. There are a number of roles to be played in implementing a tool, not necessarily by separate individuals. The tool 'champion' is the enthusiastic evangelist for the tool. The change agent is in charge of the day-to-day changes to the way people work. The angel or sponsor gives high-level support. The tool custodian is in charge of the technical aspects of the tool such as implementing new versions from the vendor and building the automated regime and testware. The implementation team is drawn from all of those who are expected to use the tool. They arc a means of communication about tool requirements and about how best to use the tool. The first step of the implementation process is to prepare for it. This requires management commitment, both visible and material. It is important that management expectations are set at realistic levels. The next step is internal publicity (usually much more than is realized) and internal market research (by the implementation team). It is a very good idea to implement a new tool first of all on a small-scale pilot project. Set quantified objectives and evaluate your results against the pilot's business case. If the results are good, then the tool can be rolled out on a wider scale. It is critically important to be aware of 'people' issues. This is one reason why a lot of tool implementations fail. Evaluate tool use against original and continuing quantified goals, and continue to improve.
Test automation case studies anc guest chapters
Introduction: case studies and guest chapters
Why these chapters are included in this book In Part 1 we have discussed test automation and outlined how to organize and structure the tcstware lor an efficient maintainable regime. It is always interesting to know what other people's experiences are. Our collection of contributions reflect people we know who have had both good and bad experiences and arc willing to share their hard-won knowledge. The case studies represent experiences over more than ten years, but often the problems encountered and lessons learned are the same. Some of the problems encountered by the authors may have been avoided if this book had been available to them at the time. Our aim is that you will be able to minimize the problems you encounter and overcome them more easily, through the experiences and advice contained in both parts of this book. Some of the authors in Part 2 use different terminology than we have defined in Part land the Glossary, but this will be explained in the chapter. In this part of the book, specific tools are mentioned by many of the authors. This is not intended to imply any approval or otherwise of these tools or of the tools that have not been mentioned. The particular tool used is not really relevant to the lessons learned in these case studies. The same lessons need to be learned with every tool. The table on pp. 303-304 gives summary details of all of the chapters in Part 2. Below we give a brief description of each chapter.
Historical case histories: chapters 12 and 13 The first two chapters in Part 2 are the oldest, both dating from 1988, and both with tools developed internally. (The commercial testing tool market was in its infancy ;ii that time.) Chapter 12 relates Mark Fewster's experience in developing automated testing, where the principles outlined in Part 1 of this boqk were initially
Chapte Author r 12 Mark Fewster,
Main message
1988-91,
> Nine
Outright success
story, proved to stand the test of time Methods more
Keiron Marsden i
Marrrie
1998/9 update Autotest
Hutcheson 14
Clive Bates
online important than service tools Windows, PC Importance of workstation: planning
SQA TeamTest
Peter Oakley
DEC DIM and V-Test
VAX VMS
Tool selection, good metrics, payback in 16 months
Paul Herzlich
WinRunner
Client/ server, Windows
Tool selection, dynamic technically challenging environment
Simon Milts
Automator QA (QARun), Lotus 123, SPSS
PC DOS and Windows
Test design for monthly varying data
Steve AUott
Windows, three databases
Practical lessons learned over three generations of automation
Stale Amland
PC, IBM server
Failure stories: lessons learned
Bob Bartlett, Susan Windsor
Not specified, PCs could be any
Lloyd Roden
QARun
Automation is worth doing even in unexpected situations Good automation, attention to people issues and architecture
Chapter Author
1994-99 Any
HansBuwalda
The Action Word method, keyword-driven
Iris Pinkster
Graham Dwyer,
PCs, ATMs
RadSTAR plus any
Freeburn 25 1997-98
AS/400,
RadSTAR plus
OS/2, NT,
RadSTAR method
another not
met stringent requirements for automation Much useful
advice reprinted from her Handbook of Jest Automation Good
specified 26
Linda Hayes
27 1990s
Angela Smale
Early restarted 1996
Action Words Tool-supported keyword-driven level using tables
level Success using
QA Partner, XRunner
automation for GUIs, technical detail and advice Microsoft
Variety of types of test automation with strengths and weaknesses
developed. These ideas have been proved in practice over the intervening years; this is now one of the most successful and long-running automations that we know of. The first part of this chapter describes the story of how test automation was developed at the company from 1988 to 1991. The second part of the chapter describes the current state of automation at the company and was supplied by Keiron Marsden, who has been involved in the use and further development of this regime. Chapter 13 describes a tool that went through phases of use followed by disuse. The main underlying problem was that having a good testing process is more important than automation. This led to the development of Mamie Hutcheson's MITs (Most Important Tests) test management method. The lessons learned are still applicable today.
More recent case histories: chapters 14-21 This set of case histories represents contributions from those known to us who have had useful experience in test automation that they are willing to share. Chapter 14 by Clive Bates describes both bad and good experiences in automating testing at a UK bank. Their first experience was not a success, as the tool became shelfware. However, they did eventually succeed using the same tool. A major key to success is good planning. Chapter 15 describes Peter Oakley's experiences at a financial institution in the UK. Like the previous chapter this is a 'failure first, success later' story, but in this case a different tool was used for the second attempt. A rigorous selection process was carried out for the second tool, including a detailed business case for expected benefits. One of the features of this chapter is the detailed metrics kept about the costs and savings from the test automation. Chapter 16 describes Paul Herzlich's experience testing one of the first electronic stock exchanges. Testing was very important but also difficult, due to the dynamic nature of the application, both in the data it handled and in rapidly responding to changes in this specialized marketplace. An efficient test regime was planned from the start, so this is definitely a success story. Paul quantifies the benefits over the first 18 months. Chapter 17 is from the UK insurance industry. The testing was outsourced to Simon Mills' company, which drew up tests based on standard quotes. These were designed for automation independent of any specific tool, and have been running successfully for four years. The distinction between the role of the tester and the automation technician is illustrated with an interesting story. In Chapter 18, the software product is a sales and marketing support system, made of standard and customer-tailored components, on multiple platforms using different database engines. This chapter by Steve Allott describes three attempts at automation, with increasing maturity each time, but also with significant problems. Failure stories can be more interesting than success stories, and are often easier to relate to. However, the stories in Chapter 19 are not complete failures, just as many of the success stories in other chapters are not complete successes. Stale Amland describes two projects where test automation was attempted using two different tools. The reasons for the problems are outlined together with advice for how to avoid them. Chapter 20 describes the automation of tests that initially seemed a very unlikely candidate for automation. Bob Bartlett and Susan Windsor work for a testing services supplier, and were asked by their client, a bank, to help select a software package. A good testing approach proved its worth at all stages, and the same automation strategy was eventually used by both the supplier and the customer (the bank). Chapter 21 by Lloyd Roden outlines the successful implementation of test automation for human resource management software by an independent testing team, with a useful summary of the key points from each stage.
Advanced methods and associated case studies: chapters The next four chapters are in two sets of two. Chapters 22 and 24 describe what we consider to be good examples of implementing keyword-driven scripting, and Chapters 23 and 25 are case studies of people using each of the techniques. In Chapter 22 Hans Buwalda describes the Action Words technique, which provides a way to separate the tests from the automation of those tests. The test clusters are kept in spreadsheets and contain the action words to be performed and the data to be used in the test. Navigation Scripts interpret the Action Words and implement the actions in a specific tool language. An example is given to explain how the method works. Chapter 23 by Iris Pinkster is a case study using the Action Word method. Chapter 24 describes an approach using spreadsheet tables to store Window definitions, test steps (navigation), and business object scenarios, supported by their proprietary tool. Chapter 25 is a case study by Jim Thomson. An early attempt to automate testing had failed, and a second attempt was not satisfactory either. The approach described in the previous chapter was then found and it provided what was needed for their third and successful attempt. The chapter includes examples of a number of useful metrics to monitor the progress of testing.
Advice: chapters 26-28 The final three guest chapters of the book are more in the nature of useful advice rather than straight case studies, although all three are based on extensive experience in test automation. Chapter 26 is a reproduction of extensive extracts from Linda Hayes' useful booklet The Automated Testing Handbook. We have selected the parts that most complement the material in the rest of this book. Chapter 27 by Chip Groder gives useful and detailed advice for testing GUI systems. There is information about how to estimate costs and savings for automation, test planning and design, how to structure test cases, a detailed example, and a checklist. Chapter 28 by Angela Smale describes her experience at Microsoft since 1988 using different types of test execution automation tools. Sometimes a certain approach proves very useful in unusual situations. She also argues for an element of randomization in automated tests, and concludes with a top ten list for successful automation.
Conclusion All of the chapters in Part 2 have a useful message to those who are attempting to do what the authors have done. Take the advice offered in Chapter 19: 'If you want to automate your testing, listen to people with experience before you start!'
Racal-Redac case history Mark Fewster and Keiron Marsden
12.1 Introduction This case study describes the project where some of the techniques described in this book were initially developed. Mark Fewster worked as a developer, development manager, and test automation manager at Racal-Redac for ten years. He was responsible for the automation of testing -managing the teams that provided the test tools, test data, and methods. He began automating testing in 1988. The first part of this chapter is derived from a conference presentation and paper written by the co-authors of this book. It was originally presented at the International Conference on Testing Computer Software in 1991. The paper was later published in the Journal for Software Testing Verification and Reliability. As you will see, starting test automation was not an easy task. However, the techniques described in this book have proved themselves in this organization. We are grateful to Keiron Marsden for providing the updated information about test automation as it is practiced now, over seven years after the initial story was written.
12.2 Background 12.2.1 The company and the products Racal-Redac at the time was a part of the Racal Electronics Group and one of the top five vendors of electronic design automation software. The company's product range included a family of products called Visula. This comprised over 120 programs, with 2.5 million lines of non-comment code statements, and was ported to all leading industry workstation hardware platforms. The main programs were graphical, user interaction being both keyboard- and mouse-driven.
12.2.2 Original testing activities The software engineers who developed or modified a piece of software performed their own tests. Subsequently, the software was handed over to the Product Assurance Group, a team of about 10 engineers (called application engineers) who were skilled in the use of the product. There the product would undergo three distinct testing phases: evaluation, integration testing, and system testing. Evaluation involved assessing the software from the product user's point of view. Integration testing ensured that all the required programs were present and that they were compatible. System testing involved a more thorough approach - simulating the environment and the use that customers made of the software. 12.2.3 The problems with manual testing Integration and system testing were performed manually and were repeated for each platform. In 1989 these activities typically consumed 38 person-weeks of effort for every software release on every platform. In that year, Visula was delivered on four platforms, and there was a nine-month delay between delivery on the first and the last; much of this delay was attributable to the manual testing bottleneck. Furthermore, as Visula grew in size and complexity, each release required more testing. If support for an increasing number of platforms were to continue (nine had been planned for 1991), a more efficient method of testing would be required. As Visula had been supported on a progressively larger number of platforms, it is not meaningful to compare the total test effort release on release. The graph of Figure 12.1 shows the average effort per platform for a series of releases of Visula, and takes into account not only the manual test effort but also the evaluation effort and administrative overheads. Because the tests were performed manually (and often from a vague test specification), they usually found a number of generic bugs (bugs present on all platforms) in the second and subsequent platforms, thereby proving that the tests were effectively random, being performed differently each time they were carried out.
12.3 Solutions 12.3.1 Multi-solution strategy The requirement was to reduce the cost of testing without reducing the test coverage. In addition to test automation other solutions were implemented in parallel: the use of an outside consultant, training in testing techniques, and better deployment of testing staff. While these are not the main subject of this case history, they are outlined below as each had an impact on the test automation solution. 12.3.2 Test automation tools A decision had to be made between buying a tool and developing one in-house. Buying a tool would mean that implementation of automated tests could be started immediately, but it might be found that the tools did not suit all our needs. Developing a tool in-house would use up precious development resources, not only in implementation, but also in maintenance. We did have a little experience of automated testing, albeit on a very small scale. (Two development groups had used UNIX shell scripts to 'automate' certain unit tests. These were based on a common script - an attempt at a generic script - but each had been customized to meet the specific needs of specific sets of test cases.) A brief market survey of commercially available testing tools did not reveal any that addressed our particular needs. It has to be said that the survey was not very thorough. At that time, we were not aware of any available catalogs of testing tools. Furthermore, there was a strong belief that developing some basic test tools would be straightforward. The decision was made to develop all the required tools in-house. The functionality of the tools is discussed in Section 12.4.1. 12.3.3 Outside consultancy An outside consultant was used during the planning stage of system testing automation. The purpose of this was to check that our chosen solution overlooked neither a better solution, nor potential problems. The least that was hoped for was a 'warm feeling' that we were on a good track. This we achieved, and we also obtained some valuable advice. 12.3.4 Training in testing techniques Changing the approach to testing provided an ideal opportunity to invest in training and improve on the techniques being used. Myers (1979) provided the initial inspiration and a training course provided the follow-up. The effectiveness of the training course was measured by recording the number of software defects found by five application engineers over the same time period just before and just after the training. After the training they found
four times as many defects as they had found before the training. However, some of the defects were considered low priority so we weighted them according to priority, 9 points for a high priority defect, 5 for a medium priority, and 1 point for a low priority. The testing performed with the benefit of the training proved to be three times as effective and gave a sevenfold payback for the cost of the training over a one-month period. This paved they way for a series of tailored courses to train all our application engineers and most of our software engineers (over 80 people in all). Testing techniques such as equivalence partitioning and boundary value analysis were taught. Additional follow-up, support, and encouragement in the use of testing techniques to all the engineers who had been trained proved worthwhile to ensure a good and consistent use of the techniques. 123.5 Better deployment of testing staff The primary task of the company's application engineers was to evaluate new software from the product user's point of view. However, it is wasteful to tell the software engineers, after the fact, that it wasn't a good idea to develop a piece of software. It is much better to tell them not to develop the software in the first place. This was thought to be best achieved by moving the application engineers into the development groups to work alongside the software engineers. Also, assigning to the development groups their own application engineers meant that the group managers had direct control over the products tor which they were responsible.
Integration test automation 12,4.1 Tool function
The automatic test harness tool (called Autotest) controls a series of test cases on different programs and software units in Visula. Each test is defined by its input data, instructions on how to run the test, and the expected output data. The tool requires that the programs to be tested arc capable of being driven solely from data held in files. Fortunately, most of our programs did have this capability. The testing process is depicted in Figure 12.2. The comparison process is performed by different programs depending on the format of the data to be compared. Some formats require only simple comparison such that every difference between the two files is reported. More complex comparison programs are required for files that contain legitimate differences. Expected output data is not prespecified manually. Instead a reference testing approach is used in which the initial test output is manually verified, and then serves as a reference point for automatic comparison of all further runs. A test report is generated giving the status of each test run. This also contains details of the versions of software, the machine used, the elapsed times, etc.
12.4.2 Development effort The test harness tool and a few 'standard' comparison tools were developed in just under a year with nearly 4 person-years effort. Much use was made of prototypes before the detailed requirements could be confirmed. Towards the end of this development period, the Product Assurance Group undertook the automation of the integration tests. This was completed using about 9 person-months of effort. Not all of the required tests could be automated. It was still necessary to perform some of them manually because the programs being tested did not facilitate access to their internal data structures. Often, the final result data was insufficient to indicate that the test had worked. 12.4.3 First use of Autotest The automated integration tests were used, for the first time, to perform a complete integration test of the Visula 5.0 release. The manual tests took 2 person-weeks, and the automated tests 1 person-week. The automated tests could actually be run in about 10 hours, but a lack of comparison tools meant that manual effort was required to verify some of the results. Without automation, integration testing took 10 person-weeks on every platform. With automation, this had been reduced to 3 person-weeks. Further reductions were possible with more automated comparisons.
12.5 System test automation 12.5.1 The new goal Having made a significant impact on integration testing, the next step was to automate system testing. However, this was a much larger undertaking: 28 person-weeks of manual tests had to be condensed into tests that could be run automatically. Unfortunately, not all the manual testing was supported by detailed test specifications. Some areas of functionality, when system tested, would be 'exercised' by the application engineers as they saw fit. There was also little
official test data. Manual testing relied on each application engineer either knowing where a suitable Data Set could be found or generating it on the spot. In addition, most of the data was platform specific as there was no mechanism for transferring certain types of data between platforms. This situation was not as bad as it sounds, since many of the engineers had been involved with testing for some time, and knew just where to find test data that had been used previously. However, this did mean that it was necessary not only to automate the tests, but also to define what had to be automated. This complication made it imperative that the application engineers be involved in the test automation. Taking a somewhat cautious approach, a proposal was put forward for a project, requiring about 3 person-years effort, to reduce the system test effort by 80%. However, convincing the Managing Director that it was still necessary to perform 20% of the testing manually proved too difficult. He called for 100% test automation!
12,5.2 Development effort The test data development was split into two phases, which were referred to as breadth test and depth test development phases. The first phase, or 'breadth testing,' aimed at insuring that all programs were exercised in some way. The intention was not so much to find defects, as to demonstrate that each program did do at least some things correctly. The second phase, or 'depth testing,' aimed at improving the test coverage (i.e. functional coverage) of the more critical areas in the software; essentially increasing the depth of testing for a subset of the programs. For breadth testing, the application engineers predominantly implemented a subset of the manual tests: those that they believed to be best for the job. No test plans or test specifications were written. It was necessary to complete this initial Test Set as quickly as possible so that a more rigorous approach to testing could be used for the most critical areas in the software. For depth testing, test specifications were produced. These insured that good use was made of test case design methodologies such as equivalence partitioning and boundary value analysis, in which the engineers had been trained. We decided to combine the automated integration tests with those being developed for system testing. With manual testing, passing the integration tests was, in effect, the entry criterion for starting system testing. For automated testing, there seemed little value in retaining the two sets separately, since either could be run in a matter of hours, rather than weeks. Problems in locating the integration test data several months after it had last been used highlighted the need for formal control. It was clear that control standards and procedures had to be introduced. Fortunately we were able to use our source code control system to mechanize much of what was required. Another notable problem was that much of the task of validating the results from integration testing had been performed manually, so that the tests themselves needed further work. (By then a richer set of comparators was available which facilitated automation of test result validation.)
12.5.3 Technical problems 12.5.3.1 Programs not designed for testability
From the very start of the test automation program, poor testability of many programs was a constant source of trouble. The development groups often proved unwilling, or unable, to make changes that would enable better testing of their applications. Fortunately, the decision to develop the test tools in-house prevented a lot of anguish. It was sometimes possible to implement a temporary workaround by building into the test tool some knowledge of the program to be tested. This temporarily contravened our tool development policy, which demanded that the tools be generic - a policy that has made it easy to maintain the test tools because of their independence from the programs they test. Few of the programs had been designed with automatic testing in mind. During the two and a half years of this story, many improvements were made to them, but there was still more that could be done. What we learned through this experience meant that we could design facilities into new programs that made it possible to test automatically most of their important aspects. 12.5.3.2 Cross-platform differences
Despite designing the test data to be 'portable,' it came as something of a surprise to find just how different the test results were on different hardware platforms. It was always known that binary files would be of little use as test result data because they could not be compared across platforms. (It is necessary to compare the Test Results from one platform with the expected result data from a different platform since it is neither desirable nor practicable to store the expected result data for all of the platforms.) However, we were not prepared for the subtle differences in the ASCII files that were generated by the same tests on different platforms. Most of the differences could be handled intelligently with existing comparators, but it did take effort that was not planned. The most difficult of these differences to cope with involved graphical output data, such as the order in which items were drawn. Strictly speaking, many of the unexpected differences were defects in the programs being tested. However, as they had no net effects, and certainly none on the end user, they were regarded as acceptable differences. Whether to fix a bug or make the comparator ignore the difference is not an entirely objective judgment. For us it depended primarily on the effort involved in each particular case. 12.5.3.3 Debug information
When the automated testing of the applications started in earnest, debugging the failed test cases soon became a time-consuming task. Large tests were inefficient because the software engineer often had to re-run each failed test case a number of times with monitoring tools, and then had to wait until the test reached the point of failure, before starting work on tracing the fault.
The debugging activity also suffered under test automation because the software engineers had to do more work to identify the problem. Prior to automation, application engineers identified a fault and then experimented with different input data or actions to try to pinpoint it. They then presented their findings to the software engineer. With automated tests, the software engineers were left to fathom out why the test case had failed (this often required an understanding of what the test case was trying to achieve) and then pinpoint the fault themselves. This problem was made worse by early versions of the tool, which had been designed specifically for finding defects, and not for helping with debugging. A number of test tool enhancements were identified and implemented to ease this problem in later versions. 12.5.3.4 Platform architecture
Differences in the various hardware platform architectures caused some problems. The most obvious of these differences is the processor speed. The test tool has the ability to abort a test case that either 'hangs' or runs into an infinite loop. This is achieved by declaring the test case's expected run time as part of the test definition. The run time of a test case can vary tenfold across different platforms, so that either a test case can be aborted prematurely, or machine time can be wasted in waiting for the test tool to abort a test case that 'died' some hours- earlier. 12.5.4 Non-technical problems 12.5.4.1 Too much change too soon We undertook too much change too soon. Perhaps the most significant change, apart from the test automation itself, was the reorganization that resulted in the application engineers being moved into the development groups. Had they been left in their own group, fewer people would have become involved at a time when teething problems were still being sorted out, and these problems could have been dealt with more efficiently, and with much less anguish. The reorganization also meant that some software engineers were required to do testing that had previously been performed by application engineers. This met with resistance - resistance to testing, and to the tool. The problem was partly addressed by the test training program - one engineer said of the course: 'Beforehand, I thought "Oh, no! Not a testing course!" but I was pleasantly surprised with how enjoyable testing now seems.' Other problems arose from a change in software-version release. When we started system test automation, it was planned to use Visula 5.0 for all but the two platforms that had already been tested manually. The completion of the automated tests was to coincide with the completion of the software ports to the remaining platforms. However, it was decided to supersede Visula 5.0 with Visula 5.1. Once Visula 5.0 system test automation had been completed, it was necessary to add further tests for the new and changed functionality in Visula 5.1. This became the responsibility of
the development groups (since these now included the application engineers), and so involved a good many more people in the first attempt to automate testing than was desirable. 12.5.4.2 Implied automation of development testing
The original goal, that of attaining 100% test automation, was widely publicized, but not qualified sufficiently well. There was an implication that development testing (unit or module testing, performed by the development staff) was to be automated. The result of this was that some software engineers took a quick look at the test tools, saw one or more problems, and then backed away. Resources were not available for introducing them all to the tool in a more helpful way. (Note that all developers eventually did use the tool, as described in Section 12.8.) 12.5.4.3 Teething problems caused delays
Because of the number of people involved with automated testing in the first few weeks of its introduction, the number of problems and difficulties that people encountered with the new approach to testing seemed enormous. Most of the problems were fairly simple to correct, but the task of communicating the solution to everyone involved proved difficult. The tool became a good excuse for everybody's problems. Many problems blamed on the test tool were found to have nothing to do with it. 'Autotesting' had taken on a very general meaning - any problems encountered while Autotesting could be blamed on Autotest itself! Most managers failed to see through this, and they still believe Autotest caused their projects to run behind schedule and over budget.
12.6 The results achieved 12.6.1 Test effort per product release
For the first major release of Visula to undergo automated testing, the average effort per platform was about 48% of what would have been expected with manual testing. This average was falling; at the time of writing, the software had not yet been ported to all the platforms. As a result of all the teething problems, the first platform showed no real gains (96% of the testing effort that would have been expected with manual testing). Subsequent platforms have used 60%, 50%, and 35% of projected manual effort. The testing effort on the ninth platform was anticipated to be around 20%. Figure 12.3 depicts the average testing effort thus far, compared with previous software version releases. It turns out that no further reduction is likely, even if the ultimate goal of 100% automation is achieved. This is because the software that is being tested contains defects. The first pass of testing usually finds a good few defects and once these are fixed the second pass finds more. It is this repetition of testing that keeps the test effort high. It does, however, have one advantage - any «nall improvement to test automation is repaid several times over.
In terms of the original goal of 100% automated testing, the results are also good. A total of 8 person-weeks of manual testing is being planned for each of the remaining platforms. It is thought that this could be reduced to 4 person-weeks if the software were to contain fewer defects at the start of testing. So 79% test automation has actually been achieved, though, in theory at least, it could be as much as 89%. 12.6.2 Lessons learned 12.6.2.1 Need management commitment
This is very important, but it has to be planned. In retrospect, test automation was not explained well enough to our managers. There was an initial 'sales campaign' which explained to all the technical staff the aims and the benefits of test automation. On its own, this was not enough. We should have repeatedly asked for their views in order to check their understanding. It was all too easy to assume that they would see and understand the problems as we did. There would have been benefits from reading a book on the management of change such as Bouldin (1989) if only it had been known of at the time. 12.6.2.2 Makes debug effort more visible
For the first time, testing of a major product release was suspended to await the arrival of bug-fixed software from the development groups. Never before had the testers caught up with the developers. The testing and debugging activities have become more distinct. 12.6.23 Need to design for testability
There is no substitute for the freedom to choose what, and when, data is recorded during a test case. Not only does this make testing more precist and meaningful, but also it eases considerably the task of tracing faults Many of our test cases have had to 'make do' with whatever was offered b] the programs. This situation has led to difficulties in finding out why tes
cases failed, and has made debugging much harder. For example, certain of the interactive programs can be driven by ASCII command files. If a command fails, the program gives no reason despite the fact that it 'knows' - at the time, there was no way of extracting this information from the program during a test run. Again, certain tests check that particular commands are executed correctly. To do this, they extract from the program under test the state of its data structures before and after the command is executed. Often, it is not possible to be selective about the details that are output - it is 'all or nothing.' This creates unnecessarily large amounts of data that take more time to generate and compare; it also uses more disk space, makes debugging more difficult, and adds nothing to the value of the test. 12.6.2.4 Need training in testing techniques
The training proved successful, not only in encouraging new techniques, but also in changing people's attitudes towards testing. There is also much to learn about designing tests for automation, some of which will be general, and some program specific. Certain of the problems might have been overcome by providing training in the use of the test tools. While such training was available, the take-up was small. More emphasis should have been placed on its benefits. Unfortunately, at the time, we didn't realize them ourselves! 12.6.2.5 Tests should be short
At the start of the system test automation, there was concern about the overheads associated with a large number of small tests. It was known that long tests (tests that take hours to run) were not desirable, but it was thought that a lot of short tests would incur unacceptable overheads (principally for run-up and run-down times of programs under test, and result comparison times). It is now clear that a test case which runs for more than a few minutes has greater potential for wasting time than several shorter ones. There are several reasons for this. First, because of the different platform architectures, the test case time-out period is usually much larger than is necessary. This can lead to several hours being wasted on only a handful of aborted test cases. Second, long test cases have the potential to find many defects, but usually only one at a time, and the test cases have to be re-run after each fix. Third, the time spent debugging after failure of a long test case can be several times that for a short one. 12.6.2.6 Control cost of maintaining test data
Much of the automated test effort has been spent reworking the test data. The unexpected differences in test results from different platforms forced us, for a time, to employ platform-specific test Data Sets. Merging the different versions took several person-weeks, but was necessary to prevent the expected maintenance effort being repeated for each platform.
12.6.2.7 Test-stopping bugs stop tests!
This seems obvious, but the impact of it was not clear to us before testing commenced. The danger of leaving code untested when a test case aborts before completion is all too real. To minimize the number of such occurrences, test cases must be short, and failed test cases thoroughly investigated. The fixing of some of the defects that caused test cases to abort before completion took on a high priority, even though they may not have affected the end user. When a decision was taken not to fix a defect, there was then the choice of abandoning the test case (and risking leaving software untested), changing the test case so that it could resume (if this were possible), or reverting to manual mode for that test case. 12.6.3 Benefits achieved
12.6.3.1 Test effort per platform halved
The average test effort per platform was halved even for the first four platforms. While the first platform required only 4% less effort than would have been expected for manual testing, the subsequent platforms have improved on this significantly. The fourth platform achieved a 65% reduction. 12.6.3.2 Consistency of regression testing' The repeatability of the automated tests is reassuring. A start has now been made on automating tests for bug fixes; this should guarantee that defects found in one product release never appear again (something that did not happen often, but was very embarrassing when it did). 12.6.3.3 Less dependence on application expertise Less experienced application engineers and software engineers have been able to assist with testing that had previously been the domain of experienced application engineers. This has allowed better use to be made of valuable skills. 12.6.3.4 Bug fixes fully regression tested
Bug-fixed releases have been more rigorously regression tested than would have been practical with manual testing. The technique has uncovered further defects (caused by the bug fixes) which otherwise would have reached our customers. 12.6.3.5 Improved time to market Visula has been delivered on more hardware platforms in a shorter period of time than has ever been achieved before. Also, a new hardware model is now being supported. This would not have been possible for weeks, if not months, without automated testing. Before automation, we delivered four platforms in nine months; after automation we delivered nine platforms in four months.
12.6.3.6 Improved cross-platform quality The consistency of regression testing has given greater confidence in the different platform releases; what works, works on all platforms. 12.6.4 The payback Over the two and a half years since the start of the test automation project, five person-years were spent on developing and maintaining the test tools, and a further five person-years on developing the test data. Significant benefits were first noticed only at the beginning of 1991, but by the end of the first quarter, about three person-years of manual testing effort had been saved. By the time Visula 5.1 is released on nine platforms, it is expected that the breakeven point will have been reached. Beyond that, person-years of manual testing effort should be being 'saved' every three or four months. The graph of Figure 12.4 depicts the cumulative effort used in developing the test tools and the test data. The 'savings' line represents the actual and estimated benefit of the test automation program. Work on the project started in July 1988, and it was predicted that the breakeven point (considering major releases of Visula only) would occur around July 1991. (In 1993, Mark Thompson reported at the STAR conference that test automation was saving the company £350000 ($500000) per year.)
12.7 Summary of the case history up to 1991 Manual testing had become a bottleneck in the product life cycle and was becoming increasingly costly. Furthermore, the requirement to support more hardware platforms was likely to accelerate the cost. Automated testing was chosen as the principal solution.
A brief market survey of commercially available testing tools did not reveal anything suitable. With a strong belief that developing some basic test tools would be straightforward, the decision was made to develop the tools in-house. A trial of the test tools was successful, and so encouraged an aggressive target of 100% automated testing. Many problems were encountered, both technical and non-technical, but significant benefits were realized. We achieved the automation of 79% of the testing, and were able to deliver our products to the market much earlier. Tests are now repeatable and consistent across all platforms. The ten person-years of effort spent in developing the tools and test data will have been matched by the savings gained through the reduction in test effort in about July 1991. From then on, savings of person-years of manual test effort should be realized every three to four months.
12.8 What happened next? The story so far represents the birth pangs of the automated testing regime at Racal-Redac. In the years since this part of the story ended, what has happened at this company? Keiron Marsden has provided the following information on where they are at the time* of writing (1999).
'Testing is at the heart of our quality system. Test automation makes it economic enough to be worthwhile.' Source: Keiron Marsden, Visula CAD/CAM Product Development Manager.
12.8.1 History since 1991 The company is now called Zuken-Redac and has moved to Bristol, UK. The Quality Assurance (QA) and Support functions have been combined because the people who have been involved in QA in the past have the knowledge needed to support, and those who have been involved in support in the past know what to look for when assessing the quality of new releases. Market share for the Visula product range is still the highest worldwide. There are no products that have been discontinued since 1993, so all existing products continue to be supported. In addition a number of new products have been added, and more functionality has gone into each new release of the existing products. Test automation has been a significant factor in enabling the company to become far more efficient to meet marketplace challenges in a dynamic industry sector. The company has also achieved ISO 9001 certification for maintenance and enhancements. Zuken-Redac now has a formal release procedure that depends on automated testing at every stage. We have thousands of automated tests, and this is still growing. There is as much testware as software.
The aim is for any full regression suite to run in 12 hours, although the largest, the CAD system, currently takes a little longer. For example, a sample Test Suite run recently for a component of the CAD system produced the following statistics: 1201 Pass 15 Expected Fail 7 Unknown 56 Fail 7 not run Total: 1286 tests
12.8.2 Technical advances in Autotest There have been some technical advances in the tool itself after its initial development. Autotest can now cope more easily with programs that require messages to be sent to communicate with them. It can automatically re-run all failed tests at the end of a set of tests, to overcome problems of unexpected events such as network failures. A very interesting technical development is the use of Autotest together with a specially written demonstration tool (called Dramatix) to semi-automate manual tests. Autotest is used to set up the test environment, i.e. make sure the correct version of software and data files are there, initialize test data, etc. The software being tested is then invoked but control is handed to Dramatix, which displays the test script for the manual test. The manual tester then performs the operations (which are not practical to automate because of the visual nature of the verification), such as checking whether objects can be moved around while preserving all connections. The tester then records Pass or Fail status in Dramatix. At the end of the test, Autotest performs any clear-up, and collects the Pass/Fail information to process in the standard way. There have also been some minor enhancements over the years, for example to make the integration into the release procedures more efficient. Now a single command to the configuration management system will copy the source code, perform the build, and run the automated tests. 12.8.3 Technical problems There are still a couple of technical problems being encountered. One is that around 1% of the expected outcomes are actually incorrect. These are discovered over time and corrected when they are found, but there are probably still some incorrect expected outcomes in the Test Suites. There is also a domino effect that happens at times. If 10 test cases fail, and a fix is supposed to correct this, the new software may actually fail 90 tests. This can be disheartening.
Some manual testing is still needed. For example, the function key layouts are different for different platforms. This means that they must be tested manually, at least once. If the x-events are stored from the manual test, they can be replayed to repeat the test when changes are made, provided the function key layout is not affected by the change. 12.S.4 Changes and benefits The most striking benefit is the level of quality of the products which is guaranteed by being able to run such a large set of tests so often. All fixes, patches, and changes are fully regression tested, not just once but at every milestone. The tests can all be re-run after the 'last' fix so that the software sent out to customers is known to be of very high quality. Automated testing is indeed at the heart of the quality system. The greatest impact from a management perspective is that time estimated for any work now always includes time to run a full regression test. Previously, estimates for development had been given by (optimistic?) developers, who did not tend to remember to include the time taken for adequate testing. For example, they may have included time to test a new feature, but may not have included regression tests or maintenance of existing tests. This led to being 'caught out' at the end of development, with time having to be extended. For example, if ten weeks were estimated for a development project, no one could accurately predict how long the testing would take or even how many tests should be run. Thus development work was not as predictable as it should have been. The biggest single change in the culture is that end dates can now be predicted with very good accuracy. This means that the planning can be done with confidence, and the whole process is much better managed. Of course, the process is not perfect, so there is occasionally a small slippage, but on the whole, things are far more predictable. An example of this was when a contractor recently finished his contract, they were able to reallocate work and know what the impact would be five months in the future. Previously it was considered pretty good to see an impact a few weeks ahead. Without the automated test system, it would be difficult to predict with this accuracy and so far into the future. Another significant benefit of the automated testing regime was when we moved to Windows NT. This has a completely different architecture to the UNIX platforms supported so far. The automated testing helped enormously; in fact, it probably would not have been possible to port to NT without it. We moved 95% of the product line to NT, and existing tests were run where possible. The porting work is now done in development before QA sees it. When the final QA of the platform was done, very few defects were found in the programs that had undergone automated testing. The defects that were found were mainly in the unique features of NT, for example pipe communication between processors.
Another benefit comes when there are a lot of minor changes for customers. It is all too easy to overlook minor changes when you are dealing with a great number of things. Autotest is a great way to find out if you've remembered them all. We have made use of filters in complex comparisons. For example, when a picture is redrawn, it must look the same to the user regardless of the order of drawing of the elements. The tool may find differences in the order of the draw instructions, but we can sort the order before doing a comparison. This feature was not actually a recent innovation, but has been improved over time. We also found it useful to build in some rounding error tolerance when moving to a 64-bit platform (Alpha). It is our policy to re-run all tests for any patch, no matter how minor. This has been very useful. In the past year, a number of defects have been found that were introduced by a fix. This is the worst thing from the customer's point of view; they report one defect only to have it replaced by another. Another problem that we used to have is worth mentioning. What used to happen was that many important customers tended to find a significant defect in the first week of using a new release. This didn't happen every time, but it was very embarrassing when it did. What we do now is to give an early release to a few selected customers worldwide. These are generally the customers who asked for a particular function that is included in the release. This early release is not a beta test; everything has gone through exactly the same quality system, so the quality is as good as we can achieve without having real users. The early adopters can then check out the release to see if they are happy, and of course they do also find some defects in the first few weeks. These defects would then be fixed with patches for each customer. All the patches are fully regression tested. After three months, a general consolidation release, incorporating all of these patches, goes out to all customers. This general release would also have been completely regression tested from program level through to system level. The majority of customers only receive the general release, but it is now higher quality than we used to be able to produce for a general release. So we have not compromised on quality, we have extended it; not only are all of the automated tests performed, but the problems that would only show up in real use are also found early, with the most serious ones being encountered first. This gives greater reliability to our customers; any defects that are found after general release are found later and are more minor. The post-release defect density for the areas that are automatically tested is now much lower than it used to be, plus the defects that are found tend to be less serious. When new enhancements are being developed, having such a large Test Suite is a great aid in stabilizing the software. We can be confident that if a new enhancement passes all the automated tests, then it will be OK. The reason for this is the high coverage that the tests achieve. A final point here is related to our organizational maturity. ISO 9001 requires us to perform defect root cause analysis. In the early days, most of
the root causes tended to be that functionality wasn't tested. Now we are identifying things earlier in the life cycle, such as problems with omissions in specifications. The problems that do slip through the net tend to be where the procedures were not followed properly, or where insufficient testing was done. 12.S.5 The current culture The quality system has a number of benchmarks or milestones: Al: Development Test Complete. Early in development, the product tests will have been planned and the test plans reviewed. The Al automated tests test each product and all changes, including tests with printers and peripherals if relevant (e.g. for driver programs) and tests on all platforms. Any defects found in running the tests go back to development to fix. The support group looks at the product from a user perspective after all of the automated tests have been run. When the developers are happy about the individual products, the Al milestone is achieved. P2: Product Test Complete. A number of software products are combined to form a release, which is tested' by QA engineers running real-user tests (manually). Any customer patches are also tested, and all previous critical defects are re-tested to insure that they are still fixed in this release. Every product must work with every other product. Some informal integration testing may be done in development before P2, e.g. to generate files in a layout editor to be handled by the route editor. If the second program cannot read the format produced by the first program, then at least it has been found early. When QA are happy about the integrated products, milestone P2 is achieved. S4: Final System Test and Integration Test Complete. All tests are run on all platforms before being put on the distribution media to be sent out to customers. A 'gold CD' of the system is produced after milestone S4 has been reached. This milestone is signed off by every manager and approved by QA. S4 is the last point at which any tests are run: any changes after this require a complete re-run of all of the S4 tests. S5: Early Adopters Release. A few copies are made and distributed to sales and support offices for local training and testing, and to the early adopters. Any patches are recorded. S6: General Release. This is where the bulk media duplication (sourced externally) of the new gold CD has been completed, before distribution to all customers. This normally comes around three months after the Early Adopters Release. Note that S4, S5, and S6 are all identical software: a CD cut at S5 is indistiguishable from one cut externally at S5; it is not a separate or different release.
There is a much better relationship between the quality department and the software developers than there used to be. Both parties are more assertive and less aggressive. QA now know they have a right to expect software of an adequate level of quality. Developers know that they have a right to be helped by QA to produce quality software. Those parts of the organization with the lowest standards (and the least test automation) are the parts that currently have the greatest conflict with QA. When changes are requested to the software, the impact on the automated Test Suites is now a serious influence on whether or not that change will be approved. For example, a requested customer enhancement might take only a few weeks to develop but it might take months to test. It may be more expensive to change a user interface than to add a new feature. This is because the user interface would need to be changed in many existing test cases, while adding a new feature would result mainly in new tests being added, and fewer changes to existing test cases. Because test estimates are always included in any development estimate, these also include the test maintenance impact. So there may have been features that were not developed because the effort to test was too great. One example is that the redevelopment of the user interface to the PCB products has probably been delayed because of the impact of the proposed changes on the tests, which had many person-years invested in them. We would like to be able to work at a scripting level that is closer to the changes the users have made, rather than being concerned with what buttons they pressed. Company policy is now that all software engineers write automated tests for all platforms. Every fix requires a set of automated tests for all platforms before it is accepted. In the early days of test automation there was great resistance from developers, not only in the use of the tool, but also in perceiving that testing should be part of their job. Now it is an accepted part of the culture that developers must write tests for any software that they develop. The advertisements for new staff mention test automation as a key feature of the job.
References BOULDIN , BARBARA
(1989) Agents of Change: Managing the Introduction of Automated Tools. Prentice Hall, Englewood Cliff, NJ. MYERS, GLENFORD (1979)
The Art of Software Testing. Wiley, New York. ©
Mark Fewster and Keiron Marsden, 1999.
The evolution of an automated software test system Marnie Hutcheson
13.1 Introduction This case study is a rare breed: it admits to less than total success, at least at first. The reasons why a good tool fell into disuse (twice), and the ultimate lessons learned make fascinating reading for anyone who wants to automate testing successfully. This case study was originally written in 1992, and describes Marnie Hutcheson's experiences at Prodigy, where she was working at the time. She has developed the excellent test management method MITs (Most Important Tests) partly as a result of her experiences described in this case study. She now runs two companies, Prosys and Ideva, the former involved in test consultancy, and the latter in internet and intranet development and training. Her book Software Testing Method and Metrics will be published by McGraw-Hill. This chapter was originally published in the proceedings of the Ninth International Conference on Testing Computer Software (ITEA and ASQC). The tool described in this chapter no longer exists. The application which it tested, an on-line shopping system, was superseded by internet technology. However, the lessons learned are still relevant.
13.2 Background Prodigy Services Company developed a wide variety of software that was required to run on many diverse platforms. Consequently many types of software and hardware test tools were used to test the PRODIGY service. The Gremlin Automated Test System began in 1988 as a set of PC-based test script automation tools used primarily to test applications on the PRODIGY service. It was eventually developed to automate many testing
tasks in addition to capture replay and it has been used to test many types of software across the Prodigy network. Many changes have been implemented, both in the test system and in our thinking. Possibly the most important lesson learned in this process is that it takes a lot more than test tools to make test automation succeed. There must be some reliable method for using the tools to insure the quality of the testing that is done.
13.3 Gremlin 1 13.3.1 Features The first financial application on the PRODIGY service took a year to develop and a year to test. Management wanted the next four financial applications completed and online in 16 months. The schedule called for considerable overlap in the implementation and testing of the applications. Gremlin 1, a script automation test system, was developed in six months in order to allow testers to meet the schedule. The toolset utilized existing internal capture replay and image capture technology where possible. The system functioned as a non-intrusive operator emulator, running on the same machine as the application being tested, and allowed users to: • capture keystrokes and screen images; • build suites from captured key trace scripts; • re-run Test Suites and capture test images; a compare test images to master images and write a report (showing the number of mismatched pixels). Additionally, an image viewer was developed which allowed the user to view first the captured master image, then the captured test image, and finally the test image superimposed on the master image. The superimposi-tion image highlighted the differences between the master and test images and blanked out the areas that matched.
13.3.2 Gremlin 1 achievements The financial applications test groups were able to automate 80% of their testing with the Gremlin system. Gremlin was given to the client financial institutions, and in many cases they used it in both the system test effort and the user acceptance test effort. Automated testing reduced the system test cycle for a financial application at Prodigy Services Company to one month. The entire test cycle, for Prodigy and the financial client, was reduced to less than three months. Not only was the testing of the new financial applications completed on time, it was possible for the tester to perform regression testing while engaged in other work. It was also possible to use the Gremlin system to monitor the health of the existing applications on the live PRODIGY service.
13.33 The rise and fall of Gremlin 1 Gremlin 1 was made generally available to Prodigy employees and Prodigy's clients in March 1989. Within eight months of its introduction, the automated test system had 56 registered internal users and 15 external users. The usership was split almost equally between development groups, the Systems and Application Test (S&AT) group, and various non-technical groups performing user acceptance testing. However, 18 months later it was discovered that fewer than 20 of the 71 registered Gremlin 1 users were still using the system in their testing. Most of the active users were in the S&AT group. Even the development group for which the system had initially been developed was no longer using the system to test financial applications. The ex-users had not replaced the Gremlin system with other automation tools; they had apparently just stopped using test automation. The usage is shown in Figure 13.1. 13.3.4 Causes for the decline in use of Gremlin 1 A survey was taken of the users and ex-users of Gremlin 1. The reasons for the decline in use fell into two distinct groups: those related to testing in general, and those related to tool functions. 13.3.4.1
General testing problems
Many of those surveyed were concerned about general testing issues, such as: » » » «
Where do I start? How do 1 design my test scripts? How do I know what to test? How do I know when I have tested enough?
The tools were not expected to supply answers to these questions, yet these were the problems which people were struggling with. This was something of a surprise, and clearly showed the need for some kind of education or class to teach software testing as a discipline. We did not yet realize the true significance of this finding. 13.3.4.2 System/tool deficiencies There were also a number of technical problems identified in Gremlin 1. This is not surprising for the first release of what was at the time very new technology. (In 1988/9 the commercial testing tool market was only just getting started.) The following deficiencies were highlighted by the survey: •
Interface problems. Gremlin 1 was text-based rather than a mousedriven graphical user interface. Users had to type in many hard-to-remember filenames with paths. If they made a mistake, they had to start that operation again at the beginning. Can't drive my application. Gremlin could only drive key traces through the user interface of the PRODIGY system. Validation. Gremlin 1 only did screen image comparison, and didn't allow masking out areas of the screen, or the comparison of files or messages. Environment. Set-up and clear-up had to be done manually. For exam ple, if a certain file had to be in a certain directory at the start of each script, the tester would have to place it there manually before the auto mated test could be run, and similarly for clear-up tasks. Not only were these types of operations time consuming, they were also difficult to document and were easily overlooked. An entire run of a Test Suite could be wasted if the correct environment was not in place. Test scripts hard to edit. Testers had to know what each keystroke and mouse movement did before they could edit a key trace. The scripts required correct syntax and case in both mnemonics and commands. Any edited script then had to be tested and debugged. Key traces hard to include in test documentation. Testers had to format and manually copy key trace scripts in order to include them in their documents. Test scripts quickly outdated. Many elements were 'hard-coded' into the scripts, for example menu option numbers, which gave them a short life expectancy. This promoted the view that key traces were 'disposable' and not worth documenting or maintaining. Consequently testers were continually retyping key traces instead of replaying them. What does this key trace test? Typically, no one but the tester who cre ated a key trace had enough confidence in its validity to use it. Even if descriptive 'comments' were edited into a key trace, they couldn't easily be reproduced in any documentation.
» What does this key trace need to run? There was no mechanism for recording or managing physical environment requirements, making it impossible to say for sure if it had tested what it was supposed to test. » No conditional logic in key traces. Our initial scripting language did not include an 'if construct, so if a test failed, little automated recovery was possible. None of these problems will come as a surprise to anyone who has used the earliest commercial capture replay tools. The conclusion seemed clear, however: we needed a better tool.
13.4 Gremlin 2,0: a step beyond capture replay Gremlin 2.0, a prototype, was introduced in October 1990. It provided a platform approach to testing rather than the isolated tool approach. The system provided a number of automated services in addition to capture replay. 13.4.1 Gremlin 2.0 features 13.4.1.1 All new interface
All the tools featured a mouse-driveable, graphical user interface with online help. With the new interface, the user was able to select operations and filenames. The need to remember long filenames and path names or arcane commands was virtually eliminated. 13.4.1.2 Script macros
Script macros were implemented to solve the problems associated with the short life of key traces. A script macro is actually a title that represents a key trace segment. The title is inserted in the script instead of the key trace segment. At runtime the macro title is expanded into the set of keystrokes that it represents. An example is given below. Macro Title: Log On Macro Text: ABCD01APWORD<ENTER>
<SNAPSHOT:>
A sample test script using macros is shown below:
Software Test Automation (ACM Press)
Experiences of Test Automation: Case Studies of Software Test Automation
Effective Software Test Automation: Developing an Automated Software Testing Tool
Modern Industrial Automation Software Design
Happy About Global Software Test Automation: A Discussion of Software Testing for Executives
Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation
A Practitioner's Guide to Software Test Design
How We Test Software at Microsoft
Electronic Design Automation: Synthesis, Verification, and Test (Systems on Silicon)
NET Test Automation Recipes: A Problem-Solution Approach
Effective GUI Test Automation: Developing an Automated GUI Testing Tool
Pragmatic Software Testing: Becoming an Effective and Efficient Test Professional
Lean-Agile Acceptance Test-Driven Development: Better Software Through Collaboration
Professional Software Testing with Visual Studio 2005 Team System: Tools for Software Developers and Test Engineers
Handbook Of Industrial Automation
ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Effective Software Test Automation: Devel...
Modern Industrial Automation Sofhvare Design Principles and Real- World Applications Lingfeng Wang Kay Chen Tan IEEE ...
"Software is complex but I'm tired of finding bug after bug that a 5th grader wouldn't have turned in. Virtually every t...
Praise for Continuous Delivery "If you need to deploy software more frequently, this book is for you. Applying it will ...
How We Test Software at Microsoft Alan Page Ken Johnston Bj Rollison PUBLISHED BY Microsoft Press A Division of Microso...
Electronic Design Automation The Morgan Kaufmann Series in Systems on Silicon Series Editor Wayne Wolf Georgia Insti...
Report "Software test automation"