# Stateful vs stateless property testing

> Use a seat-reservation model to compare single generated inputs with sequences of actions. Keep the operation order that reproduces a failure.

Source: https://cueapril.com/compare/stateful-vs-stateless-property-testing
Updated: 2026-12-01
Index: https://cueapril.com/llms.txt

## Does the fault depend on the order of operations or a single input value?

Start with stateless properties when each input and result can be evaluated on their own. Use stateful property testing when valid actions and expected results depend on earlier operations. The extra work pays off when a short, unexpected history can expose a defect that one isolated call cannot reach.

Decide whether one input or a sequence exposes a booking bug. Use an independent seat model and preserve the operation order that caused a failure.

Cue April editorial assessment. The sources identify documented capabilities. Suggested pilot checks are evaluation criteria.

## Use a tiny independent booking model

Give a room one seat. The reference model holds either no booking or one active booking ID. Reserve, cancel that booking, then reserve again. At each step compare the visible capacity and active bookings with the model. Keep the model simpler than the implementation so it does not reproduce its storage or caching mistakes.

Stateful vs. stateless property-based testing

| Requirement | Stateless property | Stateful property |
| --- | --- | --- |
| Price is non-negative | Generate a seat price and calculate its fee. | A history adds little to this isolated rule. |
| Capacity never falls below zero | Test a supplied snapshot with a known capacity. | Check the invariant after every generated operation. |
| Cancelling restores a seat | Supply an explicit before-and-after fixture. | Cancel a reservation previously produced in the same run. |
| Replay a failure | Save the input and expected value. | Save initial state, ordered operations and divergence. |

## Save the sequence as well as its inputs

Generate only actions that make sense in the current state, or define the product’s expected response to an invalid action. Reset the target between generated histories. If a failure shrinks to “reserve A, cancel A, reserve B”, store that sequence, initial state and first differing observation. A single request for B cannot explain the stale reservation.

## Primary documentation

- [Hypothesis stateful testing and rule-based state machines](https://hypothesis.readthedocs.io/en/latest/stateful.html)
- [Hypothesis quickstart](https://hypothesis.readthedocs.io/en/latest/quickstart.html)

By Cue April. Updated 2026-12-01.

## Related

- [Testing comparisons](https://cueapril.com/compare): Compare testing tools and methods against a release decision. Inspect the required evidence, maintenance work and checks each approach can provide.
- [Property-based testing](https://cueapril.com/testing/property-based-testing): Run a fast-check property-based testing example: find a delivery-rule boundary fault, replay its seed and counterexample, and verify the fix.
- [Testing comparisons](https://cueapril.com/compare/property-based-vs-example-based-testing): Compare named boundary examples with generated inputs. Use an independent membership rule to find cases a few well-chosen lists can miss.
