In this article you will find out

1, the basic concept of interface test, including what is the interface, what is the interface test, why to do interface test 2, interface test case design 3, how to do not write code, also can quickly according to the development of API documents to complete interface automation test script

Note: If you are familiar with the basic concepts of interfaces and interface test cases, you can skip them.

Suitable for this group

1, before learning interface test from entry to give up the primary test engineer

2. Test engineers who want to write interface test scripts quickly (highly recommended)

3. Developers who need to write their own interface test scripts for some reason (for example, the company does not have full-time testers) (highly recommended)

Basic concepts of interface testing

First, learn about the object under test: the interface

Interfaces refer to the interaction points between external systems and between internal subsystems.

It includes external interfaces and internal interfaces. Internal interfaces include upper-layer and lower-layer service interfaces (for example, the Serivce layer invokes the DAO layer interface) and interfaces at the same level (for example, when a user is registered, the interface for querying user information is invoked first to check whether the user is registered).

Both internal and external interfaces are generally in the form of APIS. Usually, the API interface documents should contain the following: interface description, interface URL, request mode, request parameters, parameter type, parameter description, value restriction, Mandatory or not, returned parameters, and success and failure examples.

Then learn about the testing activity for interfaces: interface testing

The broad understanding of interface testing is to test the module or system interface;

The narrow understanding of interface testing is to test the input parameters of the interface, the interface processing logic and the return content of the design.

Interface test format: single interface test (including performance test) and scenario test through interface call.

Interface test principle: through the tool or their own code, simulation client (according to the test case to define the request parameters) to the server to request access to the interface, check whether the content returned by the server is consistent with the expected value.

Interface testing process (only in iteration) : Requirements review -> Interface definition -> use case design -> scripting -> Executing scripts -> Result analysis

Finally, understand the significance of interface testing, namely: why do interface testing

To put it simply, reduce testing costs and improve development efficiency.

In full:

1. Interface testing is relatively easy to automate continuous integration.

2, the interface test can make the test early intervention, find potential problems; Ensure interface quality and improve the development efficiency of front-end and back-end joint debugging.

3. It is easy to verify the security of the interface test: whether the front and back ends are unified checksum and whether sensitive information printed (sensitive information returned by the interface) is encrypted.


Design of interface test cases

The single interface test case design is only described here. The scenario interface test case design is implemented by invoking the interface just like the scenario test case of UI functionality.

Design interface test cases, mainly from the interface input parameters, interface processing logic, interface return parameters and other three aspects:

1. Design test cases of interface input parameters. Common parameter types include: numeric value, string, array or linked list, and structure

For these types of inputs, we usually design test cases through equivalence class methods and boundary value methods

Equivalence class method: pay attention to the case where the value is within the range and the value is outside the range; Usually, the interface does not return the correct error message when the value is outside the range.

Boundary value method: pay attention to the boundary value of the value range and the data type boundary value of the input parameter; Data type boundary value overflow is a common problem, such as the maximum and minimum values of int data.

To complement the use cases, consider special values such as 0, null, NULL, negative, non-specific type, and repeated values; It is common for an interface not to handle the logic properly to cause an abnormal exit.

2. Design test cases of interface processing logic, mainly to verify whether the front and back ends are unified verification

For the interface processing logic, through the analysis from the Angle:

Constraints analysis, common constraints: numerical restrictions, status restrictions (login status), relationship restrictions (bound to a certain relationship), permission restrictions (member, non-member, etc.).

For example, if the project ID is PJ000 and belongs to user A, the interface accessing the project needs to transmit the project ID. When user B uses the ID of PJ000 to transmit parameters, check whether the project cannot be accessed.

State transition analysis, such as coupons used, whether the interface can still be used, etc.

Timing analysis, such as non-sequential execution of processes, whether data anomalies occur.

3. Design test cases of interface return parameters

The interface processing logic is analyzed from the following perspectives:

Return result analysis, overwriting all return codes.

Analysis of interface timeout: Usually occurs when the interface timeout is not handled. As a result, the process is blocked or an interface response is received after the timeout, resulting in logic errors.


3, Do not need to write Code, also can do interface tests: No Code, Still API Test

No need to write code, you can also do a good job of interface testing, of course, with the help of a magic device, to complete the work, this magic device is called: eolinker, the official website www.eolinker.com

Before using Eolinker, I used Jmeter for interface testing, and Python Requests before using JMeter. I think JMeter is more efficient, which is reflected in the following aspects:

1, testing does not need to write code, we know that writing test scripts with test code is the same as developing and writing product code, which needs to compile – debug – test – maintenance, for testing, need to consume too much time and energy, unless the company has someone to do test development.

2. UI mode, just fill in the blanks, very simple, at most write a few function calls or assertions with Beanshell

For interface testing, I only use eolinker’s automated test function module. For other functions, I can learn by myself after registering my account on the official website. Here I only mention the characteristics of Eolinker automated test function module, which is also the reason why I choose it:

1, the development of API documentation and test interface test script writing, can be carried out on Eolinker, so when writing the test script, you can directly from the Eolinker API document function module, import API interface, write the test script only need to add assertions, and parameters to be passed.

2, support UI and Code two writing mode, that is to say, you can complete the test script design through UI filling in the blank, you can also write JS Code to complete the test script design, there are official tutorials.

3. The returned parameter content of the interface before calling is used as the request parameter of the current interface. Eolinker provides correlation function, which can be completed by dot and dot, more convenient than Jmeter.

4, also provides more advanced code injection function, can be in the request interface, do some pre-processing, such as the request parameter value encryption, etc., can also return the content of post-processing, such as the interface returned content of a field value, set as a global variable

5, test result assertion provides four ways: Json verification, XML verification, full match, regular match, the most used is Json verification, if you want to verify a field content, do not need to write the re, as long as the field name to verify directly can be.

6. Test cases can be executed regularly, and the test report can be sent to the email box of the specified personnel after execution.

Writing interface test case scripting workflow: developing and writing API interface documentation -> importing developed API interface, testing according to the prepared test cases, writing test cases


Taking an Eolinker “Add Interface Item Interface” test as an example, do the following:

1. Compile API interface documents named “Add Interface Item” and “Query Item List”

2. Import API interface and write test case of “Adding project successfully” :

A. Add items and verify the return code.

B. Invoke the Query Item List interface to check whether the item is added successfully. (Like this new interface, I used to check, used to connect to the database, and then look up the table content, found that the script execution, the speed is a little slow, later used to call the query list interface method check)

3. Execute the test script and view the test report.

The Pre prepared

Interface 1: Adds an interface item interface

Add the request header for the interface item

Add the returned content of an interface item

Interface 2: interface for querying the item list

Query the header of the item list interface

Query the returned contents of the item list interface

From the above two API documentation information:

Note: In the actual project, there is a developed API document, which may be on Word, RAP or Eolinker. Here, I just take the information of two interfaces through F12 (as shown below) and write two incomplete API documents as operation examples in this paper.

Interface 1: Adds an interface item interface

Interface URL:www.eolinker.com/apiManageme…

Request method: POST

Request parameters:

CompanyHashKey projectName projectVersion: 1.0 projectType: 0

Returns the content: {” type “:” the project “, “statusCode” : “000000”, “projectHashKey” : “Nr2PNlf82c6a7995d30286e041944fd40e4c01d58b3edeb}”

Interface 2: interface for querying the item list

Interface URL:www.eolinker.com/apiManageme…

Request method: POST

Request parameter: companyHashKey

Return content: {“type”:”project”,”itemNum”:4,”statusCode”:”000000″,”projectList”:[{“projectHashKey”:”83uUHhud0519435001f268f0871eee880 90cc68dc00cac7″,”projectName”:”demo_project”,”projectType”:0,”projectDesc”:””,”projectUpdateTime”:”2018-10-08 18:26:57 projectVersion “, “” :” 1.0 “, “userType” : 0, “permission” : {” userType “: 0,” endTime “:” 2099-01-01 “, “isExpire” : 0}}}]

Step 1 Prepare and add API interface documents named “Add API Interface Management Item” and “Query Item List”

Step 2 Import the API interface and write the test case of “Adding project succeeded”

Note: login is required to access the interface. This time, I will not say the content of interface authorization, and I will do a special topic later. Here, I directly simulate the login state with cookie

Note: Regex is used here because the projectList returned is an array. Array validation is not currently supported in JSON validation

Step 3 Run the test script to view the test report

Run the test script and view the test report

This is a quick way to write a test case script! (Click all the tests, make a cup of tea, and come back to see the test report!!)

Supplement:

1. For logging in, the process of obtaining interface authorization can be written to a pre-use case (and also post-use cases), like setUp and tearDown in Python UnitTest. 2, there is a separate environment management module, including setting the default hostname, request header information, global variables and additional parameters, etc., see the previous picture

Environment Management Interface

Conclusion:

This paper describes the interface and interface test to the interface test learners, through the understanding of the basic concept of interface test, and then master the interface test case design methods and ideas, finally with the help of excellent tools, to achieve simple and fast work effect;

Some tests may use a lot of code to write automated test scripts in order to show that they are developers and can write code. I also mentioned that testing code is very expensive. Of course, it is not suggested that testing can be developed.

We can go to develop some testing tools to assist their own testing work, on the one hand to exercise the development ability, on the other hand to understand the operating principle of the software, convenient testing process, more clear software internal structure;

Projects usually give us little time for testing. In order to ensure that the project is completed on time with quality and quantity, it is urgent for us to work in a simple and fast way. Therefore, we can use some excellent tools to achieve our goal.

END…