coders/software engineers spend as much time debugging and testing their codes as they spend on developing/writing the codes
"To err is human, but to preserve in error is diabolic." - anonymous
this more than two thousand-years old proverb fits with coding
"Progam testing can be used to show the presence of bugs, but never to show their absence!" - Edsger W. Dijkstra
code coverage is used to measure the degree to which the source code of a program is executed when a particular test suite runs
various coverage criteria:
function coverage
statement coverage
branch coverage
condition coverage
loop coverage
data-flow coverage
function entry/exit coverage
full path coverage is usually impractical or impossible; module with a succession of n decision in it can have up to 2n paths; loops can result in an infinite number of path
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”.
see factorial.py in utility package for doctest example¶