How-to guide
How to choose a test oracle
How can I decide what the expected result of a test should be?
Look for an expectation independent of the code under test. A reviewed business example, an invariant or a documented relationship between results can all serve as a test oracle. Record where the expectation came from and what it lets you infer.
Find a defensible expectation
Choose an oracle that would disagree with at least one plausible wrong result.
- Ask for the applicable rule, version and units. Work one example by hand with the person responsible for the behaviour.
- If the full output is difficult to calculate, identify a property that must hold or an independent reference with known limits.
- Keep the expectation with its source. If you have only historical output, label the check as characterisation and flag the question of correctness for review.
Worked example
How many parcels should be created?
The packing rule allows up to six identical items in each parcel and asks for the fewest parcels. For thirteen items the warehouse owner agrees on three parcels. The test can count the parcels and check that every item is present exactly once. Calling the production packing function to calculate the expected count would hide an error shared by both calculations.
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