AI Testing Fundamentals

AI testing is the testing of systems in which some behaviour comes from an AI component, usually a machine learning (ML) model. In rule-based software a developer writes the logic, for example if the ticket contains "refund", route it to Billing. In an ML system a training algorithm derives the logic from examples: it is given thousands of past tickets labelled with the right team and learns patterns that predict the team for a new ticket. The result is a model whose behaviour depends on its data and which is right most of the time, not always.

That changes how expected results are defined and how a test result is judged. It does not change the basics: an AI feature is still part of a system with requirements, interfaces, data and users, and everything from the lessons on test levels and non-functional testing still applies.

Why it matters

AI features can fail without a single wrong line of code. A model can pass every demo and still misroute most tickets written in a language that was rare in its training data, answer differently after a retraining nobody announced, or slowly get worse as customer behaviour changes. A test suite that only checks code paths stays green through all of it.

For the tester the risk runs both ways: approving a release on evidence that proves less than it seems, such as a few hand-picked examples or a score measured on unrepresentative data, or being unable to say whether a wrong answer is a defect at all. Knowing what is different lets you collect evidence a team can trust and write defect reports a data scientist can act on.

Rule-based software and ML systems

In rule-based software every behaviour traces back to a requirement and to code that a person wrote and can read. For any input you can work out the expected result from the specification, and when a test fails, the defect is in the code, the configuration or the requirement.

In an ML system the model’s behaviour is learned. Developers write the training pipeline and the code around the model, but nobody writes the rule that sends a given ticket to Billing: it comes from patterns in the training data, stored as numeric parameters that cannot be read as rules. This is data-dependent behaviour: the same code trained on different data is a different system.

  • Keyword rules: a ticket saying "I was charged twice" goes to Other, because it does not contain "refund", although it is a billing complaint. The defect is a missing rule, and the fix is a new rule.
  • ML model: the same ticket probably goes to Billing, because similar tickets were labelled Billing in the training data. A new kind of complaint with no similar examples can still be misrouted, and the fix is better data, not a new line of code.
  • Many products combine both: the model proposes, and rules decide what happens next, such as sending low-confidence results to a person.

Probabilistic and non-deterministic behaviour

Rule-based code is normally deterministic: the same input in the same state gives the same output. ML systems add two kinds of uncertainty. They are probabilistic: a classifier returns a score and is right for a share of the inputs, so one wrong answer can be expected behaviour while the error rate stays within the agreed limit. They can also be non-deterministic: the same input can give different outputs.

For tests this means: record the model version, data version and settings with every result; when an output can vary, run the case several times and judge the pass rate; and test the code around the model deterministically by replacing the model with a stub that returns fixed scores. To see whether two outputs for the same input differ in meaning or only in wording, compare them side by side, for example with Text Diff. Given the same input, a fixed model version usually computes the same scores, so the variation comes from these sources:

  • Sampling: generative models such as LLMs pick each next token, a word or part of a word, from a probability distribution, and settings such as temperature control how much the output varies.
  • Retraining: training usually involves random choices, such as starting values and the order of the data, so a model retrained on the same data can answer some inputs differently.
  • Changes you do not control: a provider updates a hosted model, or a self-learning system changes as it learns from new data.
  • Small numeric differences between hardware or library versions, enough to move a score across a threshold.

Try it: Text Diff

Training data is the source of behaviour

Training data plays the part in an ML system that requirements and code play in rule-based software. Whatever patterns it contains become behaviour, including its gaps, its mistakes and its biases. If almost all training tickets were written in English, the classifier handles Arabic tickets poorly, although no line of code mentions language. If the people who labelled the data filed delivery complaints under Billing, the model does the same.

The same applies to the test data used to evaluate the model: a score describes only the population that data represents. Test data must therefore be representative of the operating environment, the inputs and conditions the system meets in production: languages and dialects, channels, devices, regions, time periods and rare but important cases, in realistic proportions. A test set that is 95% English says little about a product whose customers mostly write in Arabic, however high the score. Before you trust an evaluation, ask:

  • Where and when was the data collected, and does that match where and when the system will run?
  • Which groups does it contain, and in what proportions compared with production?
  • Who labelled it, following which written guideline?
  • Was the test data kept apart from the training data? The next lesson shows how overlap between them inflates scores.

What is different to test

ISO/IEC TR 29119-11 and the ISTQB AI Testing (CT-AI) syllabus describe characteristics that make AI-based systems harder to test than rule-based ones, and the NIST AI Risk Management Framework lists similar differences between AI risks and traditional software risks. In daily work, six things change:

  • The expected result is often unknown. For many inputs nobody can write the exact correct output in advance: this is the test oracle problem. Testers use other oracles instead: labels that people agree on for a test set, and partial oracles that check only part of the output, such as ranges of acceptable answers and rules the output must never break.
  • Acceptance criteria are statistical. "At least 90% of tickets routed correctly on a representative test set, and at least 85% in each language" replaces "this ticket goes to Billing". One passing case proves little, and one failing case may be within the agreed error rate, unless it is a must-pass case that may never fail.
  • Defects can live in the data and the model set-up: wrong labels, missing groups, an input field that gives the answer away, a badly chosen threshold. Report them like any other defect, with the model and dataset versions as part of the environment.
  • A fix can move behaviour anywhere. Retraining to fix one group of inputs can change the answers for others, so every new model version runs the whole test set and is compared case by case with the previous version.
  • Quality can change after release. Real inputs drift away from the training data, so a model that met its criteria at release can get worse without anyone changing it, and testing continues as monitoring in production.
  • More quality characteristics matter: bias, robustness to small changes in the input, transparency and explainability. Later lessons in this module cover them.
Rule-based software runs logic people wrote; an ML system runs logic learned from data, so its expected results, pass criteria and defects need different tests.

Rule-based software

A developer writes each rule, e.g. contains "refund" → Billing

Where behaviour comes from:
Rules written from the requirements
Same input twice:
Same output, unless the code uses time, state or randomness
Expected result:
Exact, derived from the specification
Pass criterion:
Each test case passes or fails
Where defects live:
Code, configuration, requirements
After a fix:
Confirmation testing, then regression testing
After release:
Changes only with a new version

ML system

A model learns the logic from labelled examples

Where behaviour comes from:
Patterns learned from training data: other data, other system
Same input twice:
Same scores from a fixed version; output may differ with sampling, retraining or an update
Expected result:
Often unknown: labels agreed by people, plus partial oracles such as ranges and rules
Pass criterion:
A rate on a representative test set, plus must-pass cases
Where defects live:
Also data, labels, the threshold and the training setup
After a fix:
Retraining can shift answers anywhere: run the whole test set again
After release:
Can degrade as real data drifts: monitor it in production

The code around the model is still conventional software and is tested with the usual techniques.

Worked example: testing an ML ticket router

A support team replaces its keyword rules with an ML classifier that reads each ticket, in Arabic or English, and returns a category and a confidence between 0 and 1. Tickets below 0.70 go to a human triage queue. The tester splits the plan into conventional checks, with the model replaced by a stub, and model checks on recent labelled tickets.

Most of the plan is ordinary testing. C1 is boundary value analysis on the threshold: scores have two decimals, so it tests the values on each side of 0.70. C2 to C4 are negative, error-handling and edge-case tests, and C5 makes every decision reproducible. Mixed-language inputs for C4 can come from a test data generator; they test the code path, not the model’s accuracy, because synthetic text does not represent real customers. The test levels still apply: the model is evaluated as a component, its link to the help desk at integration level, and the whole flow at system and acceptance level, with the performance and security checks of non-functional testing.

What is new is M1 to M5: criteria over a set, results per language, a must-pass group, a check that the test data still looks like production, and a consistency check. M1 has two limits because a model that sends almost every ticket to the human queue could pass an accuracy limit alone. The testing principles hold too: a high score does not prove that the router works for every customer, because testing shows the presence of defects, not their absence, and exhaustive testing of free text is impossible, which is why representative test data matters so much.

Feature: route support tickets with an ML classifier (Arabic and English)
Output: category + confidence 0.00..1.00 (2 decimals); below 0.70 -> human triage queue

Conventional checks (model replaced by a stub that returns fixed results)
  C1  stub returns 0.69 -> human queue; stub returns 0.70 -> category queue
  C2  model service gives no answer within 3 s -> human queue, error logged
  C3  empty ticket -> validation error, model not called
  C4  ticket mixing Arabic and English -> routed or queued, never an error
  C5  every decision stores ticket id, model version and confidence

Model checks (labelled test set: 2,000 tickets from the last 3 months)
  M1  >= 90% of auto-routed tickets in the correct category; <= 25% to the human queue
  M2  >= 85% for Arabic tickets and for English tickets, measured separately
  M3  0 of 40 "account locked" tickets routed to Other (must-pass)
  M4  language mix of the test set within 5 points of production
  M5  identical results on two runs of the same model version

Try it: Boundary Value Generator Try it: Multilingual Test Data Generator

Common mistakes

  • Testing only the model and skipping the conventional tests of the API, user interface, integrations, error handling and performance around it.
  • Judging a model by a few hand-picked examples or a single run instead of by criteria over a representative test set.
  • Accepting an evaluation score without asking where the test data came from and whether it matches the users, languages and conditions of production.
  • Writing one exact expected output for variable output and reporting every variation as a defect, or the opposite: accepting any output because "AI is non-deterministic".
  • Not recording the model version, data version and settings with the results, so a failure cannot be reproduced or compared.
  • Assuming that results from before the release stay valid, although retraining, provider updates and data drift change behaviour later.

The QA perspective

On a real team the tester joins AI work at the same point as any requirements review. When the team decides what the model should do, ask how "good enough" will be measured, on which data, for which groups of users, and which cases must never fail; the answers become the acceptance criteria. Data scientists own the training and the evaluation method, and the product owner decides which error rates are acceptable, because every kind of error has a business cost.

In daily work, keep two kinds of tests apart: conventional checks with exact oracles, using a stub where the model would make results vary, and model evaluations with statistical criteria. Record the model version, dataset version, threshold and settings in every test report and defect report. Treat the data science team’s evaluation as a test result to review, not as a replacement for system and acceptance testing, and ask how the model will be monitored after release.

Practice exercise

Review a test plan for an ML review-moderation model

Your task

An online shop in Saudi Arabia is adding an ML model that decides whether a new product review is published at once or held for a moderator. The model was trained on 40,000 English reviews collected in 2024; the shop receives reviews in Arabic and English. A colleague wrote the draft test plan below.

Review it as a tester: find what each line gets wrong, then outline a better plan that keeps conventional checks and model checks apart. Pen and paper is enough.

Material
Review moderation model v1.3 - draft test plan
T1  Submit "This phone is great, fast delivery" -> published
T2  Submit a review containing an insult -> held for moderation
T3  Run T1 and T2 once on staging; if both pass, the model is ready
T4  Test set: 500 reviews randomly sampled from the training data
T5  No API or UI tests: the data science team already tested the model
Steps
  1. For each line T1 to T5, say whether it is a conventional check or a model check, and what is wrong with it.
  2. Describe a representative test set for this model.
  3. Write statistical acceptance criteria and at least one must-pass group of cases.
  4. List the conventional tests that must still run around the model, and the questions you would ask the data scientist.
Show the model answer
Model answer

T1 and T2 are model checks with exact expected results. They are reasonable as smoke cases, but two examples say almost nothing about a model that is right only for a share of its inputs, and both are in English. T3 is a model check too: it turns two cases and one run into a release decision; readiness needs criteria over a representative set, measured on a recorded model version.

T4, the test set for the model checks, is the most serious problem. The model has already seen reviews taken from its training data, so the score will be too optimistic, and an English-only set from 2024 does not represent the Arabic and English reviews the shop receives today. A representative test set is a separate sample of recent real reviews in the production language mix, including dialects, mixed Arabic and English, spelling variants and emoji, labelled by people who follow a written guideline on what must be held.

Example criteria, to be agreed with the product owner: at least 90% of the reviews that should be held are held, and at most 5% of acceptable reviews are held, measured for Arabic and English separately; every review in a must-pass group, such as reviews containing a threat, a phone number or other personal data, is held. Re-run the whole set and compare case by case whenever the model is retrained.

T5 drops every conventional check, and that is wrong: the model is one component. You still test the review form and its API, what happens when the model is slow or unavailable (are reviews published unchecked or held?), the moderator queue, permissions, logging of the model version and score, performance, and the display of held Arabic reviews. Questions for the data scientist: Was any Arabic data used in training? Which guideline did the labellers follow? How was the test data kept apart from the training data? How will the model be monitored after launch?

Frequently asked questions

Do I need to build ML models to test AI systems?

No. You need to understand how a model’s behaviour comes from data, how it is evaluated and where it typically fails, so that you can ask the right questions and design the right tests. The next lessons in this module give you that vocabulary. Programming skills help when you automate evaluations, as they do for any automation.

Is every ML model non-deterministic?

No. A fixed version of a classifier usually returns the same output for the same input. Variation comes from sampling in generative models, from retraining, from model updates and sometimes from small numeric differences between environments. Find out which of these apply before you decide how many runs a test needs.

If a model is right 95% of the time, is a wrong answer a defect?

Not necessarily. A wrong answer within the agreed error rate, in a case that is not must-pass, is expected behaviour; keep it in the evaluation set. It is a defect when the overall rate or the rate for a group falls below the acceptance criteria, when a must-pass case fails, or when the errors follow a pattern, such as one language or one kind of request.

Does AI testing replace traditional test techniques?

No. It adds data review and model evaluation to them. The system around the model is conventional software, and techniques such as equivalence partitioning, boundary value analysis, decision tables and exploratory testing remain how you design many of the tests, including the choice of test data for the model.

References

Practise with Mutqan tools

Generate boundary values (min-1, min, min+1, nominal, max-1, max, max+1) for numeric and length constraints.

Test Design

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

Formatting

Generate the same records in multiple languages (English, Arabic, Hindi, and more) to test i18n and RTL/LTR mixing.

Test Data

Go deeper

Your progress on this topic

Part of the QA Roadmap