Lesson 3 of 4 Deploying Multi-Agent Solutions

Designing a Testing Strategy for Nondeterministic Agents

This lesson describes the layers of an agent testing strategy and where each runs, since agents combine deterministic code with nondeterministic model behaviour and need both conventional tests and evaluations that judge outputs statistically.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish unit and integration tests for agents.
  • Design regression tests and automated evaluations.
  • Apply techniques that keep tests stable despite nondeterminism.

Unit and integration tests

Unit tests cover deterministic components: tool functions, validators, middleware, routing rules, prompt template rendering and state transitions in workflows. Model calls are replaced with fakes or recorded responses, so unit tests are fast, cheap and repeatable. Integration tests run components against real services in a test environment: an agent calls real tools and models with test identities, workflows run end to end, MCP servers are called over their real transport, and authentication, network paths and contracts between agents are verified.

Sort into groups

Unit test or integration test?

Exam skills 4.3.3

Classify each test in an agent testing strategy.

Log in to try this activity Interactive activities are free with an account.

Regression tests and automated evaluations

Regression tests replay a fixed dataset of representative and previously failing cases and check that behaviour has not degraded. Because outputs vary, checks use assertions where possible (the right tool was called, the output matches a schema, the refund amount is correct) and evaluator scores otherwise.

Automated evaluations run evaluators over a dataset and compare aggregate scores and pass rates with thresholds: task adherence, tool call accuracy, groundedness, safety and custom judges. A test passes when, for example, at least 95% of cases pass groundedness and no safety case fails. Foundry evaluations can run from pipelines through the SDK or the Foundry evaluation GitHub Action and Azure DevOps task, with results recorded in the project for comparison.

The following table shows where each layer runs.

Test layerRuns onExample check
Unit testsEvery commit and pull requestRefund tool rejects amounts above the limit
Fast evaluation (small dataset)Every pull requestTask adherence pass rate at least 90% on 50 cases
Integration testsAfter deployment to testAgent authenticates to the HR API with OBO
Full regression and evaluationBefore promotion to acceptance and productionNo regression beyond tolerance on 1,000 cases
Red-teaming scanBefore promotion; scheduledAttack success rate below threshold
Match the pairs

Where each test layer runs

Exam skills 4.3.3

Match each test layer with when it runs in the pipeline.

Log in to try this activity Interactive activities are free with an account.

Handling nondeterminism

Nondeterministic outputs make naive assertions flaky. Practical techniques include asserting on structure and tool calls rather than wording, running each evaluation case more than once for critical paths, comparing aggregate scores with tolerances rather than exact values, using low temperature or fixed seeds where supported for test runs, and keeping the judge model and version fixed so that score changes come from the system under test.

Select all that apply

Taming nondeterminism

Exam skills 4.3.3

Pick the techniques that make agent tests reliable despite variable outputs.

Log in to try this activity Interactive activities are free with an account.
Worked example

Flaky tests

A team's CI pipeline compares each agent response with an expected answer string. About a third of runs fail even when nothing changed, and developers have started ignoring failures.

Exact string comparison is unsuitable for model output. The tests should assert on tool calls and structured fields, and use evaluators with thresholds over a dataset for wording and quality. Unit tests with fake model responses cover the deterministic code. This restores trust in the pipeline while still catching real regressions.

Check yourself

How are tests made reliable when model outputs vary?

Show answer

Assert on structure and tool calls rather than exact text, and compare aggregate evaluation scores with a tolerance.

Exam Tips

Remember for the exam

  • Unit tests with fake models for deterministic code; integration tests against real services.
  • Regression datasets plus evaluator thresholds act as quality gates.
  • Assert on structure and tool calls; compare aggregate scores with tolerance.