Test Techniques for AI Systems

Many AI systems have no expected output you can write down in advance. A support assistant receives thousands of new messages a day, nobody has labelled them, and several answers may be acceptable. This lesson covers the techniques for that situation, from metamorphic testing to version comparison, adversarial inputs, production experiments, drift monitoring and explainability claims.

The central idea is a different kind of test oracle. You may not know the right triage for a message, but you know that rewording it, or changing only the customer’s name, must not change the triage. A test that breaks such a relation has found a defect without anyone knowing the correct answer.

Why it matters

An AI feature evaluated once on a labelled set can still fail on inputs that set did not contain: a new phrasing, a name from an under-represented group, a crafted input, a product launched after training. Labels are expensive, so most real inputs are never checked, and the result is wrong decisions, unequal treatment and quality that drops silently after an update.

These techniques turn "there is no expected result" into test cases with a pass or fail verdict. They build on fundamentals you already have — oracles, regression testing, monitoring — and do not replace them: the system around the model still needs its functional, security and performance tests.

Metamorphic relations: an oracle without expected outputs

In metamorphic testing you run a source test case, transform its input in a controlled way to create a follow-up test case, and check a metamorphic relation (MR): how the follow-up output must relate to the source output. You do not need to know the correct output of either test.

Derive MRs from the requirement and the domain: which changes to the input must not change the result (an invariance), and which must move it in a known direction? These relations are the most used for AI systems:

  • Paraphrase: reword the input with the same meaning; the decision must not change. Compare decisions — labels, fields, amounts — not wording.
  • Counterfactual attribute swap: change only an attribute that must not matter, such as a name, gender or nationality; the output must be equal. This is the counterfactual pair from the lesson on safety, bias and robustness testing; written as an MR, the check runs on any input, labelled or not.
  • Order invariance: change an order that carries no meaning, such as complaints within a message or documents passed as context; compared as a set, the result must be the same.
  • Directional (the ISTQB AI Testing syllabus calls this monotonicity): some changes may move the result in one direction only. Adding "this is my third message about it" must not lower urgency.
  • Check the transformation itself: a paraphrase that drops a fact, or a swap of an attribute that legitimately matters, produces false violations. Review the generated follow-ups, at least a sample.
Source S-017 (charged twice, parcel late, signed Ahmed) is triaged payment and delivery at normal urgency; paraphrase, reordering and a third-message follow-up satisfy their relations, but swapping only the name to Priya lowers urgency.

MR-1 Paraphraseinvariance

  1. 1Reword, keep the meaningbilled two times, 7 days late
  2. 2Follow-up output{payment, delivery} · normal
  3. 3Relation: categories and urgency equalPass

MR-2 Attribute swapinvariance

  1. 1Change only the name- Ahmed becomes - Priya
  2. 2Follow-up output{payment, delivery} · low
  3. 3Relation: categories and urgency equalViolated: urgency fell to lowFail

MR-3 Orderinvariance

  1. 1Swap the order of the two complaints
  2. 2Follow-up output{delivery, payment} · normal
  3. 3Relation: same set, same urgencyPass

MR-4 Directionaldirection

  1. 1Add a third-message sentence
  2. 2Follow-up output{payment, delivery} · high
  3. 3Relation: urgency not lower than normalPass

Each follow-up changes one thing in the source message; the relation is checked between the two outputs, never against a known correct answer.

Worked example: metamorphic tests for a support triage model

An online store’s model triages support messages: it returns the categories involved (refund, delivery, payment, account, other) and an urgency (low, normal, high). The requirement says urgency depends on the problem and how long it has lasted, never on who the customer is. Almost no message has a label.

The tester takes 200 recent messages as sources, derives the four MRs in the record below, and has a colleague review a sample of the generated follow-ups. The model is not deterministic, so every pair runs three times and the result is a violation rate per MR.

  • MR-2 failed for S-017: changing only the signature from - Ahmed to - Priya lowered urgency to low. If a re-run repeats it, report both inputs, both outputs, the broken relation and how often it reproduced. The new name differs in gender and origin at once, so add pairs that change one signal, such as - Fatima, to narrow the cause.
  • Report rates per MR and per segment, such as the language of the message: one overall rate can hide a group the model treats differently.
  • Passing MRs do not prove correctness: a model that answers other and low for every message satisfies all four MRs. Keep a smaller labelled set for correctness, and use MRs for the unlabelled majority.
Model under test: support-triage v3 (output: categories, urgency)

S-017  source
  input:   I was charged twice for order 5521 and the parcel is a week late. - Ahmed
  output:  {payment, delivery}, normal

MR-1   paraphrase: categories and urgency must be equal
  input:   Order 5521 was billed two times, and the parcel is 7 days late. - Ahmed
  output:  {payment, delivery}, normal                                   pass

MR-2   attribute swap, name only: categories and urgency must be equal
  input:   I was charged twice for order 5521 and the parcel is a week late. - Priya
  output:  {payment, delivery}, low                                      FAIL

MR-3   order invariance: same set of categories, same urgency
  input:   The parcel for order 5521 is a week late and I was charged twice. - Ahmed
  output:  {delivery, payment}, normal                                   pass

MR-4   directional: urgency must not be lower than the source
  input:   S-017 + "This is my third message about it."
  output:  {payment, delivery}, high                                     pass

Run: 200 sources x 4 MRs x 3 runs; violation rate per MR, reported by language

Try it: Fake Name Generator Try it: Percentage Calculator

Comparing versions: back-to-back, shadow mode and A/B tests

Back-to-back testing runs two or more variants of a system on the same inputs and analyses every discrepancy between their outputs. For AI systems they are usually the current version (A) and a candidate (B): a new model, a changed prompt or a model retrained on fresh data. Use the labelled regression set plus recent real inputs, with identical settings.

Run A against itself first: a non-deterministic model can disagree with its own earlier outputs, and only differences beyond that baseline say something about B. Agreement is not correctness, since both versions can share a defect, and a discrepancy is not automatically a regression: classify each one as an improvement, a regression or a neutral change. Production then adds two steps:

  • Shadow mode (shadow testing in the ISTQB AI Testing syllabus): B receives a copy of live inputs and its outputs are logged, never shown or acted on, while A keeps serving users. Test that the shadow path has no side effects (no messages sent, no tools called, no records written) and that its logs follow the privacy rules.
  • A/B testing: a statistical approach to find which of two variants performs better. Traffic is split at random so that a share of users or tickets gets B, and a metric agreed in advance is compared, such as how often agents re-route a triaged ticket, together with guardrail metrics such as complaints. Fix the decision rule before the start too: which difference, over how many tickets, is enough. It measures the effect on users, not the correctness of single outputs.
  • Keep the order: offline comparison, shadow mode, an A/B test on a small share, then full rollout. Each step exposes users to B only after the previous one gave evidence.

Try it: JSON Diff Try it: Text Diff

When inputs move: adversarial inputs, poisoning and drift

Unlike the ordinary variation of robustness testing, adversarial inputs are crafted on purpose, often with changes a person barely notices, to make a model fail: look-alike Unicode letters or invisible characters that slip past a filter, deliberate misspellings, tiny pixel changes for image models. Test them like an invariance MR: start from inputs the system handles correctly, apply each crafted change, check that the decision holds, and add every input that breaks it to the regression set. For LLM applications they are mainly prompt injection, covered in the guide on LLM security testing, and jailbreaks, which wrap a disallowed request in a role-play or split it over several messages so that the model complies, as in the lesson on safety, bias and robustness testing. Test only systems you own or have written permission to test.

Data poisoning manipulates the data a model learns from or draws on — pre-training and fine-tuning data (fine-tuning further trains an existing model on extra examples), user feedback that is fed back into training, and the documents a RAG system retrieves — so that the model behaves wrongly or with bias, or carries a backdoor: a hidden trigger that changes its behaviour only when a certain input appears. The OWASP Top 10 for LLM Applications 2025 lists it as LLM04:2025 Data and Model Poisoning. Test the process: who can change the data, whether each record’s source is kept, whether changes are reviewed before training. After each data update, a back-to-back run against the previous model can reveal unexpected changes, but a backdoor stays silent until its trigger appears, which is why the process checks matter. Never try to poison a shared or production model.

Drift, explained in the lesson on machine learning basics, makes yesterday’s evaluation stop describing today’s system. In data drift the inputs change; in concept drift the link between an input and the correct answer changes, so inputs can look the same while answers become wrong. The ISTQB AI Testing syllabus calls comparing input and output distributions with earlier ones static drift testing, and comparing outputs with fresh ground truth, such as user feedback, dynamic drift testing. These signals should trigger a re-evaluation:

  • Inputs (data drift): a new mix of languages, unseen product names, missing fields, compared with the evaluation set.
  • Outputs: a shifting share of each label, falling confidence, more refusals or catch-all answers.
  • People and changes, where concept drift often shows first: agents re-routing tickets, complaints, a new model or prompt version, a provider updating a model whose version you have not pinned, a policy change such as a new delivery promise that changes what counts as urgent.
  • Then re-run the evaluation set with a freshly labelled sample of recent inputs. A signal shows that something changed, not that quality dropped; only the evaluation shows that.

Try it: Unicode Dataset Generator

Testing transparency and explainability claims

The NIST AI Risk Management Framework treats three characteristics as distinct: transparency, how much information about the system and its outputs is available to the people using it ("what happened"); explainability, a representation of how the system works ("how" a decision was made); and interpretability, what an output means in the context of the system’s purpose ("why" it was made). In a product they appear as claims, and each claim is a requirement to test.

  • Transparency: check that a promised notice ("You are chatting with an AI assistant") appears in every language and channel, and review the model documentation, such as a model card, against the release records: model version, training data, known limitations. The ISTQB AI Testing syllabus counts this review as a test activity.
  • Faithfulness: turn an explanation into MRs. Remove a factor it cites, and the result or the explanation must change; change a factor it does not cite, and neither should. An explanation that survives the removal of its own reason does not describe the decision.
  • Consistency and understandability: the same input gives the same explanation, and representative users can understand it, which you check as in usability testing.
  • Generated reasons: when an LLM says why it answered, that text is not guaranteed to reflect how the answer was produced. Test it like any other claim; never accept it as evidence.

Common mistakes

  • Treating passing MRs as proof of correctness: a model that gives the same answer to every input satisfies every invariance relation.
  • Trusting generated follow-ups without review, so that a changed meaning, or a swapped attribute that legitimately matters, produces false violations.
  • Judging a non-deterministic system on one run, or comparing A with B before measuring A against itself.
  • Reading agreement between versions as correctness, or shipping a version because its outputs look better without classifying each discrepancy.
  • Running shadow mode with side effects, or starting an A/B test without a metric and a decision rule fixed in advance.
  • Evaluating once at release and never again, or accepting an explanation because it sounds plausible.

The QA perspective

In test planning, ask for every AI feature what the oracle will be: a labelled set, MRs, comparison with the previous version, human review, or a mix. Derive MRs with the product owner, domain experts and whoever owns the fairness policy, because they decide which attributes must not matter, and agree with the ML engineers and operations which comparisons gate a release and which signals trigger a re-evaluation.

Record what makes a result reproducible: model and prompt versions, settings, the MR definitions, how follow-ups were generated and reviewed, the numbers of sources and runs, the A-against-A baseline and violation rates per segment. Report a broken relation like any defect, and state what the techniques did not show: that the outputs are correct.

Practice exercise

Design metamorphic tests for a review classifier

Your task

A travel site’s model reads each hotel review and returns a sentiment (positive, neutral or negative) and topics (any of cleanliness, staff, location, price, food). Most reviews have no label, and the page shows "Why this rating" with the words that drove the sentiment. Use review R-102 in the material as your source test case.

Material
Review R-102 (signed "Fatima, Cairo"):
"Great location next to the metro. The staff were friendly,
 but the bathroom was dirty and the room was noisy at night."

Model output:  sentiment = neutral
               topics    = [location, staff, cleanliness]
Explanation:   Why this rating: "great", "friendly", "dirty", "noisy"
Steps
  1. Write four MRs: a paraphrase, a counterfactual attribute swap, an order invariance and one directional relation, each with its transformation and relation.
  2. For the first two, describe a follow-up that would be invalid and cause a false violation.
  3. Design one faithfulness test for the explanation.
Show the model answer
Model answer

MR-1 paraphrase: Right by the metro, which is great. Friendly staff, but a dirty bathroom and a loud room at night. must give the same sentiment and topic set. MR-2: change only the name in the signature, for example to Priya, Cairo (another woman’s name, same city); the outputs must be equal. Change the city in a separate pair, so that a violation points to one attribute. MR-3: reverse the order of the sentences; same sentiment and topic set. MR-4 directional: add Breakfast was cold and overpriced.; the sentiment must not become more positive, and the topics must now include food and price.

Invalid follow-ups: a paraphrase that drops the dirty bathroom, or softens noisy at night to a bit lively, changes the meaning; a swap that also edits the text is no longer a pure swap. Review the generated follow-ups before the run.

Faithfulness: remove the words about the bathroom; dirty must disappear from the explanation, and the sentiment must stay the same or become more positive. Then change a word the explanation does not cite (metro to tram): sentiment and explanation must not change. If dirty is still cited after the word is gone, report that the explanation does not describe the input.

Frequently asked questions

Is metamorphic testing only for AI systems?

No. It was developed for programs whose correct output is hard to know, such as numerical, scientific and search software: you may not know sin(x) to the last digit, but sin(x) and sin(π − x) must agree within a small rounding tolerance. AI systems made it common because so many of their outputs have no expected value.

How many source inputs and repeated runs do I need?

There is no universal number. Use enough sources to cover every segment that matters, such as each language and category, and enough repeated runs to tell a real violation from sampling noise. Record both numbers with the violation rates, so others can judge how much the result shows.

What is the difference between shadow mode and an A/B test?

In shadow mode users only ever see the current version; the candidate’s outputs are logged and compared, so it finds differences without risk but cannot measure the effect on users. In an A/B test some users really get the candidate, which measures that effect but exposes them to its defects, so it comes after offline tests and shadow mode.

References

Practise with Mutqan tools

Generate random first and last names in English, Arabic and Hindi with gender and format options.

Test Data

Calculate percentages, percentage change, increase/decrease and what percent X is of Y.

Utilities

Compare two JSON documents semantically and highlight added, removed and changed values.

JSON & Data

Compare two texts line by line or word by word and highlight differences.

Formatting

Generate Unicode test strings across scripts (Arabic, Devanagari, CJK, Cyrillic), emoji, combining marks and normalisation forms.

Test Data

Go deeper

Your progress on this topic

Part of the QA Roadmap