Working with JSON files
For more information, see Managing test data.
JSON is a text file that can convert to any JavaScript object and can be sent to a server. You can also convert any JSON received from the server into JavaScript objects. This way you work with the data as JavaScript objects, with no complicated parsing and translations. In ApplinX, you could generate the procedure with initial file Data.json file containing the default inputs and assertions given by the procedure. For example, the following input and output parameters:
{
"inputs":
{
"Code":"cu"
"Password":"demoy2",
"UserId":"demo02",
"structure1":
{
"Birthday": null,
"Customer_ID": null,
"First_Name": null,
"Last_Name": null,
"Sex": null,
"TotalPoliciesAmount": null,
"Type": null
}
}
"Assertions":
{
"Firstname":"Charles",
"House_Number":"12",
"Lastname":"Chappell",
"Mobile": null,
"Municipal_Code": null,
"Nationality_Long":"British",
"Nationality_Short":"UK",
"Occupation_Long":"Actor",
"Occupation_Short":"81177",
"PO_Box": null,
"Person_Sex":"M"
}
}
Working with arrays
You can also provide input using an array. The runTest method is provided for sending inputs from a given JSON file to the Base Object and verifing the assertions from the JSON file, using the response data.
Each input entry in the JSON file is converted to GXElement so that the procedure can run. Each output attribute given by the Base Object response is converted to a JSON object and compared with the assertion loaded from the resources folder automatically.
JSON configuration file
The JSON configuration file enables you to change the following values for running the tests:
{
"serverPort": "2323",
"serverAddress": "localhost",
"apxUser": "administrator",
"apxPassword": "",
"hostApplication": "SAG_MainFrame"
}
Parameter hostApplication is mandatory; all others are optional. If a parameter is not defined, the test will try to run with the default value.
If parameter hostApplication is not defined, the test will run on actual application host.
Working with multiple JSON files
The following mechanisms are provided to enable you to work with multiple JSON files:
* (asterisk)
any files
f1.json, f2.json...
list of files
The following rules apply:
- The file extention must be .json.
- The list must not be recursive.
- The file name must be valid for the operating system.
Example:
public static Collection <Object[]> getTestData() {
String[] fileNames = {"file1.json", "file2.jsOn"};
return TestCase.getTestData(fileNames);
}
The default filter for test data is "*".
Comparing the results of a unit test
If a failure occurs in a unit test, you can use a compare function to easily locate the source of failure.
To compare the actual results of unit test with the expected results
Double click the line org.junit.ComparisonFailure in the JSON file. For more
information, see (1) in screenshot below.
Alternatively, Select the line in the marked rectangle area (2) in the screenshot below, and from the context menu choose Compare Actual With Expected Test Result.
Alternatively, Select the line and click the Compare icon
. For more information, see (3) in the screenshot below.
This produces the following output, where the discrepancies are highlighted.