Property tests generate varied inputs and check a rule that should always hold. The property must express domain correctness rather than restate implementation.
Before you start
You should understand inputs, expected outputs and the boundaries of the component under test. State the risk a test should detect before choosing a tool or mock. Distinguish controlled dependencies from real integrations so the result does not imply more coverage than the test actually provides.
The practical goal is to reason through this situation: Sorting should preserve the multiset and produce nondecreasing order. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Write an independent invariant
Sorting preserves values and produces a nondecreasing sequence.
Step 2: Generate meaningful inputs
Include duplicates, negatives and varied lengths under the actual domain.
Step 3: Inspect minimized failures
A small counterexample should reveal the broken guarantee.
Worked scenario
Sorting should preserve the multiset and produce nondecreasing order.
A sort returning an empty list satisfies nondecreasing order but violates multiset preservation. Both properties are needed. An encoder-decoder round trip can pass when both share the same mistake, so add known examples and invalid-input checks where the external representation has its own specification.
Common mistake
A weak property such as output exists can pass for incorrect algorithms.
Verify the behavior
Introduce value loss and incorrect ordering separately; ensure the properties catch both.
Interview exercise
Test an encoder and decoder.
Answer and reasoning
Check valid round trips and explicit invalid inputs, while noting that two consistently wrong functions can still round-trip.
Continue learning
Compare the scenario with the Software Testing interview questions and test your understanding with the Software Testing MCQs. For terminology and implementation details, consult the reference material.