Debugging and Testing
- C, C++, Java, Python
- Think about your programming experience. What types of bugs
have you encountered? How did you find them? Which bugs were
particularly difficult to find. How do you test your code? Do
you test while you are developing your code or do you wait until
you are done? How do you determine your test cases?
- Chapters 5 and 6 of the text.
- Debuggers (gdb)
- Effective use of print statements
- Stack trace
- Use of assertions.
- Look for familiar patterns.
- Examine the most recent changes
- Don't make the same mistake twice
- Debug it now, not later
- Think before debugging (what do you expect to happen?
each test should aim at a definitive outcome that confirms
or denies a specific hypothesis).
- Write trivial programs to test hypotheses or confirm your
understanding of how something works.
- Divide and Conquer (to look for problem in code and to generate
small inputs that cause problems).
- Display output to localize your search.
- Write self-checking code.
- Write a log file.
- Draw a picture.
- Use tools (diff, makes, memory leaks, version control).
- Keep records.
- Test code at its boundaries.
- Test pre- and post-conditions (use assertions).
- Program defensively.
- Check error returns.
- Test Incrementally.
- Test simple parts first.
- Know what output to expect.
- Compare independent implementations.
- Measure test coverage.
- Automate testing (regression testing, stress tests).
- Try to force errors to happen (cause memory allocator to fail)