Testing, Debugging, Exception Flashcards
What can you do to achieve high quality programming?
- Testing
- Defensive Programming
- Eliminate sources of bugs
What is defensive programming?
- Write specifications for functions
- Modularize programs
- Check conditions on inputs/outputs
What can you do to test your programs?
- Compare in/outputs
i. e. it’s not working
What is debugging?
Study the events leading up to an error
- -> Why is it not working?
- -> How can I fix my peogram?
How can you create a good debugging experience?
- Break program into modules that can be tested and debugged individually
- Document constraints on modules
- -> What do you expect the input to be
- -> what do you expect the output to be? - Document assumptions behind code design
When are you ready to test?
- Code has to run!
- > remove syntax errors
- -> remove static semantic errors - Have a set of expected results
What testing classes do we know?
- Unit testing: Test each function separately
- Regression testing: Catch reintroduced errors that were previously fixed
- Integration testing: does the overall program work?
What testing approaches do we know?
- Intuition about natural boundaries
- Blackbox Testing
- Glassbox testing
What is blackbox testing?
- it is designed without looking at the code
- should be done by someone else than the programmer to avoid implementer bias
- can be reused if implementation changes
What is glassbox testing?
- use code directly to guide design of test cases
- called path complete if every potential path through code is tested at least once
disadvantages:
- missing paths
- can go through loops randomly many times
Can a pass complete test miss a bug?
yes, test boundary cases
What are print statements good for?
To test hypothesis
use bisection method:
-> put print halfway in code
What are the steps in debugging?
- Study program code
- don’t ask whats wrong
- Ask how did I get an unexpected result
- Pick simple input to test with
When do you get an index error?
I.e. trying to access beyond the limits of a list
When do you get an TypeError?
- trying to convert an inappropriate type i.e. int(test)
2. Mixing data types without appropriate coercion