Practice question · Multiple choice
A test asserts that a function returns something, and passes even when the function returns the wrong answer. What has been tested?
Hints
- Ask what the assertion would have to say to catch a wrong answer.
- This test contributes to coverage. What does that tell you about coverage?
Show the answer
B. That the code ran without raising, which is liveness rather than correctness
Why
It proves the function did not crash, and nothing about the answer. That is the gap coverage metrics cannot see: every line ran, so the report is green, and the assertion never compared anything. A test is only as strong as what it asserts, which is why 'assert not None' is barely a test at all.
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.
- Order the steps of writing and running one test case.
- A test suite that passes on typical inputs can miss bugs that a handful of edge cases would catch…
- A function takes a list of numbers. Select every input that is an edge case worth testing.