---
library: "bootstrap"
slug: "MetamorphicTesting"
name: "MetamorphicTesting"
ref: "MetamorphicTesting#7129"
hash: "sema:MetamorphicTesting#mh:SHA-256:7129619c60f2d3773b9a985ae4365bf2dbdba782131b9c804e079142656dae9c"
type: "Verification"
layer: "Infrastructure"
version: "0.11.0"
root: "a6a3d1ff0f982ee30430c5b42f3784c8ec901fd68482cfc1bc30899c1e5e48c5"
license: null
url: "https://semahash.org/vocabularies/bootstrap/patterns/MetamorphicTesting"
---

# MetamorphicTesting

Test a stated relation among the outputs of several runs, which needs no exact expected answer for any single run

Infrastructure · Verification

## Mechanism

Instead of checking each run against a known answer, related runs are compared: a relation states how the outputs must correspond when the inputs are changed in a stated way, as permuting the rows fed to an order-independent aggregation must leave its result unchanged. A relation may involve more than two runs. Each relation is derived, before any run, from a property the correct output must have, stated in the [Spec](https://semahash.org/vocabularies/bootstrap/patterns/Spec.md) or known of the domain, never from the implementation's behaviour, and it states how a violation is decided: exactly, within a tolerance, or by a statistical test where outputs are random. Follow-up inputs are generated from source inputs, and a violation is a failure on that set of inputs. A satisfied relation shows the outputs are consistent under that relation, not that any single output is correct. It builds tests for [EmpiricalTest](https://semahash.org/vocabularies/bootstrap/patterns/EmpiricalTest.md) that need no exact expected answer, including where the correct output cannot be computed independently.

## Invariants

- Each relation is derived from a stated property of the correct output, from the specification or the domain, and recorded before execution together with how a violation is decided.
- A violation is reported with the source inputs, the transformations and every output the relation involves.
- A pass is reported as consistency under the named relations, never as correctness.

## Failure modes

- Weak relation: the relation also holds for wrong implementations, for example one any constant output satisfies, so passing proves little.
- Relation read off the code: the relation is derived from the implementation's behaviour, so the test cannot disagree with it.
- Shared error: the defect changes every related output in the same way, so the relation holds.
- Tolerance creep: numeric relations get tolerances wide enough to hide real violations.

## Where this came from

—

## Builds on

- [Spec](https://semahash.org/vocabularies/bootstrap/patterns/Spec.md) (references)
- [EmpiricalTest](https://semahash.org/vocabularies/bootstrap/patterns/EmpiricalTest.md) (references)

## Related

- [DetectorSelfTest](https://semahash.org/vocabularies/bootstrap/patterns/DetectorSelfTest.md)
- [ClosureConservationCheck](https://semahash.org/vocabularies/bootstrap/patterns/ClosureConservationCheck.md)
- [Morphproof](https://semahash.org/vocabularies/bootstrap/patterns/Morphproof.md)
- [Falsification](https://semahash.org/vocabularies/bootstrap/patterns/Falsification.md)

## Identity

- Library: bootstrap 0.11.0 (root a6a3d1ff0f98)
- Ref: MetamorphicTesting#7129
- Hash: sema:MetamorphicTesting#mh:SHA-256:7129619c60f2d3773b9a985ae4365bf2dbdba782131b9c804e079142656dae9c

## Links

- Page: https://semahash.org/vocabularies/bootstrap/patterns/MetamorphicTesting
- JSON: https://semahash.org/vocabularies/bootstrap/patterns/MetamorphicTesting.json
- Library: https://semahash.org/vocabularies/bootstrap
- Library index: https://semahash.org/vocabularies/bootstrap/index.json
