# Tests

Tests are suites that run a Web Agent's actions inside your app. Faustine generates the cases from the agent's actions, and a run executes them in a page of your app, with the session of the user who is signed in there. They live in the agent's **Tests** tab.

## How it works

A suite is a list of cases. Each case calls one or more actions and checks the result. Faustine writes the cases from the draft: it works out what each action creates, reads, updates or deletes, and which action undoes each create.

A run does not happen on Faustine's servers. The portal sends the suite to a page of your app that has a debug session open, the page executes the cases with its own actions, and the results come back to the portal as each case finishes. The actions make the same requests they make for the agent, against the same backend.

Tests run real actions. Run them on an environment with test data.

## Kinds of suite

**New test** offers three ways to create a suite.

| Option | What it generates |
| --- | --- |
| **Full coverage (recommended)** | One lifecycle chain for each module and one case for each remaining action, with sample parameters. |
| **Manual selection** | Cases for the modules and actions you select. |
| **Custom, with the AI editor** | Opens the Advanced editor, where you describe what to test and Faustine writes the cases. |

Generation runs on your model provider and takes a few minutes.

## Lifecycle chains and cleanup

A lifecycle chain orders the cases of one kind of record so that each uses what the previous one made: create a customer, read it, update it, delete it. The cases of a chain share values, such as the ID of the record the first case created.

A case that creates something has a cleanup. Cleanups run at the end of the suite, in reverse order, including when the run is cancelled.

When an action creates a record and the agent has no action that undoes it, the suite cannot clean up. The portal marks the suite with **leaves state**, and each run leaves records named "Faustine Test" in your app.

## Runs

A run needs a page with a debug session. See [Open a debug session](https://docs.faustine.ai/web-agents/debug-sessions/). Each suite keeps the history of its runs.

A run records, for each case:

- The result: passed, failed or skipped.
- Each action the case called, with its input, its output and how long it took. The portal keeps the first 40 calls of a case.
- What the case printed to the console, up to 50 lines.
- The error of its cleanup, if the cleanup failed. A failed cleanup does not fail the case.

A case is skipped when it is disabled in the suite, or when the page's version does not have the action. The run records the reason.

| Run status | Meaning |
| --- | --- |
| `passed` | No case failed. |
| `failed` | At least one case failed. |
| `cancelled` | Someone cancelled the run from the portal. The cleanups of the cases that ran were executed. |
| `aborted` | The page reloaded, closed or lost its session during the run. The results that arrived are kept, and the cleanups did not run. |

## Fix a failed run

A run with failures has a **Fix in AI editor** button. It opens the Advanced editor on that run. Faustine reads the failures, groups them by cause and changes the case or the action, depending on which one is wrong. See [The Advanced editor](https://docs.faustine.ai/web-agents/advanced-editor/).

## What to know before you run a suite

| Consideration | Description |
| --- | --- |
| The actions are real | A case that creates a customer creates it in the backend the page talks to. |
| The user is real | The run has the permissions of the user signed in to the page. Actions that user cannot perform fail. |
| Production asks first | A run on a page of the Production environment needs a confirmation. Debug sessions are off on Production by default. |
| One run at a time | A suite has one run in progress, and a page runs one suite at a time. |

## Next steps

- [Generate and run a test suite](https://docs.faustine.ai/web-agents/run-a-test-suite/): create a suite and run it in a page of your app.
- [Open a debug session](https://docs.faustine.ai/web-agents/debug-sessions/): connect the page the suite runs in.
- [Turn an action on or off and test it](https://docs.faustine.ai/web-agents/test-an-action/): run a single action instead of a suite.
- [The Advanced editor](https://docs.faustine.ai/web-agents/advanced-editor/): write custom cases and fix failures.
