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

Naming tests that sound like sentences and stories

Test methods should read like sentences and test cases should read like titles of chapters. This is part of BDD's philosophy of making tests easy-to-read for non-programmers.

Getting ready

For this recipe, we will be using the shopping cart application shown at the beginning of this chapter.

How to do it...

With the following steps, we will explore how to write a custom nose plugin that formats results as a BDD-style report.

  1. Create a file called recipe26.py to contain our test cases.
  2. Create a unittest test where the test case represents a cart with one item, and the test methods read like sentences.
    import unittest from cart import * class CartWithOneItem(unittest.TestCase): def setUp(self): self.cart ...

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