Skip to catalogue

29

property-based testing

Do not only write examples. Write a property that must always hold, and let a generator try to break it.

What is property-based testing?

Property tests declare invariants: round-trip encoding, sort preserves length, a permission function never leaks on random ids. The generator hunts counterexamples.

Why does property-based testing matter when vibe coding?

The model studies for the two examples you typed. Property tests face it with inputs it has not seen. For parsing, permissions, and money, that is harsher than one more example.

How do you do property-based testing?

Write the invariant. Use a library to generate inputs. On failure, keep the shrunk counterexample as a plain test.

How do you ask a model for property-based testing?

Property tests for (function). Invariant: (property). Not just examples. If you find a counterexample, keep it as a fixed test.

What goes wrong with property-based testing?

An invariant that only says “does not crash.” Too weak. Write “round-trips” or “never returns another user’s row.”

adjacent