Automating Tests Across ML Pipelines
This lesson explains automated tests at several levels that catch code bugs, bad data, weak models and infrastructure problems before production.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish the testing layers.
- Place each kind of test in the MLOps process.
- Design effective quality gates.
Testing layers
Unit tests check feature engineering functions, data parsers and inference handlers with small fixed inputs. Data validation tests check schema, ranges and completeness with Glue Data Quality or custom checks. Model quality gates compare evaluation metrics with thresholds and with the current production model, using a ConditionStep. Bias and explainability checks use Clarify. Integration tests deploy to a staging endpoint and send real requests to check request and response formats. Load tests confirm latency and throughput under expected traffic, for example with Inference Recommender.
Which test layer?
Where tests run
Different tests run at different points in an MLOps process. Unit tests of code, such as feature transformation functions, run in CodeBuild when code is committed. Data validation and model quality gates run inside the SageMaker pipeline, where the data and model are available.
Integration and load tests run in the deploy pipeline after deployment to staging and before the manual approval for production, because they need a running endpoint. A failing test at any stage stops the pipeline and reports why, so problems are fixed before they reach production.
Testing generative AI components
Generative AI adds prompt regression tests, structured output validation, safety tests with adversarial prompts and guardrail tests, covered in the next lessons. The following table summarises the layers.
| Test | Checks | Where |
|---|---|---|
| Unit | Feature and inference code | CodeBuild on commit |
| Data validation | Schema, ranges, completeness | Pipeline start |
| Model quality gate | Metrics vs. threshold and champion | Pipeline ConditionStep |
| Bias check | Clarify metrics vs. limits | Pipeline ClarifyCheckStep |
| Integration | Endpoint request/response contract | Staging, deploy pipeline |
| Load | Latency and throughput | Staging, before approval |
Designing effective quality gates
A quality gate compares a new model with expectations, and the way the comparison is defined decides whether it catches real regressions. An absolute threshold, such as AUC of at least 0.85, guarantees a minimum standard. A relative threshold, such as no more than 0.01 below the current production model, catches a model that passes the minimum but is worse than what users already have. Most pipelines use both, with a small tolerance so that random variation between training runs does not block every release.
Aggregate metrics can hide regressions on important groups. Computing metrics per segment, such as per region, product line or customer type, and gating on the most important segments prevents a model that improves overall while failing for one market. The evaluation data itself must be fixed and versioned; a test set that changes between runs makes the gate's decisions incomparable.
The order of tests matters for cost and speed. Cheap, fast checks, such as unit tests and data validation, should run first, so that a broken feature function or a malformed input file stops the pipeline before hours of training. Expensive checks, such as load tests on a staging endpoint, run last, only for candidates that passed everything else. Tests must also be deterministic enough to trust: a test that fails at random is soon ignored, so fixed random seeds, fixed test data and tolerances appropriate to the metric's natural variation are part of good test design.
The following diagram shows a mismatch between a new model version and its production client, and the test that catches it.

A good quality gate
A broken contract
A new model version expects 42 features, but the production client sends 41 because a feature was added in training. Unit tests and the quality gate passed.
An integration test that replays a sample of real production requests against the staging endpoint would fail with a 4xx error before production approval. Adding that test to the deploy pipeline closes the gap; the model itself was fine, but the interface between client and model had changed.
Which tests catch changes to an endpoint's request format?
Show answer
Integration tests against a staging endpoint.
Exam Tips
Remember for the exam
- Unit tests in CodeBuild; data and quality gates in the SageMaker pipeline.
- Integration tests against a staging endpoint catch request format changes.
- Load tests confirm latency before production approval.
- Gate on both absolute thresholds and comparison with the champion.
- A failing test must stop the pipeline.