# Recipe: refactor and test a workflow

> Use a coding agent to review an existing RPA workflow, improve its error handling, and add a test case that proves it still works.

This recipe takes a workflow you already have, improves its structure and error handling, and adds a test case that proves it still works. It shows that a coding agent is useful well beyond the first build.

## Prerequisites

- A coding agent set up for UiPath work, with an authenticated session (see [Install and set up](install-and-set-up.md)).
- An existing UiPath project with at least one workflow.

## Refactor and test

1. Open your coding agent in the existing project folder.
2. Ask it to review first, without changing anything:

   "Review `Process.xaml` for missing error handling, risky activity choices, and unclear structure. List the findings with severity. Do not fix anything."

3. Review the findings and decide which to apply.
4. Ask the agent to apply those specific changes.
5. Ask the agent to add a test case that covers the main path:

   "Add a Given-When-Then test case for the happy path of `Process.xaml`, and register it in the project."

6. Ask the agent to run the Workflow Analyzer and the test.
7. Resolve any problems it finds.
8. Review the diff and the test result before you accept the changes.

**Result:** a cleaner workflow with better error handling and a passing test that guards it.

:::note
The findings, the file layout, and the run commands vary by agent, project, and prompt. Confirm success from the test result and your own review of the diff, not from the agent's "done" message.
:::
