An AI feature has two kinds of uncertainty: ordinary software failures and variable model behavior. Test them separately so a network outage does not look like a widget regression and a fluent answer does not conceal invalid data.
Test the UI with deterministic inputs
Define a narrow provider boundary and use fakes in unit and widget tests. For a non-streaming feature, a fake can return a fixed answer or throw a controlled error. Test the visible state rather than an exact internal implementation.
abstract interface class LessonAssistant {
Future<String> answer(String question);
}
class FakeLessonAssistant implements LessonAssistant {
FakeLessonAssistant({this.fail = false});
final bool fail;
@override
Future<String> answer(String question) async {
if (fail) throw StateError('Simulated provider failure');
return 'A widget describes part of the user interface.';
}
}
For a streaming boundary, create a fake stream that emits several chunks and another that fails after the first chunk. Verify that the UI preserves appropriate partial output, exposes an error state and does not pretend a failed stream completed successfully.
Write observable acceptance criteria
| Case | What to verify |
|---|---|
| Empty question | No remote request is started |
| Request in flight | Loading is visible; duplicate submit is blocked |
| Provider error | Useful message and an explicit retry |
| User leaves the screen | No update to a disposed widget |
| Invalid structured output | Rejected or corrected before an action |
| Tool requests a sensitive action | Normal authorization and confirmation remain enforced |
Keep these checks independent of the model’s exact wording. Use unit tests for parsers and widget tests for interactions.
Evaluate the model separately
Maintain a small, representative set of questions with a rubric: factual correctness, appropriate uncertainty, valid schema and relevant explanation. Include ambiguous input, unsupported requests and deliberately misleading instructions in retrieved text. Track the model identifier and prompt version with each evaluation run.
A good score on ten examples is limited evidence, not a guarantee. Review failures manually and expand the set from real product errors. Keep recorded requests free of personal information unless the user-facing feature and retention policy explicitly require it.
Check cost and latency behavior
Measure time to first visible response, completion time and retry frequency. Limit repeated requests from a stuck interaction. Keep production monitoring free of secret tokens and unnecessary conversation content. A loading indicator that never resolves is a product bug even if the provider caused the original failure.
Exercise
Write a widget test using the successful fake, then another using the failure fake. Add a manual evaluation rubric for five lesson questions. Report software checks and model-quality results separately so a reviewer can see exactly which behavior was verified.