Skip to main content

Search...

Metamorphic Testing: Testing Without a Test Oracle

With a search engine or an AI model, often nobody knows what the right answer would be. What can be checked anyway: whether the system behaves consistently.

Expert reviewed by Richard Seidl · Jul 31, 2026

What Is Metamorphic Testing?

Classical Test versus Metamorphic TestComparison scheme of a classical test and a metamorphic test. Classical test: one input leads to one result, which is compared with a known expected result. Metamorphic test: two related inputs A and B lead to two results, which are checked not against an expected value but in their relationship to each other, with no known expected value at all.Classical TestInputResultComparison with knownexpected resultvs.Metamorphic TestInput A (source)Input B (follow-up,transformed)Result AResult BCheck the relationbetween the resultsno test oracle needed

Swipe right or use the arrow keys to see the full graphic.

Metamorphic testing is a rule-based test technique that checks relations between several inputs and their results, which lets it work even where a clear test oracle is missing. Its tool is the metamorphic relation: a property that must hold between related inputs, no matter which concrete result the system delivers.

That sounds more abstract than it is. A journey planner must not offer an earlier arrival for the same route when the requested departure time moves later. Which connection is the right one on any given day, nobody knows by heart with a timetable that changes daily. But that a later departure can never lead to an earlier arrival is certain, because every connection available to the later search was also available to the earlier one. This relationship is a metamorphic relation. If the system violates it, a defect is found, without anyone having to know the “right” connection.

A metamorphic test consists of a source test case with the original input and a follow-up test case with the transformed input. The relation defines how the two results must relate to each other: equal, subset, superset, never smaller. If the results honour the relation, the test run counts as passed. On a failure, only the debugging clarifies which of the involved test cases actually computed wrongly. Within the test design techniques, metamorphic testing belongs to the rule-based group.

When Is the Technique a Good Fit?

Metamorphic testing plays out its strength wherever the test oracle problem is pronounced: with search and information systems, recommendation services, numerical computations without an independent reference, optimisation algorithms, rendering, compression and encryption, and to a special degree AI models. Everywhere the desired result is hard to predict while relationships between several results remain determinable.

The reverse holds too: where a clear expected behaviour is known, the direct comparison of actual against expected stays more precise. Metamorphic testing does not replace classic tests; it opens up the territory they cannot reach.

The Procedure in Four Steps

  1. Identify metamorphic relations. Which properties must hold between related inputs? Ideally several relations per test object, worked out together with someone who knows the domain.
  2. Determine the source test cases. Fix the original inputs, preferably including some whose result would be hard to check manually.
  3. Generate the follow-up test cases. For each relation, derive the transformed input: shift the departure time, force an intermediate stop, set a filter, change the spelling.
  4. Check the relation. Execute source and follow-up test cases and apply the relation to the results. If a result deviates from the expected relationship, a defect is found.

In practice, a generator takes over steps 2 to 4: for each source input it automatically creates the follow-up input and checks the relation. Property-based frameworks such as Hypothesis, jqwik or QuickCheck lend themselves well to this.

A Compact Example

Metamorphic Relation MR1, Later Departure, Journey PlannerTransformation scheme of the metamorphic relation MR1 later departure for a journey planner. Left, the source: search from 14:00. A transformation (shift the departure time back by one hour) leads to the follow-up: search from 15:00. Right, the two results with the required relation: the earliest possible arrival of the follow-up must never be earlier than that of the source.Source: search from14:00Source result: earliest possiblearrival XTransformation MR1: shiftthe departure time back by 1hourFollow-up: search from15:00Follow-up result: earliestpossible arrival YExpectation: arrival of follow-up (Y) ≥ arrival ofsource (X)earliest possible arrival never earlier than the source

Swipe right or use the arrow keys to see the full graphic.

The journey planner of a public transit network is a classic test oracle case: the timetable changes constantly, roadworks and cancellations included. Four metamorphic relations suggest themselves:

RelationSourceFollow-upExpectationholds only if
MR1: later departuresearch from 14:00search from 15:00earliest possible arrival never earlier than the sourceboth searches return the earliest arrival across all routes
MR2: forced intermediate stopdirect search A to Bsearch A to B via Cjourney time never shorter than the sourceboth searches optimize for journey time and do not pre-sort by number of changes
MR3: transport mode filtersearch without filtersearch “local transport only”result set is a subset of the sourcethe source returns the complete result set, not a top-N selection
MR4: spelling substitution”Main Station""Main Stn”identical connectionsthe abbreviation resolves as an alias to the same stop ID

The last column is not fine print; it is the actual core of the work. A metamorphic relation without its preconditions is not a relation but a guess. Formulate MR3 without the qualifier while the planner, as is common, returns only the five best connections, and you will reliably get violations reported that are not defects. After three such false alarms, nobody trusts the suite any more. That is why every relation comes with the question: under which assumptions must it hold, and are those assumptions even met in the system under test?

Four Metamorphic Relations for the Journey Planner at a GlanceFour short schemes of the metamorphic relations MR1 to MR4 for the journey planner, arranged as a 2×2 grid. MR1 later departure: search from 14:00 becomes search from 15:00, expectation: earliest possible arrival never earlier than the source. MR2 forced intermediate stop: direct search A to B becomes search A to B via C, expectation: journey time never shorter than the source. MR3 transport mode filter: search without filter becomes search local transport only, expectation: result set is a subset of the source. MR4 spelling substitution: Main Station becomes Main Stn, expectation: identical connections.MR1: Later DepartureSource: search from 14:00Follow-up: search from 15:00Expectation: earliest possible arrival never earlier thanthe sourceMR2: Forced Intermediate StopSource: direct search A to BFollow-up: search A to B via CExpectation: journey time never shorter than the sourceMR3: Transport Mode FilterSource: search without filterFollow-up: search "local transport only"Expectation: result set is a subset of the sourceMR4: Spelling SubstitutionSource: "Main Station"Follow-up: "Main Stn"Expectation: identical connections

Swipe right or use the arrow keys to see the full graphic.

The test runs automated, say with 120 randomly drawn origin-destination pairs per relation. A plausible outcome of such a run: MR1 is violated seven times, always on connections shortly before midnight, because the planner drops the date at the day boundary and sorts an arrival at 0:15 as “earlier” than one at 23:50. MR4 is violated three times, because the abbreviation, contrary to the documented alias mapping, resolves to a different stop ID than the written-out name. Both are real defects, because the preconditions of the two relations are met here, and for both no single test case would have shown a “wrong” result; only the comparison of two runs makes them visible.

Why There Is No Clean Coverage Measure Here

With most techniques you can name a number at the end. Not with metamorphic testing, and that follows from how the technique works: there are currently no recognized coverage measures for metamorphic testing from which useful exit criteria could be derived.

The reason is easy to see once you have seen it. Covering each relation once says little, because a satisfied relation checks the result only partially. Afterwards you know that two runs relate to each other correctly. Whether both are wrong, you do not know. A quota like “80 percent of relations covered” therefore suggests a certainty the technique cannot deliver.

What carries weight instead: the quality of the relations and the number of inputs per relation. A good relation is necessary, meaning its violation proves a defect. It is not sufficient; honouring it proves no correctness. And it must be sharp enough to catch anything at all; formulate only truisms and you find nothing. Three search directions help: the mathematical structure of the problem (symmetries, monotonicity), the domain (which transformation of an input may change the result in which way?), and user behaviour (which consistency do users expect between two consecutive actions?). For the number of inputs there is no reliable rule of thumb. The proven route is to pair metamorphic testing with random testing and generate as many source inputs as runtime and budget allow. More inputs do not raise any coverage; they raise the chance of actually catching a rare violation.

As an exit criterion, a review therefore serves better than any percentage: are the relations derived from the domain, do they cover the risky properties of the system, and is the sample large enough that a run without violations means anything at all?

Metamorphic Testing for AI Systems

Metamorphic Testing for an Image ClassifierTransformation scheme for metamorphic testing on an image classifier. Left, the source: an original image is classified. A transformation (rotating or mirroring the image) leads to the follow-up: the same image, rotated or mirrored. Right, the required relation: the classifier should return the same class for both images, as long as the essence of the image is preserved.Source: original imageSource result: classifieroutputs class XTransformation: rotate ormirror the imageFollow-up: rotated ormirrored imageFollow-up result: classifieroutputs class YExpectation: class Y = class Xclassifier should stay stable, as long as the essence ofthe image is preserved

Swipe right or use the arrow keys to see the full graphic.

With machine learning and generative AI, the technique has gained considerably in practical relevance. AI systems are hit by the test oracle problem with full force: the input space is effectively infinite, the behaviour only described statistically, a complete check against a specification not feasible. Classic test cases with a concrete expected value rarely get far there. Metamorphic relations are often the only route to a systematic, automatable check.

Typical relations for AI systems: an image classifier should stick to its classification under small rotations, mirrorings or brightness changes, as long as the essence of the image is preserved. A machine translator should reconstruct the meaning on a round trip of translation and back-translation. A recommendation system should not overturn its top recommendations just because a user briefly viewed an item and discarded it again. A language model should answer consistently to a rephrased question with the same content. Violations of such relations point to unstable training, missing normalisation or unintended order sensitivity.

One restriction belongs in the picture: metamorphic testing checks consistency, not correctness in the strict sense. A model can be consistently wrong. In AI applications, the technique is therefore combined with human spot checks and with property-based tests for robustness and response time.

Strengths and Limits

The strengths: the technique tests where otherwise hardly anything can be tested systematically. It automates well and scales across many source inputs per relation. And it needs no knowledge of the algorithm’s inner workings, which makes it insensitive to complex implementations.

The limits: good metamorphic relations demand domain knowledge, and a wrongly formulated relation produces false findings or overlooks real ones. The technique proves no correctness; it uncovers inconsistencies. Where an oracle exists, the classic test remains the first choice.

Random testing with property-based tests pursues a related idea with a different structure and provides the tooling basis for automated metamorphic tests. Decision table testing is the rule-based sibling technique for deterministic business logic with a clear oracle. For the input side, equivalence partitioning stays relevant, for parameter combinations pairwise testing. The page test design techniques gives an overview of all eleven techniques; to keep listening, there is a podcast episode on test design with AI.

Frequently Asked Questions

Metamorphic testing is a test technique that uses relations between several inputs and their results to check systems without a clear test oracle. Instead of comparing a single result against an expected value, it checks whether the results of related inputs relate to each other the way a metamorphic relation demands.

A metamorphic relation is a necessary property of the test object that must hold between related inputs, independent of the concrete result. Journey planner example: someone who wants to leave an hour later must not be offered an earlier arrival, and a forced intermediate stop must never shorten the journey. Every relation holds only under named preconditions, for instance that both searches return complete results. If a properly formulated relation is violated, a defect is found.

The test oracle problem describes situations in which no expected result can be determined for an input, nothing to compare the actual result against. Typical for search engines, recommendation systems, numerical algorithms and AI models: the data basis changes constantly, the intended behaviour is only described statistically, a direct comparison of actual against expected is fragile or impossible.

AI models have huge input spaces, statistically described behaviour and rarely a clear expected value per input. Metamorphic relations often provide the only systematically automatable check here: an image classifier should classify stably under small rotations, a language model should answer consistently to rephrasings with the same content, a recommendation system should not change systematically through irrelevant actions.

Both check properties instead of concrete expected values, and they are closely related. Property-based testing checks properties of individual executions with generated inputs, for instance that a result is never negative. Metamorphic testing compares the results of several deliberately transformed inputs with each other. Property-based frameworks such as Hypothesis or jqwik are well suited to implementing metamorphic tests.

No. The technique checks consistency, not absolute correctness: that a system answers consistently on two related inputs says nothing about whether the answer is any good in domain terms. That is why metamorphic testing is combined with classic comparisons against expected results where an oracle exists, and complemented with human spot checks for AI systems.

Build the base first

Metamorphic testing does not stand on its own: it rests on solid test design craft, from equivalence partitions to decision tables. That base is exactly what you build in the ISTQB Foundation Level.