# Metamorphic testing explained with an example

> Use a relationship between two runs to test a result that is hard to calculate. A stocktake example shows which faults each comparison can reveal.

Source: https://cueapril.com/knowledge/explanations/metamorphic-testing-explained
Updated: 2026-12-02
Index: https://cueapril.com/llms.txt

## How can I test a result when I cannot calculate the full expected output?

Metamorphic testing checks an expected relationship between two runs. Transform an input in a controlled way, predict how the output should change or stay the same, and compare the observed relationship with that prediction.

## What makes a relationship useful?

The relationship needs an independent reason to hold in the product’s domain. Reordering independent items might preserve a total. It might change a result when priority, rounding or position affects the rule. State those preconditions so a failed relationship is interpretable.

## What can still go wrong?

Two wrong outputs can satisfy the same relationship. A calculation that always returns zero will preserve a total under reordering. Add a known example or a second relation that would expose that particular failure.

## Worked example: Reorder a stocktake

In a stocktake that sums every line independently, reordering the same lines must preserve each item’s total. Adding one more line for three blue mugs must then increase only the blue-mug total by three. Together the checks catch more faults than either comparison alone.

## 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

- [How to write and replay a property-based test](https://cueapril.com/knowledge/how-to/write-a-property-test)

- [How to choose a test oracle](https://cueapril.com/knowledge/how-to/select-a-test-oracle)

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

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