Structure of JSON TestCases

In addition to the Modules that you create by scanning, you can also use Modules from the Standard subset in your JSON Engine 3.0 TestCases. You can find the following Modules under Standard modules->TBox XEngines->JSON:

In your TestCases, you can add, edit, or verify all elements listed in the table "Business-based control types":

  • Insert: add new JSON elements.

  • Input: modify existing elements.

  • Verify: verify values. Properties of control types are specified in the Value column for editing.

Verify the occurrence of an element

The property Exists verifies whether an element occurs in a JSON file or not. The value is True or False accordingly. The ActionMode is Verify.

The JSON file books.json is loaded into the resource json.

The task is to verify whether the element title occurs in the JSON file which contains the element lang with the value en, and the element text with the value Everyday Italian.

Verifying the existence of a JSON element

Examples

The TBox package contains sample Modules and TestCases for JSON. Some of these examples are described in this chapter.

Before executing the TestCases, the test configuration parameter ExampleDirectoryJSON must be defined. The directory to be used for saving the JSON files during test execution must be specified.

The created JSON files are saved to the directory D:\JSON examples in this example.

Test configuration parameter ExampleDirectoryJSON

Boolean values

In the example below, the TestCase Boolean is described in greater detail.

  1. TestStep 1: the JSON Resource boolean is created using the Module Create JSON Resource.

  2. TestStep 2: the Module Fill JSON Resource with boolean values is used in order to provide the structure of the underlying JSON file. The object flags and the subsequent values yes (true) and no (false) are added.

  3. TestStep 3: the content of the Resource boolean is saved to the file entered in the TestStepValue Filepath by using the Module Save JSON Resource as file.

  4. TestStep 4: the file saved in the previous TestStep is loaded to the Resource boolean2 by using the Module Open JSON file.

  5. TestStep 5: the values of the yes and no elements of the superordinate element flags are verified.

Example - Boolean values

Numbers

In the example below, the TestCase Number is described.

  1. The XModule Create JSON Resource is used to create the JSON Resource number.

  2. In both of the following TestSteps Fill JSON Resource with numbers and Verify the numbers, the same Module of a JSON file is used.

  3. The JSON object multiple numbers including the values positive (345), negative (-345), decimal (78.345), and negative decimal (-78.345) is added in the TestStep Fill JSON Resource with numbers.

  4. The previously added values are verified in the TestStep Verify the numbers.

Example - Numbers

String values

In the example below, the TestCase String is described.

  1. The Resource string is created using the XModule Create JSON Resource.

  2. The same JSON file Module is used in both of the following TestSteps Fill JSON Resource with a string and Verify the string.

  3. The root element containing the string simple string with the value this is not a word is added in the TestStep Fill JSON Resource with a string.

  4. The previously added string is verified in the TestStep Verify the string.

Example - String

Arrays

In the example below, the TestCase Full array is described in greater detail.

  1. TestStep 1: the JSON Resource array is created using the Module Create JSON Resource.

  2. TestStep 2: the Module Fill JSON array is used in order to provide the content of the scanned JSON file.

    The values domino, 000, false, and an empty value are added to the array element.

  3. TestStep 3: the content of the Resource array is saved to the file entered in the TestStepValue Filepath by using the Module Save JSON Resource as file.

  4. TestStep 4: the file saved in the previous TestStep is loaded to the Resource array2 by using the Module Open JSON file.

  5. TestStep 5: the values of the element array are verified.

Example - Array