Sub topic 4
Anatomy of a test case
This chapter assumes you know what Agentforce topics and actions are, and that you can read basic YAML. It covers the parts of a single test case and what each part checks.
What a test case is
A test case is one scripted conversation turn. You give the agent an utterance, which is the message a user would type. You also state what you expect the agent to do. The Testing Center sends the utterance to the agent, records what happened, and compares it with your expectations.
Each test case has four parts:
| Part | Question it answers | Checked against |
|---|---|---|
| Utterance | What does the user say? | Input to the agent |
| Expected topic | Which topic should handle it? | The topic the agent selected |
| Expected actions | Which actions should run? | The actions the agent invoked |
| Expected outcome | What should the response achieve? | The agent's final reply |
How the checks line up
The three expectations map to three stages of one agent run. The topic is chosen first, then actions run, then the reply is written.
Because each stage is checked separately, a failure tells you where the run went wrong. A wrong topic points to routing. A right topic with missing actions points to action selection or its inputs. Right topic and actions with a poor reply points to instructions or the data returned.
A test case in a spec file
The same four parts appear in a YAML spec. Here is a suite with two cases.
name: Order_Support_Agent_Tests
description: Core routing and action checks for the order support agent
subjectType: AGENT
subjectName: Order_Support_Agent
testCases:
- utterance: Where is my order 1001?
expectedTopic: Order_Status
expectedActions:
- Get_Order_Status
expectedOutcome: The agent tells the customer the current status of the order.
- utterance: What is the best pizza recipe?
expectedTopic: Off_Topic
expectedActions: []
expectedOutcome: The agent politely declines and explains what it can help with.The top-level fields describe the suite. subjectType and subjectName name the agent under test. Everything under testCases is one entry per test case.
Rules that prevent common errors
- Use developer names.
expectedTopicandexpectedActionsmust match the developer names in your agent, not the display labels. A label that looks right but does not match the developer name makes the case fail. - Use an empty list when no action should run. The second case sets
expectedActions: []. This asserts that the agent invoked nothing. Leaving the field out says less. - Write the outcome as a behavior. The expected outcome is natural language, and the response is judged against its meaning. Describe what the reply must accomplish, as in "tells the customer the current status". Do not quote exact wording, because the agent's phrasing varies between runs.
- Keep one intent per case. An utterance that asks for two things makes a failure hard to read. Split it into two cases.
- Make the utterance self-contained. Include any identifier the action needs, such as the order number, so the test checks the agent and not missing input.
Exercise
Exercise
A test case sets expectedTopic to OrderStatus and expectedActions to [GetOrderStatus]. When the suite runs, the agent selects OrderStatus but does not invoke any action. Which part of the case is likely to fail, and where should you look first?
Show answer
The expected actions check fails, while the expected topic check passes. Routing worked, so look at the action: whether it is attached to the Order_Status topic, whether the topic instructions tell the agent when to call it, and whether the utterance supplied the input the action needs, such as the order number.