Sub topic 10
Defining tests in a YAML spec or CSV file
This chapter assumes you know what a test case contains (an utterance, an expected topic, expected actions, and an expected outcome). It also assumes you can read YAML and use a command line. You will see how to write the same test cases as a file instead of clicking them into the UI.
Why use a file
A spec file is plain text, so you can keep it in version control, review changes in a pull request, and reuse it across orgs. The Testing Center UI is fine for a first test. A file works better once the suite grows or several people edit it.
Two formats are common:
- YAML spec: The format that Salesforce CLI reads. It names the agent under test and lists every test case.
- CSV file: A table with one row per test case. It suits teams who draft cases in a spreadsheet and then import them in the UI.
The YAML spec
A spec has a header that identifies the suite and the agent, followed by a list of test 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 header fields mean this:
| Field | Purpose |
|---|---|
| `name` | Name of the test suite. |
| `description` | A short note for people who read the suite later. |
| `subjectType` | What kind of thing is tested. Here it is `AGENT`. |
| `subjectName` | The API name of the agent under test. |
| `testCases` | The list of cases. |
Each case uses utterance, expectedTopic, expectedActions, and expectedOutcome. For an out-of-scope request, write expectedActions: [] to state that no action should run. Leaving the field out is not the same assertion.
The topic and action names in the example are placeholders. They must match the developer names in your own agent, or the case fails even when the agent behaves well.
The CSV file
A CSV file holds the same four values per case, one case per row, with a header row naming the columns. Check the column names that your org's import screen expects before you build a large file, because the UI is the source of truth for them. Put several actions in one cell with the separator that the import screen documents, and quote any cell that contains a comma. Outcome sentences often do.
Check the spec before you run it
Most spec failures come from small mistakes. Review these before each run:
- The
subjectNamematches the agent's API name exactly. - Every
expectedTopicand action name matches a developer name, not a label. - Indentation is consistent. YAML uses spaces, never tabs.
- Each case has an utterance that a real user could plausibly type.
Create the suite from the spec
Once the file is ready, one CLI command creates the test definition in the org. The next chapters cover running it.
sf agent test create --spec specs/order-support-tests.yaml --api-name Order_Support_Agent_Tests --target-org my-orgThe --spec flag points to your file. The --api-name flag sets the API name of the new test definition in the org.
Exercise
A teammate adds a test case for an unrelated question and leaves out the expectedActions line, assuming that means "no actions". What should they write instead, and why?
Show answer
They should write expectedActions: []. The empty list states explicitly that the agent should run no actions. Omitting the field does not make the same assertion, so the intent of the test would be unclear.