For the complete documentation index, see llms.txt. This page is also available as Markdown.

Unit tests for scripts

Test scenarios

Creating a unit test

For each script (services and validators), test scenarios can be defined. After clicking the Unit tests button in the left bar, the test panel will open. The panel displays the currently defined test cases for a given script. A new test can be added using the button at the bottom of the panel Add test.

Figure 1. Unit tests panel

Each scenario has the following to define:

  • Test name,

  • Test description,

  • Activity - whether it is run after clicking the Run all,

  • Input parameters - the values we want to test for a given script,

  • Request data,

  • Output verification - the values we expect for the input values provided:

    • Output parameters for services,

    • Message keys for validators.

Figure 2. Test input parameters
Figure 3. Test result verification parameters

Unit test results

We can run the selected test by clicking the icon located on the tile with information about the test scenario. Clicking the Run all button will run all active tests.

The test result can be marked green - the tests ended with the expected result - or red - incorrect result.

After the test is executed, a drawer with logs will appear, containing information:

  • The name of the test that was executed,

  • Test logs,

  • Output value.

If all tests are run, the execution time will be the sum of all test executions. The log drawer contains information about each previous execution, separated by an empty line. The log drawer can be cleared of logs using the button Clear logs.

Figure 4. Test with a positive result
Figure 5. Test with a negative result

Request data in unit tests

When creating unit tests, the application allows simulating the data contained in the request. In the Request data tab, we can add fields that are to return a specified value. We refer to the provided values using the function getValue() available on the context.

Figure 6. Defining request data in unit tests
Figure 7. Result of running the test with request data

Errors during tests

If the script contains errors, the test will fail, and the error will be logged in the console below the editor. The message will include the cause and location of the error.

Figure 8. Error after running the test

Ways to verify output

Script services

We can verify the output of script services in several ways. They are divided into number comparison and text comparison:

Number comparison

Verification
Description

>

Greater

>=

Greater than or equal to

<

Less

<=

Less than or equal to

==

Numbers are equal

≠

Numbers are not equal

When choosing one of the comparison operators above, keep in mind that the script outputs and the values entered for comparison are converted to numbers. If conversion of either value fails, the test will end with a negative result.

For example, for the following data: service output: 6.0, value to compare: 6, comparison: ==, the result is correct. The value 6.0 returned from the script is equal to the value 6 entered in the expected field.

Illustration 9. Test input parameters
Figure 10. Test result verification parameters
Figure 11. Number comparison using the EQ operator ended with a positive result

Text comparison

Verification
Description

EQ

Strings are equal

NOT_EQ

Strings are not equal

~

Matches regular expression

!∅

Non-empty

The data is compared as text. Numbers are also treated as text.

For example, for the following data: service output: 6.0, value to compare: 6, comparison: EQ, the result is incorrect. The text value 6.0 returned from the script is not equal to the text value 6 entered in the expected field.

Figure 12. Number comparison using the EQ operator ended with a negative result

Script validators

We verify the output of script validators by selecting the message keys that will be returned in a given test case.

For example, a script validator returns two error keys with their parameters:

  • pl.error1

  • pl.error2

For the test to end with a correct assertion, both error keys should be on the list.

If we add extra keys or one of the error keys is missing, the test will fail.

Figure 13. Script validator test with a positive result
Figure 14. Script validator test with a negative result

Last updated

Was this helpful?