> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts.md).

# Testing scripts

### Introduction

The `build & test` page includes an integrated test panel, to the right of your code. Here, you can build up realistic test inputs — a sample payload, plus any variables your script uses — then run the script and inspect the output, logs and errors.

{% hint style="info" %}
You don't need to deploy a script in order to test it. The `run` button builds and executes the version you're viewing in the background — nothing that's live is affected.&#x20;
{% endhint %}

### Test inputs

Select the `test inputs` tab to set up your test data.

#### Payload

Add/paste a payload that can be used to test your script — for example:

<div data-with-frame="true"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FSVy9J3X7E0Sg3v0hsyFr%2FTest%20Script%20input.png?alt=media&amp;token=4914fbc8-18b9-4794-9337-835726d46d12" alt=""><figcaption></figcaption></figure></div>

#### Standard inputs

Every script — whatever its [type](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting#script-types) — receives the standard inputs, as key/value pairs. Use the `add variable` option in each section to build up your test values:

<div data-with-frame="true"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FhFsiSw821xiBrmMSByo4%2FTest%20Script%20Input%20Variables.png?alt=media&amp;token=6c405b82-263e-4696-be5b-7f99168065be" alt=""><figcaption></figcaption></figure></div>

| Input          | Summary                                                                                                                                                                                             |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Variables      | Key/value pairs for any [variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables) your script references.         |
| Flow variables | Key/value pairs for any [flow variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables) your script reads or updates. |
| Metadata       | Key/value pairs for any payload metadata your script works with.                                                                                                                                    |

### Running a test

Make sure your latest changes are saved, then click the `run` button — the button confirms which version will be run (for example, `run v3`, where `v3` is the version you're currently viewing).

The script runs against your test inputs, and the results are displayed in the `logs` tab.

### Reviewing results

When a run completes, the time taken is displayed (for example, `ran in 95 ms`), and results are organised into three tabs:

| Tab    | Summary                                                                                             |
| ------ | --------------------------------------------------------------------------------------------------- |
| Logs   | Any log messages written by your script during the run — useful for tracing how the script behaved. |
| Output | The result returned by your script — typically your transformed payload.                            |
| Errors | Any errors raised during the run — if the script failed, look here first.                           |

For example, the `output` tab after converting an XML payload to JSON:

<div data-with-frame="true"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FWTNFQRf3W4AHsngFGaPP%2FTest%20Script%20output.png?alt=media&amp;token=17f1b44e-16a7-4d40-b85a-ac4e0708a50a" alt=""><figcaption></figcaption></figure></div>

From here you can `pretty print` the result for easier reading, `copy` it to your clipboard, or `download` it as a file.

Keep refining and re-running until you're satisfied that the script is working as required.

### Next steps

Once testing is complete, you can:

* [Deploy the script version](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/deploying-scripts-and-managing-versions) so it can be used (and update any flows already using this script).
* [Apply a payload-level script to process flows via the script shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/script-shape).
* [Apply a field-level custom script to field transformations via the map shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/map-shape).
