Tuesday, 3 December 2013

Test doctring

The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown. There are several common ways to use doctest:
  • To check that a module’s docstrings are up-to-date by verifying that all interactive examples still work as documented.
  • To perform regression testing by verifying that interactive examples from a test file or a test object work as expected.
  • To write tutorial documentation for a package, liberally illustrated with input-output examples. Depending on whether the examples or the expository text are emphasized, this has the flavor of “literate testing” or “executable documentation”.
when it comes to test, we need to intelligently choose different test methods for different test cases. here are some things that we need to take into consideration.
  • Size
    For collections (strings, lists, tuples, dictionaries) test with:
    • empty collection
    • a collection with 1 item
    • smallest interesting case
    • collection with several items
  • Dichotomies
    Consider your situation:

    For example:
    • vowels/non-vowels
    • even/odd
    • positive/negative
    • empty/full
    • etc.
  • Boundaries
    If a function behaves differently for a value near a particular threshold (i.e. an if statement checking when a value is 3; 3 is a threshold), test at the that threshold.
  • Order
    If a function behaves differently when the values are in a different order, identify and test each of those orders.
There is often overlap between the categories, so one test case may fall into more than 1 category.

No comments:

Post a Comment