Metamorphic Tests with Related Inputs
A metamorphic test checks how an output should change when the input undergoes a known transformation.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Choose a relation you can justify
For a sum of exact integers, permuting the values leaves the result unchanged. Duplicating the whole list doubles it. These relations derive from the same accumulation rule and can be checked across generated cases.
Keep one direct oracle
An incorrect function that always returns zero satisfies both relations. Pair them with a worked input whose result is known independently. Use testable program inputs to choose an example reliably detecting that constant answer.[1]
Derive the relation between results before running tests
If a pure routine computes range as maximum minus minimum, adding seven to every input should leave the result unchanged. For [2,5,9] both the original range and the range of [9,12,16] are seven. See properties invariant under transformations.
Base input [2,5,9] → range 7
Transformed [9,12,16] → range 7
Reversed order [9,5,2] → still range 7
Combine relations with an independently known example
A function returning a constant could pass a test checking only shift invariance. Combine numerical examples and relations that detect different defects. Avoid generating values where fixed-width overflow violates the transformation's assumptions.