Practice question · Put in order
Order the steps of writing and running one test case.
- Choose an input to test
- Work out the expected output independently, by hand
- Compare the actual output with the expected output
- Run the program on that input
Hints
- A test case is a pair: an input and the output it should produce.
- The expected output must be worked out independently, not read off the program's own result.
Show the answer
- Choose an input to test
- Work out the expected output independently, by hand
- Run the program on that input
- Compare the actual output with the expected output
Why
Pick an input, decide the expected output independently, run, then compare. Working out the expected result independently is essential, if you take the answer from the program itself, the test can never catch a wrong answer.
Practise Testing Small Programs
The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Testing Small Programs
- A program that passes one hundred typical-case tests is guaranteed to have no bugs.
- A function is meant to accept a whole number of items. Sort each test input by its kind.
- A test suite that passes on typical inputs can miss bugs that a handful of edge cases would catch…
- A test asserts that a function returns something, and passes even when the function returns the wrong answer.…
- A function takes a list of numbers. Select every input that is an edge case worth testing.