Python Testing Cookbook
Second Edition
Easy solutions to test your Python projects using test-driven development and Selenium
Greg L. Turnquist
Bhaskar N. Das
BIRMINGHAM - MUMBAI
Python Testing CookbookSecond Edition
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Merint Matthew
Acquisition Editor: Chaitanya Nair
Content Development Editor: Rohit Singh
Technical Editor: Romy Dias
Copy Editor: Safis Editing
Project Coordinator: Vaidehi Sawant
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Graphics: Jason Monteiro
Production Coordinator: Deepika Naik
First published: May 2011
Second edition: June 2018
Production reference: 1290618
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
978-1-78712-252-9
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the authors
Greg L. Turnquist has worked in the software industry since 1997. He is an active participant in the open source community and has contributed patches to several projects, including MythTV, Spring Security, MediaWiki, and the TestNG Eclipse plugin. As a test-obsessed script junky, he has always sought the right tool for the job. He is a firm believer in agile practices and automated testing. He has developed distributed systems and LAMP-based setups, and he has supported mission-critical systems hosted on various platforms.
After graduating from Auburn University with a master's in computer engineering, Greg started working with the Harris Corporation. He worked on many contracts utilizing many types of technology. In 2006, he created the Spring Python project and went on to write Spring Python 1.1 in 2010. He joined SpringSource, a division of VMware in 2010, as part of its international software development team.
Bhaskar N. Das has 8 years' experience in various projects involving application development, maintenance, and support with IBM. He has worked in various technologies and domains including Java, Python, application servers, the cloud, and various database technologies. His domain expertise includes finance and asset management (IT and finance assets). His areas of interest include big data, business finance optimization and scaling, data science, and Machine Learning.
About the reviewers
Maurice HT Ling is a Research Assistant Professor at the Perdana University School of Data Sciences. He obtained his BSc.(Hons.) in Molecular and Cell Biology from The University of Melbourne, Australia, in 2004, and his BSc. in Computing from the University of Portsmouth, United Kingdom, in 2007, before obtaining his Ph.D. in Bioinformatics from The University of Melbourne, Australia, in 2009. He is a bioinformatician who is currently working on looking at evolutionary biology and various aspects of life. His main techniques involve experimental evolution and simulations, such as artificial life simulation, for accessing evolutionary perspectives, and using existing published data. He has developed computational algorithms as part of this research. He has a wide range of other interests, including professional and social aspects of science and education, and studies this area using autoethnographical and autobiographical methods. He co-founded Python User Group (Singapore), and has been instrumental in inaugurating PyCon Asia-Pacific as one of the 3 major Python conferences worldwide, together with PyCon US and EuroPython. On the commercial side, he is the principal partner of Colossus Technologies LLP, Singapore. In his free time, he likes to read, enjoy a cup of coffee, writing his personal journal, or philosophizing on various aspects of life.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
Testing has always been part of software development. For decades, comprehensive testing was defined by complex manual test procedures backed by big budgets; but something revolutionary happened in 1998. In his Guide to Better Smalltalk, Smalltalk guru, Kent Beck, introduced an automated test framework called SUnit. This triggered an avalanche of test frameworks, including JUnit, PyUnit, and many others for different languages and various platforms, dubbed the xUnit movement. Automated testing was made a cornerstone of the agile movement when the top 17 software experts signed the Agile Manifesto in 2001.
Testing includes many different styles, including unit testing, integration testing, acceptance testing, smoke testing, load testing, and countless others. This book delves deeper and explores testing at all the important levels while using the nimble power of Python. It also demonstrates many tools.