# Test cases for an agent

Generate tests from the prompt, run them before every change and see where the agent answers wrong.

> Full REST + WebSocket API reference: https://api.happ.tools/reference

## Why [#why]

Prompts change often and checking an agent by hand takes time. A test case pins the expected behaviour: "asked about delivery, the agent quotes the terms from the knowledge base". A run shows what broke before customers see it.

<Steps>
  <Step>
    ### Generate cases [#generate-cases]

    Open the agent, **Test** tab, click &#x2A;*Suggest (AI)** and **Generate**. Happ reads the prompt, tools and knowledge base and proposes cases. Keep the ones you need and click **Save selected**.
  </Step>

  <Step>
    ### Mock the actions [#mock-the-actions]

    Tools run for real in tests. For actions that change something (creating an order, writing to a CRM) set mocks in the case or in the shared test settings.
  </Step>

  <Step>
    ### Run them [#run-them]

    Click ▶ on a case or **Run all**. Before the run Happ shows the number of cases and a cost estimate; runs spend the LLM balance.
  </Step>

  <Step>
    ### Read the result [#read-the-result]

    Open the run: each case has a transcript, the judge verdict and the reason. For a red case click **Suggest prompt fix**.
  </Step>
</Steps>

<Callout title="A habit that pays off">
  Run all cases after every prompt edit. If the agent ever got a customer wrong, turn that conversation into a new case.
</Callout>

## Next [#next]

* [Agent versions](/docs/agents): roll back to a version where every test was green.
