Sub topic 11
Running a test suite
This chapter covers what happens when you run a test suite, how to start a run from the Testing Center and from Salesforce CLI, and what to check before you trust the output. It assumes you have already created a test suite, either in the UI or from a YAML spec, and that you know the three assertions in a test case: expected topic, expected actions, and expected outcome.
What a run does
A test run takes every test case in the suite and sends its utterance to the agent as if a user had typed it. The agent selects a topic, chooses and executes actions, and produces a reply. The Testing Center then compares what happened with what the test case expected.
Each test case is evaluated on its own, so one failure does not stop the others. The run produces a result for every case. It also produces an overall status for the run itself.
Two properties of this flow affect how you work:
- The run is asynchronous. Starting a run returns quickly, and the cases are processed in the background. You either wait for it or come back later with a job ID.
- The agent really runs. The utterances go through the same reasoning path as a live conversation, and actions execute. Treat a run like real traffic, not like a mock.
Before you run
Check these points first. Most "mysterious" failed runs come from this list.
- Run in a sandbox or scratch org. If an action creates or updates records, a test that expects that action will create or update records. Use test data, and make sure no action sends email or calls an external system you care about.
- Confirm the agent is in the state you want to test. Know which version of the agent the run exercises. If you edited a topic but did not save or activate it, the run may not reflect your edit. Check this in your org, because the behavior depends on how the agent is set up.
- Confirm the names in the suite match the agent. The expected topic and action names must match the developer names in your agent. A renamed topic fails every test that references the old name, and the agent is not at fault.
- Confirm the data exists. A test that asks "Where is my order 1001?" needs an order 1001 in the org.
Running from the Testing Center UI
In the UI, the flow has four steps:
- Open the Testing Center from Setup and select your test suite.
- Start the run. The exact button label and location can vary by release.
- Wait while the run processes. The page shows that the run is in progress.
- Open the finished run to see the result for each test case.
The UI suits the first runs of a new suite, because you can open a failing case and inspect it right away. It also suits teammates who do not use a terminal. Its weakness is repeatability: you must click through the steps each time, and you cannot easily attach a run to a build.
Running with Salesforce CLI
The CLI gives you the same run in a scriptable form. This assumes you have authorized the org and created the test definition from your spec, as in the previous chapter.
sf agent test create --spec specs/order-support-tests.yaml --api-name Order_Support_Agent_Tests --target-org my-org
sf agent test run --api-name Order_Support_Agent_Tests --wait 10 --result-format human --target-org my-orgThe first command deploys the test definition to the org. The second starts the run and uses these flags:
| Flag | Meaning |
|---|---|
| `--api-name` | The API name of the test definition to run. |
| `--wait 10` | Wait up to 10 minutes and print the results when the run finishes. Without it, the command returns after starting the run. |
| `--result-format human` | Print readable output. Other formats, such as `json`, suit scripts. |
| `--target-org` | The alias or username of the org that holds the test definition. |
Waiting and resuming
If you omit --wait, or the wait time expires before the run finishes, the run keeps going in the org. You get a job ID and can fetch the results later:
sf agent test list --target-org my-org
sf agent test results --job-id <JOB_ID> --result-format json --target-org my-orgsf agent test list shows the test definitions in the org. sf agent test results retrieves the results of a past run by its job ID. A short --wait is therefore safe: it limits how long your terminal blocks, not how long the run lasts.
Choosing a result format
Use human when you read the output yourself. Use json when a script parses the results, for example to count failures. The CLI also supports formats aimed at test tooling, such as junit. Run sf agent test run --help to see the formats your CLI version offers.
Run status and case results
A run has its own status, separate from the case results. A run can complete while many cases fail. "Completed" means the run finished processing, not that the agent passed.
Read the two levels in order:
- Run level. Did the run finish, or did it stop with an error? An error at this level usually points to setup problems such as a missing test definition or an inactive agent.
- Case level. For each case, did the topic, the actions, and the outcome match? The next chapter covers how to read these results in detail.
Edge cases and gotchas
- Long suites and waits. A suite with many cases takes longer than a small one, because each case is a full agent turn. Set
--waitaccording to the size of the suite, or skip it and fetch results by job ID. - Changes after you start. If you change the agent or the test definition while a run is in progress, the results may mix old and new behavior. Start a new run after you finish editing.
- Flaky cases. Agent replies are not deterministic. If a case passes on one run and fails on the next with no change, do not edit the agent. Run the suite again, then compare. A later chapter covers this.
- Stale test definitions. If you edit the YAML spec, the org keeps the old definition until you update it. Check the
sf agent test createhelp for how to overwrite an existing definition, and always redeploy the spec before you run. - Org mismatch.
--target-orgdecides which org's agent and data are tested. Running against the wrong alias gives results that look valid and mean nothing.
A practical run routine
- Edit the agent or the spec.
- Redeploy the spec with
sf agent test createif the spec changed. - Start the run with
sf agent test runand a wait time that fits the suite size. - Read the run status, then the failed cases.
- If a case fails, rerun once to rule out nondeterminism before you change anything.
Exercise
You run sf agent test run --api-name Order_Support_Agent_Tests --wait 2 --target-org my-org, and the command stops waiting before the suite finishes. Does the run fail? What do you do next?
Show answer
No. The wait time only limits how long the terminal blocks. The run continues in the org. Use sf agent test list and sf agent test results --job-id <JOB_ID> to fetch the results later, or rerun with a longer --wait.
Exercise
A run shows the status "completed", but 4 of 12 cases failed. Is the status wrong?
Show answer
No. The run status describes whether the run finished processing. The case results describe whether the agent matched the expectations. Read the failed cases individually.
Exercise
Why should you run a new suite in a sandbox and not in production?
Show answer
Actions execute for real during a test. A test that expects an action that writes data or sends a message will write the data or send the message.