Test the deterministic parts properly and the stochastic parts behaviorally. Unit test feature transforms against fixtures, enforce schema and range contracts on inputs, keep a golden row test that loads the serialized pipeline and checks known inputs produce known scores, and write behavioral tests on model outputs (invariance, directional expectations) rather than asserting an exact accuracy number.
Why interviewers ask this
Many candidates say you cannot really test machine learning, which is the wrong answer. Interviewers want to hear that most of a pipeline is ordinary deterministic code that tests fine, and that models themselves are testable behaviorally. Mentioning a golden row regression test and data validation contracts shows you have prevented an outage rather than only responded to one.
How to structure your answer
- Point out that most of the pipeline is deterministic code.
- Name unit tests on transforms and schema contracts on inputs.
- Describe a golden row test on the serialized artifact.
- Add behavioral tests instead of asserting an exact metric.
- Say what belongs in CI and what runs on a schedule.
Example answer
Most of a pipeline is ordinary code and tests exactly like ordinary code. Feature transforms get unit tests against small fixtures, including the ugly cases: nulls, a category never seen in training, a negative value where only positives were expected. Input data gets contract checks, so schema, types, ranges, and expected null rates, run as a gate before training rather than discovered afterward as a weird model. Then a golden row test, where I keep a serialized pipeline and a handful of fixed inputs with their expected scores, and CI fails if a refactor changes them. That has caught silent preprocessing changes for me more than once. For the model itself I do not assert accuracy above some number, because that is flaky and a bad gate. I write behavioral tests instead: invariance, so changing an irrelevant field barely moves the score, and directional expectations, so increasing a feature we know is monotonically related moves the prediction the right way. Full training runs are too slow for every commit, so those go nightly, with a fast smoke training on a tiny sample in CI to prove the pipeline still runs end to end.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you write a test for a model that is legitimately nondeterministic?
- What data validation tool would you use, and what would you gate on?
- How do you keep golden row tests from becoming maintenance noise?
Related machine learning engineer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions