Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing

Book description

Fundamental testing methodologies applied to the popular Python language

Testing Python; Applying Unit Testing, TDD, BDD and Acceptance Testing is the most comprehensive book available on testing for one of the top software programming languages in the world. Python is a natural choice for new and experienced developers, and this hands-on resource is a much needed guide to enterprise-level testing development methodologies. The book will show you why Unit Testing and TDD can lead to cleaner, more flexible programs.

Unit Testing and Test-Driven Development (TDD) are increasingly must-have skills for software developers, no matter what language they work in. In enterprise settings, it's critical for developers to ensure they always have working code, and that's what makes testing methodologies so attractive. This book will teach you the most widely used testing strategies and will introduce to you to still others, covering performance testing, continuous testing, and more.

  • Learn Unit Testing and TDD—important development methodologies that lie at the heart of Agile development

  • Enhance your ability to work with Python to develop powerful, flexible applications with clean code

  • Draw on the expertise of author David Sale, a leading UK developer and tech commentator

  • Get ahead of the crowd by mastering the underappreciated world of Python testing

  • Knowledge of software testing in Python could set you apart from Python developers using outmoded methodologies. Python is a natural fit for TDD and Testing Python is a must-read text for anyone who wants to develop expertise in Python programming.

    Table of contents

      1. Introduction
      2. Chapter 1: A History of Testing
        1. You Do Test, Don’t You?
        2. Fundamentals and Best Practices
          1. Python Installation
          2. Pip
          3. Virtualenv
          4. Source Control (SVN, Git)
          5. Interactive Development Environment (IDE)
        3. Summary
      3. Chapter 2: Writing Unit Tests
        1. What Is Unit Testing?
        2. What Should You Test?
        3. Writing Your First Unit Test
          1. Checking Values with the assertEquals Method
          2. Checking Exception Handling with assertRaises
        4. Following the PEP-8 Standard
        5. Unit Test Structure
        6. Additional Unit Test Examples
          1. Getting Clever with assertRaises
          2. Making Your Life Easier with setUp
        7. Useful Methods in Unit Testing
        8. Summary
      4. Chapter 3: Utilizing Unit Test Tools
        1. Using Python’s Nose
          1. Installing Nose
          2. Using Nose’s Best Features
        2. PyTest: An Alternative Test Runner
          1. Installing PyTest
          2. PyTest’s Best Features
          3. Choosing Between Nose and PyTest
        3. Mock and Patch Tricky Situations
          1. Installing the Mock Library
          2. Mocking a Class and Method Response
          3. When Mock Won’t Do, Patch!
        4. Summary
      5. Chapter 4: Writing Testable Documentation
        1. Writing Your First Doctest
          1. The Python Shell
          2. Adding Doctests to a Method
          3. Running Your Doctests
          4. Handling Error Cases
          5. Advanced Doctest Usage
        2. Improving Doctests with Nose Integration
        3. Summary
        4. Resources
      6. Chapter 5: Driving Your Development with Tests
        1. Agile Development
          1. Adopting the Agile Process Now
        2. Ethos of Test Driven Development
        3. Advantages of Test Driven Development
        4. Ping-Pong Programming
        5. Test Driving Your Problem
          1. Writing Your Failing Test
          2. Making Your Test Pass
          3. Driving More Features with Tests
          4. Wrapping Up the Task
        6. Summary
        7. Resources
      7. Chapter 6: Writing Acceptance Tests
        1. What Is Acceptance Testing?
          1. Anatomy of an Acceptance Test
          2. Using Gherkin Syntax
          3. The Magic Is in the Step File
          4. Goals of Acceptance Testing
          5. Implementing Developer and QA Collaboration
        2. Letting Behavior Drive Your Problem
          1. Writing Your Failing Acceptance Test
          2. Defining Your Steps
          3. Implementing Your Code
          4. Developing More of the Feature
          5. Delivering the Finished Article
        3. Advanced Acceptance Test Techniques
          1. Scenario Outline
          2. Tables of Data in Scenarios
        4. Summary
        5. Resources
      8. Chapter 7: Utilizing Acceptance Test Tools
        1. Cucumber: The Acceptance Test Standard
        2. Lettuce in Detail
          1. Tagging
          2. Fail Fast
          3. Nosetest Integration
        3. Robot: An Alternative Test Framework
          1. Installing Robot
          2. Writing a Test Case
          3. Implementing Keywords
          4. Running Robot Tests
        4. Summary
        5. Resources
      9. Chapter 8: Maximizing Your Code’s Performance
        1. Understanding the Importance of Performance Testing
        2. JMeter and Python
          1. Installation
          2. Configuring Your Test Plans
          3. Utilizing Your Test Plans Effectively
        3. Code Profiling with cProfile
          1. Run a cProfile Session
          2. Analyzing the cProfile Output
        4. Summary
        5. Resources
      10. Chapter 9: Looking After Your Lint
        1. Coming to Grips with Pylint
          1. Installing Pylint
          2. Using Pylint
          3. Understanding the Pylint Report
          4. Customizing Pylint’s Output
        2. Covering All Your Code with Unit Tests
          1. Installing Coverage
          2. Using Coverage
          3. Advanced Coverage Options
        3. Summary
        4. Resources
      11. Chapter 10: Automating Your Processes
        1. Build Paver Tasks
          1. Installing Paver
          2. Creating a Paver Task
          3. Executing Paver Tasks
          4. Defining a Default Build
        2. Setting Up Automated Builds
          1. Installing Jenkins
          2. Adding Coverage and PyLint Reports
          3. Making Your Build Status Highly Visible
        3. Summary
        4. Resources
      12. Chapter 11: Deploying Your Application
        1. Deploying Your Application to Production
          1. Creating a Deployable Artifact
          2. QA Environment
          3. Implementing Stage and Production Environments
          4. Implementing a Cloud Deployment
        2. Smoke Testing a Deployed Application
          1. Example Application Stack
          2. Smoke Test Scenarios
          3. Implementing Smoke Tests
        3. Summary
        4. Resources
      13. Chapter 12: The Future of Testing Python
        1. Stub the Solution
        2. Making Deployment Natural
        3. Automating (Nearly) Everything
        4. Working in Public
        5. Collaborating on Step Definitions
        6. Final Thoughts
        7. Resources

    Product information

    • Title: Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing
    • Author(s):
    • Release date: July 2014
    • Publisher(s): Wiley
    • ISBN: 9781118901229