Sub topic 4
Anatomy of a test case
This chapter takes one test case apart and explains what each field checks. It assumes you know what Agentforce topics and actions are, that you can read YAML, and that you have an org with the Testing Center enabled. Later chapters cover each assertion in more depth, so this one gives you the working model.
What a test case is
A test case is one scripted conversation turn and a set of checks on how the agent handled it. You give the agent a single customer message. The Testing Center runs it against the agent, records what the agent did, and compares that record with your expectations.
A test case has four parts:
- Utterance: the message sent to the agent.
- Expected topic: the topic the agent should choose.
- Expected actions: the actions the agent should run.
- Expected outcome: a description of what the response should accomplish.
The first part is the input. The other three are the assertions. Each assertion looks at a different layer of the agent, so a failure points you toward a specific cause.
A complete example
The following spec defines a test suite with two cases. The topic and action names are examples. They must match the developer names in your own agent.
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 of the file describes the suite. name identifies the test definition in the org. subjectType and subjectName say what is being tested, here an agent called Order_Support_Agent. Everything under testCases is a list, and each list item is one test case.
How the agent processes an utterance
To see why there are three assertions, follow what happens to one utterance.
- The agent reads the utterance and picks the topic whose classification description fits best.
- Within that topic, the agent follows the topic instructions and decides which actions to run.
- The agent writes a reply using the action results.
Because the stages run in order, an early error spreads. If the agent picks the wrong topic, it usually runs the wrong actions or none, and the reply is wrong too. A single mistake can therefore fail all three assertions at once. When that happens, fix the earliest failing stage first.
The utterance
The utterance is the exact text sent to the agent. Write it the way a real customer would, not the way a developer would. Real messages are short, informal, and sometimes incomplete.
Keep these points in mind:
- One turn per case. Each test case sends one utterance. Treat every case as independent of the others, and don't rely on earlier cases to set up context.
- Include the data the action needs.
Where is my order 1001?carries the order number. Without it, the agent would ask a follow-up question instead of running the action, and your expected action would fail for a reason that has nothing to do with routing. - Use data that exists. If the action looks up order 1001, that record must exist in the org where the test runs. A missing record is a common cause of failures that look like agent bugs.
- Vary the wording across cases. Customers phrase the same request many ways, so a suite that repeats one phrasing only proves the agent handles that phrasing.
Expected topic
expectedTopic is the developer name of the topic the agent should select. It checks routing: did the agent understand which area of work the request belongs to?
The value is a name, not a label. A topic can have a display label such as "Order Status" and a developer name such as Order_Status. Use the developer name, with the same spelling and underscores that appear in your agent. A typo here makes the test fail even when the agent behaved perfectly.
Out-of-scope requests still need a topic. In the example, the pizza question is expected to land in Off_Topic. The name depends on how your agent handles requests it cannot serve, so check what your agent actually uses.
Expected actions
expectedActions is a list of the action developer names the agent should run for this utterance. It checks execution: did the agent call the right tools?
- A case that should run one action lists one name, as in
Get_Order_Status. - A case that should run no action uses an empty list, written
[]. This is a real assertion. It says the agent must not run anything, which matters for out-of-scope requests and for requests where the agent should ask a question first. - A case that needs several actions lists them all.
An empty list is different from leaving the field out. Writing expectedActions: [] states your intent, so use it whenever the correct behavior is "do nothing."
Expected outcome
expectedOutcome is a plain-language description of what the final response should achieve. Unlike the topic and actions, it is not compared as an exact string. A reply never matches word for word, since the model words it differently on each run. An evaluation step compares the actual response with your description and judges whether it meets it.
Write the outcome as a behavior, not a script:
| Weak outcome | Stronger outcome |
|---|---|
| The agent says "Your order is shipped." | The agent tells the customer the current status of the order. |
| The agent answers correctly. | The agent states the order status and does not invent a delivery date. |
| The agent refuses. | The agent politely declines and explains what it can help with. |
The weak versions either demand exact wording, which makes the test brittle, or say nothing that can be judged. A good outcome names the facts the reply must contain and, when it matters, the things it must avoid.
Exact checks and judged checks
The three assertions are not checked the same way, and the difference affects how you read failures.
| Assertion | How it is compared | Typical cause of failure |
|---|---|---|
| Expected topic | Exact match on the topic name | Wrong routing, or a name typo in the spec |
| Expected actions | Match against the actions that ran | Wrong or missing action, or action inputs not available |
| Expected outcome | Judged against your description | Reply is incomplete, wrong, or the description is vague |
Topic and action checks are mechanical, so they give the same verdict for the same behavior. The outcome check involves judgment and can be less stable, so write outcomes tightly and don't treat a single outcome failure as proof of a bug until you have looked at the actual reply.
Common errors
- Using display labels instead of developer names. Copy names from the agent definition, not from the UI heading you see.
- Omitting data from the utterance. The agent asks a clarifying question, no action runs, and the action assertion fails.
- Forgetting the empty list. For out-of-scope cases, assert
[]so the test confirms nothing ran. - Writing outcomes as exact quotes. The test fails when the wording shifts, even though the behavior is right.
- Packing several intents into one utterance. When it fails, you can't tell which intent caused it. Split it into separate cases.
Exercise
A customer writes "Can you cancel my subscription?" Your order support agent has topics OrderStatus and OffTopic and one action, GetOrderStatus. Cancellation is not supported. Write the test case in YAML, and explain why the expected actions value is what you chose.
Show answer
utterance: Can you cancel my subscription? expectedTopic: OffTopic expectedActions: [] expectedOutcome: The agent explains that it cannot cancel subscriptions and describes what it can help with, such as checking order status. The actions list is empty because no supported action applies. Asserting [] confirms the agent does not run GetOrder_Status or any other action for a request it cannot serve. The outcome describes the behavior instead of quoting a reply, so wording changes between runs do not break the test.
Exercise
A test case with the utterance "Where is my order?" expects the topic OrderStatus and the action GetOrder_Status. The topic assertion passes, but the action assertion fails. Give the most likely cause and a fix.
Show answer
The utterance has no order number, so the agent routed correctly but asked the customer for the number instead of running the action. Fix the test by putting an order number in the utterance, such as "Where is my order 1001?" (and confirm that order exists), or change the case to expect an empty action list and an outcome that says the agent asks for the order number.