> For the complete documentation index, see [llms.txt](https://docs.reorc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.reorc.com/data-modeling/data-tests/custom-generic-tests.md).

# Custom generic tests

Beyond built-in generic tests, you can write custom generic tests to cover complex testing scenarios.&#x20;

At bottom, generic tests are Jinja macros that return failing rows. These tests are considered project-level assets and can be used across different models in your project.&#x20;

To define a generic test, simply write a macro and wrap it within `{% test %} {% endtest %}` block. A generic test should accept one or both standard parameters:

* `model`: The model or resource where the test is applied.
* `column_name`: If the test validates assumptions about a specific column's data, include the `column_name` parameter.

Here's an example:&#x20;

This `payment_amount_reasonable` test receives four parameters: the model, column name, minimum and maximum amounts. Inside, the validation logic is organized into a CTE (common table expression) that queries all the payment amounts not in the reasonable range.

We can apply this generic test to models that store payment amount of different kinds.

```sql
-- custom generic test for the reasonable payment amount

{% test payment_amount_reasonable(model, column_name, min_amount=0, max_amount=200) %}

with validation as (
    select
        {{ column_name }} as payment_amount
    from {{ model }}
    where {{ column_name }} < {{ min_amount }}
        or {{ column_name }} > {{ max_amount }}
)

select *
from validation

{% endtest %}
```

## Create a custom generic test

To create a custom generic test, follow these steps:

1. In your project, go to **Library** > **Generic Test**.
2. Click **+ Add new**.
3. Define the generic test with the following fields:

   * SQL Code: provide the test code.
   * Parameter: hit the **Refresh** button to fetch the parameters involved in the test definition and provide the type.
   * Description: describe the functionality of the test.
   * Category: select the test category that the test should reflect.

   <figure><img src="/files/YLfFccv9BgAC83KdNZ7J" alt=""><figcaption></figcaption></figure>
4. Click **Add**.

## Add a custom generic test

The created generic test is then accessible from **Test case template**. You set up the test the same way as a built-in generic test.&#x20;

<figure><img src="/files/MVWDwbDaU5cuk4kC2M3z" alt=""><figcaption></figcaption></figure>

Specify parameter values in the **Configuration** section:

* **Generic Test:** Select the desired generic test from the dropdown menu.
* **Test Category:** Assign an appropriate category to the test based on its nature.
* **Configuration:** The test script will be automatically populated when you select a generic test from the dropdown.
* **Parameters:** Provide the parameter values.

<figure><img src="/files/5NRystLUIfQvRgPEXUNJ" alt=""><figcaption></figcaption></figure>

Once added, you can verify the test by running the model in [Console](/asset-management/console.md).
