# Automated tests

Automated tests are an important component for maintaining the integrity and reliability of knowledge maps. By automating the testing process, authors can ensure that any changes or updates to the knowledge map do not adversely affect its behaviour. These tests can be configured to simulate various scenarios, verifying that the knowledge map produces consistent and expected results. With the ability to run tests against a draft version of the knowledge map, authors can identify and rectify issues before they impact the live system. Automated testing not only streamlines the quality assurance process but also significantly reduces the manual effort required to maintain the knowledge map's accuracy over time.

<figure><img src="/files/QmpfIMBrP8KuUiHg19Yj" alt=""><figcaption><p>Automated tests</p></figcaption></figure>

## Setting up an automated test

When creating a new automated test we start by entering the query we want to test.

Enter the relationship name with either the subject or object instance (or both). Clicking `Next` will auto-populate the next step in the test. (Add the next step manually with the circular + button)

In the example below it displays a question being asked. You can type the test response and click next to auto-populate the next step again. (For plural answers click + under the answer to add more than one answer)

This can be repeated until you get to the result.

<figure><img src="/files/JXIzRYkO8KrTu7W4NrAm" alt=""><figcaption><p>Creation of an automated test</p></figcaption></figure>

{% hint style="info" %}
When configuring a question response, you can enter the subject, relationship, object and certainty factor to respond with (if a second form question) or a yes/no response in the event of a first form question being asked.

You can also choose to provide no response to a question (if the map is configured to allow this). This will be presented as 'Skip response' when the test is saved.&#x20;
{% endhint %}

Note that you should always finish an automated test with an expected result; even if no response is expected, you can specify 'No result'.

## Running an automated test

Once a test has been created it can be run at a later date to verify that the query runs as expected.

All tests can be run with the `Run All` button, or they can be run individually with the play button on the test itself.

There are two possible causes for a test to fail:

**Unexpected question or result**

If Rainbird returns a question or a result that wasn’t expected, then a test will fail. It’s worth noting that questions are expected in the order defined in the test and it will fail if this is not the case.

If an unexpected result is received, the evidence tree can be accessed to view the chain of reasoning and validate if the result is correct or why it has produced an unexpected result.

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

**HTTP failure: 400 bad request**

The request may fail if the response is not consistent with how the knowledge map is configured, for example, responding with multiple answers to a question whose relationship is singular. Where the request doesn't fit the expected response, a HTTP 400 Bad Request error is returned.

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

## Exporting and importing automated tests

You can export automated tests as JSON. This allows for changes to be made easily in a text editor, making batch wording changes easier if a concept instance or a relationship has been renamed. Tests can then be imported back into the Rainbird Studio.&#x20;

The export/import function also allows tests to be copied across to different knowledge maps and shared with other authors.

## Best practice

Create tests that isolate specific areas of functionality. i.e. each time you add a rule to a relationship, you could create a test to isolate and test that specific rule.&#x20;

There are two types of tests you can create:

{% tabs %}
{% tab title="Results only" %}
Confirms specific result(s) are returned given a set of test data. This uses the `inject` functionality to provide all necessary data for the test to bypass any questions being asked, whilst being able to confirm the correct result is still given.

These are beneficial if you want to test the output, without testing the order or display of questions.
{% endtab %}

{% tab title="End-to-end / interaction testing" %}
Test the entire interaction from start to finish, including the ordering of the questions and the question text that is displayed.

It is best to create this type of test after you confirm the behaviour meets the expected user experience of your solution, otherwise small changes to question wording can result in a lot of tests to update.
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rainbird.ai/rainbird/knowledge-modelling/testing-your-km/automated-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
