# How to write and replay a property-based test

> Write a property, generate inputs that challenge it and replay a failing case. See how two repeated stock codes expose a missing item in a parcel.

Source: https://cueapril.com/knowledge/how-to/write-a-property-test
Updated: 2026-12-02
Index: https://cueapril.com/llms.txt

## How do you turn a general rule into a property-based test?

State a rule that should hold across a family of inputs, generate examples from that family and check the rule for each. When a case fails, shrink it and save enough information to reproduce the failure on the same version.

## Design the property, generator and replay together

A good generator reaches the parts of the input space where you expect the rule to be challenged.

1. Write the rule in plain language and give a small example that would violate it. Agree any preconditions.
2. Generate representative values, including empty, repeated and boundary values where valid. Check both the quantity and variety of cases that actually ran.
3. For a failure, preserve the smallest reproducible input, seed, runner version and replay information. Keep the small case as a regression alongside the broader property.

## Worked example: A packing list must preserve every item

Generate lists of stock codes that can contain duplicates. After splitting a list into parcels, flatten the result and compare the count of each code with its original count. A bug that silently drops repeated items might shrink to a list containing just two identical codes. That pair makes a precise regression example.

## Try it on your pull request

Choose a change in your repository and tell Cue April what should happen. Review the proposed checks before they run.

[Try Cue April on your repository](https://app.cueapril.com/sign-up/?next=%2Fquality-start)

## Related reading

- [Test data generator](https://cueapril.com/knowledge/definitions/test-data-generator)

- [Shrinking](https://cueapril.com/knowledge/definitions/shrinking)

- [Metamorphic testing explained with a worked example](https://cueapril.com/knowledge/explanations/metamorphic-testing-explained)

[Browse the Knowledge base](https://cueapril.com/knowledge)
