PacktLib: Python Testing: Beginner's Guide

Python Testing

Credits

About the Author

About the Reviewers

Preface

Testing for Fun and Profit

How can testing help?

Types of testing

You've got Python, right?

Summary

Doctest: The Easiest Testing Tool

Basic doctest

Time for action – creating and running your first doctest

Time for action – writing a more complex test

Time for action – expecting an exception

Time for action – using ellipsis in tests

Time for action – normalizing whitespace

Time for action – skipping tests

Embedding doctests in Python docstrings

Time for action – embedding a doctest in a docstring

Putting it in practice: an AVL tree

Summary

Unit Testing with Doctest

What is Unit testing and what it is not?

Time for action – identifying units

Unit testing throughout the development process

Time for action – unit testing during design

Time for action – unit testing during development

Time for action – unit testing during feedback

Time for action – unit testing during development... again

Time for action – unit testing during maintenance

Time for action – unit testing during reuse

Summary

Breaking Tight Coupling by using Mock Objects

Installing Python Mocker

Time for action – installing Python Mocker

The idea of a mock object

Python Mocker

Time for action – exploring the basics of Mocker

Mocking self

Time for action – passing a mock object as self

Summary

When Doctest isn't Enough: Unittest to the Rescue

Basic unittest

Time for action – testing PID with unittest

Test fixtures

Time for action – testing database-backed units

Integrating with Python Mocker

Summary

Running Your Tests: Follow Your Nose

What is Nose?

Installing Nose

Organizing tests

Time for action – organizing tests from previous chapters

Nose and doctest

Time for action – creating a fixture for a doctest

Nose and unittest

Time for action – creating a module fixture

Time for action – creating a package fixture

Nose's own testing framework

Time for action – using Nose-specific tests

Summary

Developing a Test-Driven Project

Writing the specification

Time for action – what are you going to do?

Writing initial unit tests

Time for action – nailing down the specification with unit tests

Coding planner.data

Using the tests to get the code right

Fixing the code

Time for action – writing and debugging code

Writing persistence tests

Writing persistence code

Finishing up

Summary

Testing Web Application Frontends using Twill

Installing Twill

Exploring the Twill language

Time for action – browsing the web with Twill

Time for action – Twill scripting

Calling Twill scripts from tests

Time for action – running Twill script files

Time for action – running Twill script strings

Integrating Twill operations into unittest tests

Time for action – using Twill's browser object

Summary

Integration Testing and System Testing

Integration tests and system tests

Time for action – figuring out the order of integration

Automation with doctest, unittest, and Nose

Time for action – writing integration tests for the time planner

Summary

Other Testing Tools and Techniques

Code coverage

Time for action – using coverage.py

Version control hooks

Time for action – installing Nose as a Bazaar post-commit hook

Time for action – installing Nose as a Mercurial post-commit hook

Time for action – installing Nose as a Git post-commit hook

Time for action – installing Nose as a Darcs post-record hook

Time for action – installing Nose as a Subversion post-commit hook

Automated continuous integration

Time for action – using Buildbot with Bazaar

Summary

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Answers to Pop Quizes

Index