100% found this document useful (2 votes)
17 views

Python Testing Cookbook Easy solutions to test your Python projects using test driven development and Selenium 2nd Edition Greg L. Turnquist & Bhaskar N. Das - Download the ebook today and own the complete version

The document promotes various eBooks related to Python testing and test-driven development available for download at textbookfull.com. It includes titles such as 'Python Testing Cookbook' and 'Test Driven Development with Python', authored by notable figures in the field. Additionally, it provides information about the authors, publication details, and a brief overview of the content covered in these books.

Uploaded by

hevoscambai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
17 views

Python Testing Cookbook Easy solutions to test your Python projects using test driven development and Selenium 2nd Edition Greg L. Turnquist & Bhaskar N. Das - Download the ebook today and own the complete version

The document promotes various eBooks related to Python testing and test-driven development available for download at textbookfull.com. It includes titles such as 'Python Testing Cookbook' and 'Test Driven Development with Python', authored by notable figures in the field. Additionally, it provides information about the authors, publication details, and a brief overview of the content covered in these books.

Uploaded by

hevoscambai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Explore the full ebook collection and download it now at textbookfull.

com

Python Testing Cookbook Easy solutions to test


your Python projects using test driven development
and Selenium 2nd Edition Greg L. Turnquist &
Bhaskar N. Das
https://textbookfull.com/product/python-testing-cookbook-
easy-solutions-to-test-your-python-projects-using-test-
driven-development-and-selenium-2nd-edition-greg-l-
turnquist-bhaskar-n-das/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Test Driven Development with Python Obey the Testing Goat


Using Django Selenium and JavaScript 2nd Edition Harry J.
W. Percival
https://textbookfull.com/product/test-driven-development-with-python-
obey-the-testing-goat-using-django-selenium-and-javascript-2nd-
edition-harry-j-w-percival/
textbookfull.com

Python Testing with Selenium: Learn to Implement Different


Testing Techniques Using the Selenium WebDriver Sujay
Raghavendra
https://textbookfull.com/product/python-testing-with-selenium-learn-
to-implement-different-testing-techniques-using-the-selenium-
webdriver-sujay-raghavendra/
textbookfull.com

Thoughtful machine learning with Python a test driven


approach First Edition Kirk

https://textbookfull.com/product/thoughtful-machine-learning-with-
python-a-test-driven-approach-first-edition-kirk/

textbookfull.com

Thoughtful Machine Learning with Python A Test Driven


Approach 1st Edition Matthew Kirk

https://textbookfull.com/product/thoughtful-machine-learning-with-
python-a-test-driven-approach-1st-edition-matthew-kirk/

textbookfull.com
iOS Test Driven Development by Tutorials First Edition
Learn Real World Test Driven Development Joshua Greene

https://textbookfull.com/product/ios-test-driven-development-by-
tutorials-first-edition-learn-real-world-test-driven-development-
joshua-greene/
textbookfull.com

Test Driven Development in Ruby A Practical Introduction


to TDD Using Problem and Solution Domain Analysis Paranj

https://textbookfull.com/product/test-driven-development-in-ruby-a-
practical-introduction-to-tdd-using-problem-and-solution-domain-
analysis-paranj/
textbookfull.com

Python Unit Test Automation. Practical Techniques for


Python Developers and Testers 1st Edition Ashwin Pajankar

https://textbookfull.com/product/python-unit-test-automation-
practical-techniques-for-python-developers-and-testers-1st-edition-
ashwin-pajankar/
textbookfull.com

Test Driven Java Development Invoke TDD principles for end


to end application development 2nd Edition Alex Garcia

https://textbookfull.com/product/test-driven-java-development-invoke-
tdd-principles-for-end-to-end-application-development-2nd-edition-
alex-garcia/
textbookfull.com

Test Driven Java Development 1st Edition Farcic Viktor


Garcia Alex

https://textbookfull.com/product/test-driven-java-development-1st-
edition-farcic-viktor-garcia-alex/

textbookfull.com
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 Cookbook
Second 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
[email protected] 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 autho
rs.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
Title Page

Copyright and Credits

Python Testing Cookbook Second Edition

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the authors

About the reviewers

Packt is searching for authors like you


Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Conventions used

Sections

Getting ready

How to do it…

How it works…

There's more…

See also

Get in touch

Reviews
1. Using Unittest to Develop Basic Tests

Introduction

Asserting the basics

Getting ready

How to do it...

How it works...

There's more...

assertEquals is preferred over assertTrue and assertFalse

self.fail([msg]) can usually be rewritten with assertions

Our version of Python can impact our options

Setting up and tearing down a test harness

How to do it...

How it works...

Running test cases from the command line

How to do it...

How it works...

There's more...

Running a subset of test case methods

How to do it...

How it works...

Chaining together a suite of tests

How to do it...

How it works...
There's more...

The name of the test case should be significant


Defining test suites inside the test module

How to do it...
How it works...

There's more...
Test suite methods must be outside of the test class

Why have different suites?


optparse is being phased out and replaced by argparse

Retooling old test code to run inside unittest


How to do it...

How it works...
There's more...
Where are the bugs?
FunctionTestCase is a temporary measure

Breaking down obscure tests into simple ones


How to do it...

How it works...
There's more...

Where is the bug?


What is the right size for a test method?

Unittests versus integration tests


Testing the edges

How to do it...
How it works...

There's more...
Identifying the edges is important

Testing for unexpected conditions


Testing corner cases by iteration

How to do it...
How it works...

There's more...
Does this defy the recipe – breaking down obscure

tests into simple ones?


How does this compare with the recipe – testing th

e edges?
See also
2. Running Automated Test Suites with Nose
Introduction

Getting nosy with testing


How to do it...

How it works...
There's more...
Nose is extensible

Nose is embeddable
See also
Embedding nose inside Python
How to do it...

How it works...
There's more...
Writing a nose extension to pick tests based on regular expressions
Getting ready

How to do it...
How it works...
There's more...
Writing a nose extension to generate a CSV report

Getting ready
How to do it...
How it works...
There's more...

Writing a project-level script that lets you run different test suites
How to do it...
How it works...
There's more...

Why use getopt instead of optparse?


3. Creating Testable Documentation with doctest
Introduction
Documenting the basics

How to do it...
How it works...
There's more...

Catching stack traces


How to do it...
How it works...
Running a doctest from the command line

How to do it...
How it works...
Coding a test harness for doctest
How to do it...

How it works...
There's more...
Filtering out test noise
How to do it...

How it works...
There's more...
Printing out all your documentation including a status report
How to do it...

How it works...
There's more...
Testing the edges
How to do it...

How it works...
There's more...
See also
Testing corner cases by iteration

How to do it...
How it works...
Does this type of test fit better into doctest or unittest?
See also

Getting nosy with doctest


Getting ready
How to do it...
How it works...

Updating the project-level script to run this chapter's doctests


How to do it...
How it works...
There's more...
4. Testing Customer Stories with Behavior-Driven Development
Introduction

Naming tests that sound like sentences and stories


Getting ready
How to do it...
How it works...

There's more...
Testing separate doctest documents
Getting ready 
How to do it...

How it works...
There's more...

Doesn't this defy the usability of docstrings?

Writing a testable story with doctest


Getting ready

How to do it...

How it works...
There's more...

Writing a testable novel with doctest


Getting ready

How to do it...

How it works...
There's more...

Writing a testable story with Voidspace Mock and nose

Getting ready
How to do it...

How it works...
There's more...

Tell me more about the spec nose plugin!

Why didn't we reuse the plugin from the recipe "Naming tests s
o they sound like sentences and stories"?

See also

Writing a testable story with mockito and nose


Getting ready

How to do it...
How it works...
See also

Writing a testable story with Lettuce


Getting ready...

How to do it...

How it works...
There's more...

How complex should a story be?


Don't mix wiring code with application code

Lettuce works great using folders

See also
Using Should DSL to write succinct assertions with Lettuce

Getting ready

How to do it...
How it works...

There's more...
See also

Updating the project-level script to run this chapter's BDD tests

Getting ready
How to do it...

How it works...

See also
5. High-Level Customer Scenarios with Acceptance Testing
Introduction

Installing Pyccuracy

How to do it...
How it works...

See also
Testing the basics with Pyccuracy

Getting ready

How to do it...
How it works...

There's more...

See also
Using Pyccuracy to verify web app security

Getting ready
How to do it...

How it works...

See also
Installing Robot Framework

How to do it...

There's more...
Creating a data-driven test suite with Robot Framework

Getting ready
How to do it...

How it works...

There's more...
Do I have to write HTML tables?

What are the best ways to write the code that implements our c

ustom keywords?
Robot Framework variables are Unicode

See also
Writing a testable story with Robot Framework

Getting ready

How to do it...
How it works...

There's more...

Given-When-Then results in duplicate rules


Do the try-except blocks violate the idea of keeping things li

ght?
See also

Tagging Robot Framework tests and running a subset

Getting ready
How to do it...

How it works...

There's more...
What about documentation?

See also
Testing web basics with Robot Framework

Getting ready...

How to do it...
How it works...

There's more...

Learn about timing configurations – they may be im


portant!

See also
Using Robot Framework to verify web app security

Getting ready

How to do it...
How it works...

There's more...

Why not use a "remember me" option?


Shouldn't we refactor the first test scenario to use the keywo

rd?
Would arguments make the login keyword more flexible?

See also

Creating a project-level script to verify this chapter's acceptance tests


Getting ready

How to do it...

How it works...
There's more

Can we only use getopt?


What's wrong with using the various command-line tools?
6. Integrating Automated Tests with Continuous Integration
Introduction

Generating a CI report for Jenkins using NoseXUnit

Getting ready
How to do it...

How it works...
Configuring Jenkins to run Python tests upon commit

Getting ready

How to do it...
How it works...

There's more...

Do I have to use git for source code management?


What is the format of polling?

See also
Configuring Jenkins to run Python tests when scheduled

Getting ready

How to do it...
How it works...

There's more...

Jenkins versus TeamCity


See also

Generating a CI report for TeamCity using teamcity-nose


Getting ready

How to do it...

How it works...
Configuring TeamCity to run Python tests upon commit

Getting ready

How to do it...
How it works...

There's more...
What did teamcity-nose give us?

See also

Configuring TeamCity to run Python tests when scheduled


Getting ready

How to do it...

How it works...
See also
7. Measuring Your Success with Test Coverage
Introduction

Building a network management application

How to do it...
How it works...

Installing and running coverage on your test suite

How to do it...
There's more...

Why are there no asserts in unittest?


Generating an HTML report using coverage

How to do it...

How it works...
Generating an XML report using coverage

How to do it...

How it works...
What use is an XML report?

See also
Getting nosy with coverage

How to do it...

How it works...
There's more...

Why use the nose plugin instead of the coverage tool directly?

Why are SQLite3 and Spring Python included?


Filtering out test noise from coverage

How to do it...

How it works...

There's more...
See also

Letting Jenkins get nosy with coverage

Getting ready

How to do it...

How it works...
There's more...

Nose doesn't directly support coverage's XML option

Updating the project-level script to provide coverage reports

Getting ready
How to do it...
How it works...

There's more...

Can we only use getopt?


8. Smoke/Load Testing – Testing Major Parts

Introduction

Defining a subset of test cases using import statements


How to do it...

How it works...

There's more...

Security, checking, and integration aren't smoke tests!

What provides good flexibility?


See also

Leaving out integration tests

How to do it...

How it works...

There's more...
Should a smoke test include integration or unit tests?

See also

Targeting end-to-end scenarios

Getting ready

How to do it...

How it works...
There's more...

How does this define smoke tests?

See also

Targeting the test server

Getting ready
How to do it...

How it works...

There's more...

How likely is it that a development and production environment

would use two different database systems?

This isn't just confined to database systems


Coding a data simulator

Getting ready

How to do it...

How it works...

There's more...
Why does the server script initialize the database?
Another Random Document on
Scribd Without Any Related Topics
back
back
back
back
back
back
back
back
back
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like