Using JSON for Interface Testing

Using JSON for Interface Testing: 

Interface testing verifies the communication between two different systems. It is performed on the application under test to verify if the to and fro communication between two networks are correctly performed.

An interface is basically the connection between two software systems and testing that connection for data transfer is called Interface testing. The interface covers a wide range of services in the real world, it can be used to refer to Web service, API, etc.

Interface Testing

An Interface contains a set of rules, messages, commands etc that facilitates communication between two systems.

This testing mainly concentrates on testing of two major segments:

  • Database and application server communication
  • Web and Application server communication

Interface test is performed to evaluate the above-mentioned scenarios to validate whether the components are correctly passing the control and data to one another correctly. It also verifies the interaction between different modules.

Why is Interface Test Performed?

It is performed to ensure:

  • IIf the communication between the systems is performed correctly.
  • All software and hardware that are used in the system are performing correctly.
  • All the documents that are linked to the communication are available on all integrated platforms.
  • Security and encryption requirements adhere to the communication between the systems.
  • The integrated components are able to handle network failures and communication loss.

Types of Defects Found

Most of the defects found in the user interface testing are due to incorrect mapping of the data between the systems. Hence, most of the bugs can basically be classified into the following categories.

  • Inconsistent data transmission between the two systems.
  • One of the systems misinterprets data transmission from another system.
  • The transmission channel or interface between the two systems fail and that restricts the data transfer between the systems thereby causing the entire interface to fail.

How is it Performed?

It can be mainly categorized into the following phases:

  • Interfaces can be tested individually during system testing. This type of testing is mainly carried out using stub or dummy system. A dummy system or stub impersonates the behavior of the whole system interaction.
  • Another instance where the interface test is performed is a junction where two systems are communicating with each other.
  • Hence, we test if the data sent by one system has been correctly mapped and inserted into another system or not. Other than the data insertion we also check for data integrity, i.e. the data, when inserted into another system, has not been manipulated or altered, etc.
  • Testing can also be carried out when a system transmits data to another application database. Here, we will test if the data from one system has been correctly inserted into a given column of the given table based on the mapping. We will also test the data integrity and data consistency with respect to the source system.

In all these testing scenarios, interface test is performed based on the business requirements and business flow rules.

Difference Between Interface Testing and Integration Testing

Verification and validation of end to end functionality of components connected together are called Integration testing or more popularly as System Integration testing. Integration testing mainly validates if two or more system integrated together has been working flawlessly together or not.

Testing Interface on the other hand basically concentrates on the connection channel between the two systems. The connection channel between two or more system is called an Interface. Testing of this connection channel is called Interface Testing. Most of the interfaces are either, APIs or web services. It doesn’t have a UI but takes an input and presents the user with an output.

For Example

Interface Testing

In the above example, the website and the database share an interface to transmit the login information i.e. Username and password.

The interface uses web service to send the login information to the database, which in turn validates the authenticity of the incoming message (username and password) and returns the value as true if both the username and password match with the record present in the database or false in case if any of them or both the username and password does not match with the data present inside.

Let’s discuss interface testing example:

Let’s say we have an application where we have different databases interacting with each other.

In this example, we will consider two database interaction through an interface channel.

Let’s consider there are two databases or application, database A and B. “A” transfers some data to “B”, which is then used by B to perform some operation. After performing a certain operation on the incoming data B inserts that data into the database and creates an output JSON for confirmation with the list of updated data and sends it back to A.

Both A and B use interface channel for communication between them.

Business Scenario

“A” contains employee data for all the employees belonging to the finance department.

The data needs to be ported to “B on a daily basis. “B” contains data about general employee details. All the data from “A” needs to be transferred to a particular table and column of “B”. Other than the entering data “B” also needs to sort and organize data. It also needs to make sure whether the data has been entered against the correct employee.

Once the data has been entered into the system, “B” should send an output JSON to confirm if the data has been inserted into the database.

In case of any discrepancy in JSON schema or missing data “B” will not process the data and it will send a Reject JSON message with the reason for rejection.

Business scenario of interface testing

Test Environment Setup

To test a scenario like this one, we will need a test stub to mimic database “A”. The developer can provide a location where you can either dump your test JSON or a mock UI and paste your JSON data and invoke the processing through the interface. For testing purpose, we can also have an output location where we can receive the confirmation JSON from “B”.

In our example, we will use a folder path where we will put our test JSON, the service will be constantly poking the location for JSON file. Once the file is present, the service will pick up the file and send it to “B” via the interface. Once the file has been picked up, it will be deleted from the pick-up location.

Starting your Testing

Once the test environment has been set up, the next step is to create the test data.

While creating test data (read test JSON) we should keep a few things in mind:

  • Follow the business rules.
  • Make sure the mandatory fields are present.
  • Change the value of the fields according to the business rules for each test.
  • Make sure JSON schema is in the correct format.
  • Make sure nomenclature for the JSON filename has been adhered.

Let’s have a look at the sample test JSON we will use for testing:

"employeeID ": 2569875,
"LastName": “Jackson”,
"baseSalary": 2569,

"Year": 2017,

Begin your Test

Once you have created your test JSON file, drop it at the pick-up location. The service will pick this up and post it into database B.

Scenarios to test:

There can be a number of scenarios that need to be tested for this example like:

  • Working with the web service to send and receive data.
  • Data integrity for the input data. This can be validated by querying tables and columns in database B for the data entered through the test JSON.
  • Negative scenarios.

At first, we will check if the test JSON file has been picked up from the location or is not present at the location. This will validate the working of the service. Next, we will navigate to the output folder to view the output JSON. Presence of output JSON validates if the input data has been sent to database B and acknowledgment for the same has been received.

The next part of testing comprises of validating the data entered into the database.

In the above test, we will validate if the data sent through the test JSON has been correctly entered into the database. We will validate data integrity, data consistency and data insert. We will have to query database B for the given column in a particular table to validate if the data has been correctly inserted into the table.

Let’s say we have EmpDetails table where the data has to be inserted. So, we will run a query to validate the data.

The query will be something like this:

SELECT employeeID, LastName, baseSalary, DesignationCode, Month, Year, Official, Others
FROM EmpDetails
Where employeeID = 2569875;

Here, we will be using the employeeID as the primary key for querying the data in the EmpDetails table. We will query using all the column name in which the data has been inserted. Then the data in the column name can be validated with the data sent through the JSON.

In the above case the data from the JSON is being stored in more than one table in the database, hence you can use SQL JOINS to fetch all the desired data.

The third step in testing will be to test the negative scenarios.

Some of the negative scenarios that can be tested are:

  • The behavior of the system when incorrect data is fed through JSON.
  • When the JSON has the wrong schema or structure.
  • When the processed JSON is missing the primary key or any mandatory fields.
  • Nomenclature of the JSON file is not valid.

In all these cases, the system should be able to handle these scenarios and no data should be inserted into the system as per the business rule.


The connection channel between two systems through which data is transmitted is called an Interface and Interface testing mainly works around the testing of these connections. Most of the interfaces make use of Web Service or APIs. It doesn’t always have a UI but it does accept input and provide output.

Being one of the most widely used data transfer formats, JSON can be used for interface data transfer.

A tester needs to have basic JSON structure knowledge to create test data (in the form of JSON) and to read output data from the system. A tester should also be well-versed with the mapping between JSON keys and database table-column.

Any tester who wants to work on Interface testing should have a clear knowledge about the business guidelines and the rules of an application. A tester should also have adequate knowledge about the database and should be able to write simple SQL queries.

For any question or clarification please do get in touch with us in the comment section.

Tutorial #5: JSON Interview Questions