Book contents
- Frontmatter
- Contents
- 1 Introduction
- 2 What Are Good Programs?
- 3 How to Get Started
- 4 How to Understand Your Language
- 5 How to Use the Best Tools
- 6 How to Make Sure You Don’t Lose Your Program
- 7 How to Test Your Program
- 8 How to Make Your Program Clear
- 9 How to Debug Your Program
- 10 How to Improve Your Program
- 11 How to Get Help (without Cheating)
- 12 How to Score Well in Coursework
- 13 How to Score Well in a Programming Exam
- 14 How to Choose a Programming Language
- 15 How to Go Beyond This Book
- Bibliography
- Index
7 - How to Test Your Program
Published online by Cambridge University Press: 10 July 2020
- Frontmatter
- Contents
- 1 Introduction
- 2 What Are Good Programs?
- 3 How to Get Started
- 4 How to Understand Your Language
- 5 How to Use the Best Tools
- 6 How to Make Sure You Don’t Lose Your Program
- 7 How to Test Your Program
- 8 How to Make Your Program Clear
- 9 How to Debug Your Program
- 10 How to Improve Your Program
- 11 How to Get Help (without Cheating)
- 12 How to Score Well in Coursework
- 13 How to Score Well in a Programming Exam
- 14 How to Choose a Programming Language
- 15 How to Go Beyond This Book
- Bibliography
- Index
Summary
This chapter is about how to tell whether your program is correct. It discusses systematic testing, and how this can be automated, e.g. using a unit testing framework such as JUnit. It covers what tests you should have, and when you should write them, mentioning Test-Driven Development, an approach to programming in which you write the tests before you write the code that is to be tested. Finally it discusses property-based testing, commonly used in Haskell. In this approach you specify and test something about the relationship between the inputs and outputs of your program, and that relationship is tested on many randomly-chosen input examples.
- Type
- Chapter
- Information
- How to Write Good ProgramsA Guide for Students, pp. 68 - 82Publisher: Cambridge University PressPrint publication year: 2020