Computer Science
15-110, Fall 2010, Lecture 2
Testing and Debugging
- Testing
- unit testing
- testFoo() for each function foo()
- make your own test cases! Look for "edge" or "boundary" or just "weird" cases!
- testAll()
- print expected and observed values when assertions fail!
- Debugging
- read stack trace output on crashes!
- print statements, the debug() function, and the db() function
- assertions and invariants
- disabling events + simulating events
- profiling with time.time() and with cProfile.run("myTest()")
- use the pdb Python debugger
- break into debugger with: import pdb; pdb.set_trace()
- some commands:
- h help
- l list source code near the current line
- w where (print stack trace)
- a arglist: print the arglist of the current function
- p expr print the value of the expression
- pp expr same as p, only "pretty-printed"
- s step into called functions
- n next (step over called functions)
- r return: run until this function returns
- c continue (run again)
- !stmt execute the stmt in the current context
- q quit from the debugger