Book contents
- Frontmatter
- Contents
- Preface
- Part I Numerical Software
- Part II Developing Software
- 6 Basics of computer organization
- 7 Software design
- 8 Data structures
- 9 Design for testing and debugging
- 10 Exercises
- Part III Efficiency in Time, Efficiency in Memory
- Part IV Tools
- Part V Design Examples
- Appendix A Review of vectors and matrices
- Appendix B Trademarks
- References
- Index
9 - Design for testing and debugging
Published online by Cambridge University Press: 28 January 2010
- Frontmatter
- Contents
- Preface
- Part I Numerical Software
- Part II Developing Software
- 6 Basics of computer organization
- 7 Software design
- 8 Data structures
- 9 Design for testing and debugging
- 10 Exercises
- Part III Efficiency in Time, Efficiency in Memory
- Part IV Tools
- Part V Design Examples
- Appendix A Review of vectors and matrices
- Appendix B Trademarks
- References
- Index
Summary
This section is about how you should design your software so it is easy to test and debug. Bugs are inevitable. But we should try to eliminate them as quickly and thoroughly as we can. To do this, we need to test the code thoroughly. The best way to do this is to automate the testing. When bugs are uncovered, the situation that revealed the bug should be added to the set of (automated) tests. When changes are made, re-do the tests. This is known as regression testing and is how many software companies ensure the quality of their software.
Memory allocation and the associated debugging issues are dealt with in Chapters 14 and 15.
Incremental testing
This is perhaps the most crucial single technique in designing for debugging. Test as you go. Make sure each piece is working correctly before you put them together. Don't try to construct a full-featured program from the beginning, but make sure that you can get a “bare bones” version going. For any feature you want to add, first devise a test for what this feature does. Then start building the feature, checking it against the test you devised. This way you can test each new addition while having confidence that the base system is behaving correctly.
The Extreme Programming approach [21] is even stronger: Before you start writing code, write the test code and data. Furthermore, you should automate the tests, and add new tests as you refine, debug, and test the code. Whenever you feel that you have things working, run the complete set of tests. This ensures that you haven't broken anything that you thought was fixed.
- Type
- Chapter
- Information
- Writing Scientific SoftwareA Guide to Good Style, pp. 118 - 142Publisher: Cambridge University PressPrint publication year: 2006