Engineering Craft · 18 min · free with an account

Choosing a Test

Lesson preview · about 30%

Different bugs need different tests, and naming them is the answer.

Core idea

Examples check what you thought of; properties check what you did not.

Start with the idea

Unit tests pin down behaviour you already thought of. Property tests generate inputs and check an invariant, which finds the cases you did not. Fuzzing pushes malformed input at a parser until it panics. Integration tests check the seams. A candidate who reaches for all four in the right places is saying something a coverage number cannot.

Different tests answer different questions. A unit test can pin one known rule with a small input. A property test generates many inputs and checks an invariant, such as parse-then-format preserving a value. A fuzz target feeds malformed or unexpected inputs to a parser and watches for crashes or violated assertions. An integration test checks boundaries among modules or a real storage adapter. None of these is a substitute for knowing what behavior matters to users.

Start with a parser. Unit tests cover empty input, a normal record, and a known malformed delimiter.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep