Python Testing Cookbook


Python Testing Cookbook
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$22.94
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • Learn to write tests at every level using a variety of Python testing tools
  • The first book to include detailed screenshots and recipes for using Jenkins continuous integration server (formerly known as Hudson)
  • Explore innovative ways to introduce automated testing to legacy systems
  • Written by Greg L. Turnquist – senior software engineer and author of Spring Python 1.1
  • Part of Packt's Cookbook series: Each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible

Book Details

Language : English
Paperback : 364 pages [ 235mm x 191mm ]
Release Date : May 2011
ISBN : 1849514666
ISBN 13 : 9781849514668
Author(s) : Greg L. Turnquist
Topics and Technologies : All Books, App Testing, Application Development, Cookbooks, Open Source

Table of Contents

Preface
Chapter 1: Using Unittest To Develop Basic Tests
Chapter 2: Running Automated Test Suites with Nose
Chapter 3: Creating Testable Documentation with doctest
Chapter 4: Testing Customer Stories with Behavior Driven Development
Chapter 5: High Level Customer Scenarios with Acceptance Testing
Chapter 6: Integrating Automated Tests with Continuous Integration
Chapter 7: Measuring your Success with Test Coverage
Chapter 8: Smoke/Load Testing—Testing Major Parts
Chapter 9: Good Test Habits for New and Legacy Systems
Index
  • Chapter 1: Using Unittest To Develop Basic Tests
    • Introduction
    • Asserting the basics
    • Setting up and tearing down a test harness
    • Running test cases from the command line with increased verbosity
    • Running a subset of test case methods
    • Chaining together a suite of tests
    • Defining test suites inside the test module
    • Retooling old test code to run inside unittest
    • Breaking down obscure tests into simple ones
    • Testing the edges
    • Testing corner cases by iteration
    • Chapter 2: Running Automated Test Suites with Nose
      • Introduction
      • Getting nosy with testing
      • Embedding nose inside Python
      • Writing a nose extension to pick tests based on regular expressions
      • Writing a nose extension to generate a CSV report
      • Writing a project-level script that lets you run different test suites
      • Chapter 3: Creating Testable Documentation with doctest
        • Introduction
        • Documenting the basics
        • Catching stack traces
        • Running doctests from the command line
        • Coding a test harness for doctest
        • Filtering out test noise
        • Printing out all your documentation including a status report
        • Testing the edges
        • Testing corner cases by iteration
        • Getting nosy with doctest
        • Updating the project-level script to run this chapter's doctests
        • Chapter 4: Testing Customer Stories with Behavior Driven Development
          • Introduction
          • Naming tests that sound like sentences and stories
          • Testing separate doctest documents
          • Writing a testable story with doctest
          • Writing a testable novel with doctest
          • Writing a testable story with Voidspace
          • Mock and nose
          • Writing a testable story with mockito and nose
          • Writing a testable story with Lettuce
          • Using Should DSL to write succinct assertions with Lettuce
          • Updating the project-level script to run this chapter's BDD tests
          • Chapter 5: High Level Customer Scenarios with Acceptance Testing
            • Introduction
            • Installing Pyccuracy
            • Testing the basics with Pyccuracy
            • Using Pyccuracy to verify web app security
            • Installing the Robot Framework
            • Creating a data-driven test suite with Robot
            • Writing a testable story with Robot
            • Tagging Robot tests and running a subset
            • Testing web basics with Robot
            • Using Robot to verify web app security
            • Creating a project-level script to verify this chapter's acceptance tests
            • Chapter 6: Integrating Automated Tests with Continuous Integration
              • Introduction
              • Generating a continuous integration report for Jenkins using NoseXUnit
              • Configuring Jenkins to run Python tests upon commit
              • Configuring Jenkins to run Python tests when scheduled
              • Generating a CI report for TeamCity using teamcity-nose
              • Configuring TeamCity to run Python tests upon commit
              • Configuring TeamCity to run Python tests when scheduled
              • Chapter 7: Measuring your Success with Test Coverage
                • Introduction
                • Building a network management application
                • Installing and running coverage on your test suite
                • Generating an HTML report using coverage
                • Generating an XML report using coverage
                • Getting nosy with coverage
                • Filtering out test noise from coverage
                • Letting Jenkins get nosy with coverage
                • Updating the project-level script to provide coverage reports
                • Chapter 8: Smoke/Load Testing—Testing Major Parts
                  • Introduction
                  • Defining a subset of test cases using import statements
                  • Leaving out integration tests
                  • Targeting end-to-end scenarios
                  • Targeting the test server
                  • Coding a data simulator
                  • Recording and playing back live data in real time
                  • Recording and playing back live data as fast as possible
                  • Automating your management demo
                  • Chapter 9: Good Test Habits for New and Legacy Systems
                    • Introduction
                    • Something is better than nothing
                    • Coverage isn't everything
                    • Be willing to invest in test fixtures
                    • If you aren't convinced on the value of testing, your team won't be either
                    • Harvesting metrics
                    • Capturing a bug in an automated test
                    • Separating algorithms from concurrency
                    • Pause to refactor when test suite takes too long to run
                    • Cash in on your confidence
                    • Be willing to throw away an entire day of changes
                    • Instead of shooting for 100 percent coverage, try to have a steady growth
                    • Randomly breaking your app can lead to better code

                    Greg L. Turnquist

                    Greg has worked since 1997 as a software engineer at Harris Corporation, always seeking the right tool for the job. Since 2002, Greg has been part of the senior software team working on Harris' $3.5 billion FAA telco program, architecting mission-critical enterprise apps while managing a software team. He provides after hours support and 2nd-level engineering to support the nation-wide telco network and is no stranger to midnight failures and software triage. In 2010, Greg joined the SpringSource division of VMware.

                    Being a test-bitten script junky, Greg has used JUnit, TestNG, JMock, FEST, PyUnit, and pMock testing frameworks, along with other agile practices to produce top-quality code.

                    He has worked with Java, Spring, Spring Security, AspectJ, and Jython technologies and also developed sophisticated scripts for *nix and Windows platforms. Being a wiki evangelist, he also deployed a LAMP-based wiki website to provide finger-tip knowledge to users.

                    In 2006, Greg created the Spring Python project. The Spring Framework provided many useful features, and he wanted those same features available when working with Python.

                    Greg completed a master's degree in Computer Engineering at Auburn University, and lives in the United States with his family.

                    Code Downloads

                    Download the code and support files for this book.


                    Submit Errata

                    Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                    Errata

                    - 6 submitted: last submission 09 Jun 2014

                    Errata type: Others | Page number: 15

                    For this recipe, the tests have been deliberately coded to fail.
                    This should be: For this recipe, the second test has been deliberately coded to fail.

                    Errata type: Typo | Page number: 79

                    """Convert a base10 number to basen.edur SHOULD BE: """Convert a base10 number to basen

                     

                    p>Errata type: Typo | Page number: 97

                     

                    Page 97 Start creating a script by importing Python's inspect library as the basis for drilling down into a module from inspect import* SHOULD BE: Start creating a script by importing Python's inspect library as the basis for drilling down into a module. from inspect import*

                     

                    Errata type: Technical | Page number: 18

                    The tip on this page is revised to make it clear as follows:

                    Python 2.6 doesn't have the built-in ability to pick and precise test methods from the command line, out of the box, which is what makes this recipe useful.


                    Python 2.6 doesn't have the ability to pick and choose precise test methods from the command line, which makes this recipe useful. If we are using Python 2.7, we can find details about the new Command-Line Interface section on Python Documentation. That page documents how to use the command-line interface to run individual methods. But this isn't available if we need to support multiple versions of Python, making this recipe handy.

                     

                    Errata type: Code | Page number: 55

                    The final portion of code, underneath the sentence beginning with "Write a
                    test runner...", there are two identical lines with the same mistake.
                    IS:
                    "nose.run(argv=args, plugin=[RegexPicker()]"
                    SHOULD BE:
                    "nose.run(argv=args, plugins=[RegexPicker()]" 

                    Page: 54 | Type: Technical 

                    "5. Create a new file called recipe15_plugin.py to..."

                    SHOULD BE:

                    "5. Create a new file called recipe13_plugin.py to..." 

                    Sample chapters

                    You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                    Frequently bought together

                    Python Testing Cookbook +    Bazaar Version Control =
                    50% Off
                    the second eBook
                    Price for both: €30.90

                    Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                    What you will learn from this book

                    • Get started with the basics of writing automated unit tests and asserting results
                    • Use Nose to discover tests and build suites automatically
                    • Write Nose plugins that control what tests are discovered and how to produce test reports
                    • Add testable documentation to your code
                    • Filter out test noise, customize test reports, and tweak doctest's to meet your needs
                    • Write testable stories using lots of tools including doctest, mocks, Lettuce, and Should DSL
                    • Get started with the basics of customer-oriented acceptance testing
                    • Test the web security of your application
                    • Configure Jenkins and TeamCity to run your test suite upon check-in
                    • Capture test coverage reports in lots of formats, and integrate with Jenkins and Nose
                    • Take the pulse of your system with a quick smoke test and overload your system to find its breaking points
                    • Add automated testing to an existing legacy system that isn't test oriented

                     

                    In Detail

                    Are you looking at new ways to write better, more efficient tests? Are you struggling to add automated testing to your existing system? The Python unit testing framework, originally referred to as "PyUnit" and now known as unittest, is a framework that makes it easier for you to write automated test suites efficiently in Python. This book will show you exactly how to squeeze every ounce of value out of automated testing.

                    The Python Testing Cookbook will empower you to write tests using lots of Python test tools, code samples, screenshots, and detailed explanations. By learning how and when to write tests at every level, you can vastly improve the quality of your code and your personal skill set. Packed with lots of test examples, this will become your go-to book for writing good tests.

                    This practical cookbook covers lots of test styles including unit-level, test discovery, doctest, BDD, acceptance, smoke, and load testing. It will guide you to use popular Python tools effectively and discover how to write custom extensions. You will learn how to use popular continuous integration systems like Jenkins (formerly known as Hudson) and TeamCity to automatically test your code upon check in. This book explores Python's built-in ability to run code found embedded in doc strings and also plugging in to popular web testing tools like Selenium. By the end of this book, you will be proficient in many test tactics and be ready to apply them to new applications as well as legacy ones.

                     

                    A practical guide, this cookbook will ensure you fully utilize Python testing tools to write tests efficiently

                    Approach

                    This cookbook is written as a collection of code recipes containing step-by-step directions on how to install or build different types of Python test tools to solve different problems. Each recipe contains explanations of how it works along with answers to common questions and cross references to other relevant recipes. The easy-to-understand recipe names make this a handy test reference book.

                    Who this book is for

                    Python developers and programmers with a basic understanding of Python and Python testing will find this cookbook beneficial. It will build on that basic knowledge equipping you with the intermediate and advanced skills required to fully utilize the Python testing tools. Broken up into lots of small code recipes, you can read this book at your own pace, whatever your experience. No prior experience of automated testing is required.

                    Code Download and Errata
                    Packt Anytime, Anywhere
                    Register Books
                    Print Upgrades
                    eBook Downloads
                    Video Support
                    Contact Us
                    Awards Voting Nominations Previous Winners
                    Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                    Resources
                    Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software