O'Reilly logo

Python Testing Cookbook by Greg L. Turnquist

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing a testable story with mockito and nose

When our code interacts with other classes through methods and attributes, these are referred to as collaborators. Mocking out collaborators using mockito (http://code.google.com/p/mockito and http://code.google.com/p/mockito-python) provides a key tool for BDD. Mocks provide a way for providing canned behavior compared to stubs, which provide canned state. While mocks by themselves don't define BDD, their usage keenly overlaps the ideas of BDD.

To further demonstrate the behavioral nature of the tests, we will also use the spec nose plugin found in the pinocchio project (http://darcs.idyll.org/~t/projects/pinocchio/doc).

Getting ready

For this recipe, we will be using the shopping cart application shown ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required