Adding JSON scenarios
You define unit test scenarios in JSON files. You create one JSON file per
scenario.
About this task
A JSON file consists of three parts: a name, input data, and a list of assertions.
You can retrieve the input data content from Decision Designer by copying a JSON payload from a data set in the Run tab. For more information about the Run feature, see Running models with test data. Alternatively, you can find your data sets in the <model>/resources/validate_dataset folder of your decision library.
You can define one or more assertions in a test. Each assertion consists of five items:
label(optional)- Specifies a name for the assertion. It is displayed when the assertion fails. If no label is
provided, a default value in the format
#<assertion number>is used. pointer- Specifies the location of the value in the output to validate, by using a JSON Pointer. The
following examples are valid JSON Pointers:
""points to the root of the document. For decisions that return a single value, such as a number or a string, it is the only possible pointer."/birthdate"points to the value of the property named"birthdate"in the top‑level object of the output."3"points to the fourth element of a list (index starts at0).
operator- Specifies the comparison operation. The list of supported operators is available in Table 1.
ignoreOrder(optional)- Indicates whether to ignore the order of elements when comparing lists. It is set to
falseby default. expected- Defines the expected value. For most operators, this value is required to have the same JSON type as the actual value, that is, the value at the pointer’s target within the output.
| Operator | Definition | Example | Details |
|---|---|---|---|
⊃ |
Contains |
|
These operators can be used on any type of data. They support the |
⊅ |
Does not contain |
|
|
= |
Equals |
|
These operators can be used on any type of data. They support the |
!= |
Does not equal |
|
|
> |
Is greater than |
|
These operators can be used on numbers. |
≥ |
Is greater than or equal to |
|
|
< |
Is less than |
|
|
≤ |
Is less than or equal to |
|
|
∈ |
Is within a range |
|
These operators can be used on numbers. |
∉ |
Is not within a range |
|
Procedure
What to do next
You are now ready to run your unit tests:
- To run unit tests locally, follow the instructions that are described in Building and deploying from a CI/CD stack.
- To run unit tests in Decision Designer, you
must first push all the content of the
src/testfolder to your Git repository and load it to Decision Designer. When you are ready to run your unit tests, follow the instructions that are described in Building and deploying from Decision Designer. Click the View report iconnext to the test status to see the test results.
Important: Unit tests run every time that you deploy your decision service. Update unit
tests whenever you update the model that you are testing to avoid deployment failures.