Testing & Validation Frameworks

Key points

  • Testing pyramid: unit tests (components), integration tests (interactions), system tests (end-to-end), user acceptance tests (business requirements)
  • Accuracy testing: precision, recall, F1, AUC-ROC; must be evaluated across subgroups, against baselines, with statistical significance
  • Fairness testing protocol: define attributes, select metrics, set thresholds, disaggregate by subgroup, conduct intersectional analysis
  • Four-fifths rule: selection rate below 80% of highest group creates presumption of adverse impact; useful benchmark beyond employment
  • Robustness: adversarial inputs, distribution shift, out-of-distribution detection, noise tolerance — model must handle real-world conditions
  • Security: poisoning, model inversion, membership inference, model extraction, prompt injection — specialist testing required
  • Pilot testing: real data, representative users, sufficient duration, parallel human process, evaluate before full deployment
  • Continuous production testing: automated regression, ongoing fairness monitoring, periodic evaluations, canary deployment, A/B testing

Testing & Validation Frameworks

Comprehensive testing and validation ensures AI systems are accurate, fair, robust, and secure before deployment and throughout operation. The AIGP BoK requires understanding of testing across the full lifecycle, from unit testing to continuous production monitoring.

Testing Strategy

The Testing Pyramid

AI system testing follows a layered approach. Unit tests verify that individual components function correctly in isolation: data processing functions produce expected outputs, feature engineering produces correct transformations, and model inference produces outputs in the expected format. Integration tests verify that components work correctly together: the data pipeline feeds the model correctly, the model's outputs integrate properly with downstream systems, and API contracts between components are honoured. System tests evaluate the complete end-to-end system under realistic conditions, including performance under expected load, behaviour with realistic data distributions, and graceful degradation under adverse conditions. User acceptance tests validate that the system meets business requirements, user workflows function as intended, edge cases are handled appropriately, and stakeholders are satisfied with the system's behaviour.

Accuracy Testing

Accuracy testing evaluates how well the model performs its intended task. For classification tasks, key metrics include precision (of positive predictions, what percentage are correct), recall (of actual positives, what percentage are identified), F1 score (the harmonic mean of precision and recall, balancing both), and AUC-ROC (the model's ability to distinguish between classes across all thresholds). For regression tasks, key metrics include mean squared error, mean absolute error, and R-squared.

Critical governance practices for accuracy testing include using test sets that are fully independent of training data (no data leakage), establishing minimum performance thresholds before deployment begins, evaluating accuracy across relevant subgroups (not just overall), comparing performance against baselines (simpler models, human performance, previous versions), assessing statistical significance rather than relying on point estimates, and conducting regression testing after any model changes to verify no degradation.

Edge Case Testing

Edge cases are inputs that fall outside the normal operating range and can reveal how the model behaves under unusual conditions. Categories include boundary values (inputs at the extremes of expected ranges), extreme inputs (values far outside expected ranges), missing data (how the model handles incomplete inputs), invalid formats (unexpected data types or structures), unexpected combinations (legitimate but unusual feature combinations), and rare events (scenarios that are uncommon but important). Edge case testing should produce documented behaviour for each category, with clear procedures for how the model handles each type: graceful degradation, error messages, fallback to human decision-making, or user notification.

Fairness Testing

Fairness Test Protocol

A structured fairness testing protocol begins with preparation: defining the protected attributes relevant to the use case, selecting the fairness metrics appropriate to the context and stakeholders, establishing acceptable thresholds (what level of disparity is tolerable), preparing demographically disaggregated test data, and documenting the baseline before any mitigation.

Execution involves calculating each fairness metric for the overall population and for each demographic subgroup, conducting statistical tests to determine whether observed disparities are statistically significant, comparing results against the established thresholds, and performing intersectional analysis (testing combinations of protected attributes, such as race and gender together, since an individual may face compound discrimination that single-attribute analysis misses).

Analysis examines any identified disparities, their statistical significance, the potential impact on affected populations, and the root causes. Based on this analysis, decisions are made about whether to proceed with deployment, require mitigation, or reject the model.

The Four-fifths Rule

In US employment discrimination law, the four-fifths (or 80%) rule creates a presumption of adverse impact when the selection rate for a protected group is less than 80% of the selection rate for the highest-performing group. For example, if the hiring rate for Group A is 50% and for Group B is 30%, the ratio is 30/50 = 60%, which falls below the 80% threshold and creates a presumption of discrimination. While this rule originates in employment law, it provides a useful benchmark for fairness testing across many AI applications.

Robustness Testing

Robustness testing evaluates how well the model performs when conditions deviate from the ideal. Adversarial testing examines the model's vulnerability to deliberately crafted inputs designed to cause misclassification. Small, carefully constructed perturbations to an input (for example, adding noise to an image that is invisible to humans) can cause dramatic changes in the model's output. Distribution shift testing evaluates performance when the input data distribution differs from the training data. This simulates real-world conditions where the population or environment changes over time. Out-of-distribution detection tests whether the model can recognise when an input falls outside its training domain and flag the prediction as uncertain rather than providing a confident but unreliable answer. Noise tolerance testing evaluates performance with corrupted, incomplete, or noisy inputs that reflect realistic data quality issues.

Security Testing

AI systems face security threats specific to machine learning. Poisoning attacks test whether an attacker can corrupt the model by manipulating training data. Model inversion attacks test whether an attacker can reconstruct training data by querying the model. Membership inference attacks test whether an attacker can determine if a specific individual's data was used in training. Model extraction attacks test whether an attacker can create a copy of the model by systematically querying it. Prompt injection attacks (for LLM-based systems) test whether an attacker can override system instructions through crafted inputs. Security testing should be conducted by specialists with expertise in adversarial machine learning, and findings should be documented, prioritised by severity, and remediated before deployment.

Pilot Testing

Before full deployment, pilot testing validates the AI system's performance under real-world conditions with a limited scope. Pilot design should use representative data from actual operations (not synthetic or historical data), deploy to a representative subset of the target user population, run for sufficient duration to capture normal operational variation (including daily, weekly, and seasonal patterns), and maintain a parallel process (human decision-making alongside AI) for comparison.

Pilot evaluation compares AI performance against established baselines, assesses operator experience and feedback, identifies unexpected behaviours or failure modes, evaluates the effectiveness of human oversight mechanisms, and validates that monitoring and alerting systems function correctly.

Continuous Testing in Production

Testing does not end at deployment. Continuous testing in production includes automated regression testing triggered by model updates, ongoing fairness metric monitoring, periodic full evaluation cycles (quarterly or as determined by risk level), canary testing for model updates (deploying to a small subset before full rollout), and A/B testing to compare new model versions against current production models.

Practise AIGP questions

Members get the AIGP question bank with explanations, flashcards, timed mock exams, Privacy Pro AI, progress tracking and the Pass Guarantee.