Method and device for automatically testing interface and electronic equipment

By obtaining and converting interface documents, designing interface test cases and instantiating script templates, the problem of multi-interface testing in the prior art is solved, and the effectiveness and accuracy of automated testing is achieved.

CN119149420APending Publication Date: 2024-12-17NEUSOFT REACH AUTOMOBILE TECH (SHENYANG) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411272680.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Existing interface testing tools are difficult to effectively handle multi-interface testing with dependencies and cannot provide automated testing solutions.

Method used

By obtaining interface documents and converting them into interface database files, designing interface test cases, using interface dependencies fields as ordered lists, automating testing of multiple interfaces with dependencies is achieved, instantiating and executing the target script template, and generating tests Results and reports.

Benefits of technology

It realizes automated testing of multiple interfaces with dependencies, alleviates the problem that traditional technologies cannot perform automated testing and improves the efficiency and accuracy of testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149420A_ABST
    Figure CN119149420A_ABST
Patent Text Reader

Abstract

The invention provides an automatic interface testing method and device and electronic equipment, the automatic interface testing method is an automatic testing technology adapting to interface relevance, an interface dependency field in an interface testing case is an ordered list, the ordered list is used for storing at least one interface identifier, and the interface dependency field is used for storing at least one interface. If the number of the interface identifiers is more than one, the interface test cases corresponding to the interface identifiers are interface relevance test cases, so that automatic testing is carried out on a plurality of to-be-tested interfaces with dependency, in addition, the interface test cases are adopted to instantiate the corresponding target script templates, and then the test scripts are obtained; automatic testing of a plurality of interfaces with dependency can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of interface testing, and in particular to a method, a device and an electronic device for automatic interface testing. Background Art

[0002] In the software development process, interface testing is an important part of ensuring software quality. It can help the development team discover and solve potential integration problems at an early stage and ensure normal interaction between different modules. Interface testing is a type of software testing. Its purpose is to replace the front-end page or third-party caller when the front-end component is not integrated to verify whether the interface parameter transfer, function implementation, output results and fault tolerance processing meet the interface specifications. This helps to improve the quality, stability and reliability of the software and reduce the cost of later repairs.

[0003] In the actual development and testing process, interface testing can be performed in a variety of ways, such as automated testing tools represented by Postman and Jmeter, and cloud testing platforms represented by CodeArts TestPlan. These tools or platforms bring a certain degree of quality control and defect monitoring capabilities to the project. However, they also have some shortcomings, one of which is that there may be some challenges when dealing with dependencies between interfaces.

[0004] In actual projects, interface testing will cover a certain degree of business logic, which will lead to the complexity of interface testing scenarios, and the linkage and dependency between interfaces need to be considered. For example, the output of one interface is used as the input of another interface, or the output result of one interface requires the setting of another interface, etc., and current interface testing cannot provide an effective solution. In other words, interface testing tools such as Postman provide a good solution for single interface testing, but there may be some shortcomings for multi-interface testing with dependencies.

[0005] In summary, how to perform automated testing on multiple interfaces with dependencies has become a technical problem that urgently needs to be solved. Summary of the invention

[0006] In view of this, an object of the present invention is to provide a method, device and electronic device for automatic interface testing, so as to alleviate the technical problem that the traditional technology cannot perform automatic testing on multiple interfaces with dependencies.

[0007] In a first aspect, an embodiment of the present invention provides a method for automated interface testing, comprising:

[0008] Acquire an interface document, and convert the interface document into an interface database file, wherein the interface database file is used to store information of the interface to be tested;

[0009] Manually designing interface test cases based on the interface database file, wherein the interface test cases are used to provide test data for the interface to be tested, and the interface dependency field in the interface test cases is an ordered list, and the ordered list is used to store at least one interface identifier, and if the number of the interface identifiers is more than one, the interface test cases corresponding to the interface identifiers are interface association test cases, so as to realize automated testing of multiple interfaces to be tested that have dependencies;

[0010] The interface test case is used to instantiate the corresponding target script template to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic;

[0011] The test script is executed by the execution module to obtain the test result and the test report.

[0012] Furthermore, the field information in the interface database file includes: interface identifier, interface path, interface description, request header, request method, request body, request body type, response body, response body type, wherein the interface identifier is unique, and each interface identifier corresponds to the request method.

[0013] Further, manually designing interface test cases based on the interface database file includes:

[0014] The script designer designs the interface test case according to the business scenario and the interface database file;

[0015] The field information in the interface test case includes: test identifier, test description, interface dependency, request parameters, request body, pre-function, post-function, and verification point.

[0016] Further, the interface test case is used to instantiate the corresponding target script template, including:

[0017] Determine the use case type of the interface test case according to the interface dependency field in the interface test case;

[0018] Determine a target script template corresponding to the use case type according to the use case type;

[0019] The target script template is instantiated using the interface test case to obtain the test script.

[0020] Furthermore, the use case types include: cGet, cPost, cPut, cDelete, cPostGet, cPutGet, cDeleteGet, cGetPost, cGetPut, cGetDelete, and the use case types can be expanded according to business scenarios. Each of the use case types uniquely corresponds to a script template.

[0021] Furthermore, the script template includes three identification variables: db_file, case_file and case_id;

[0022] Wherein, db_file is used to identify the interface database file of the test script;

[0023] case_file is used to identify the file where the interface test case of the test data source of the test script is located;

[0024] case_id is a test identifier of an interface test case used to identify the source of the test data of the test script.

[0025] Furthermore, the test script includes: db_file, case_file and case_id, and the test script is executed by the execution module, including:

[0026] Load the corresponding interface database file according to the db_file, and obtain the file handle of the interface database file;

[0027] Load the corresponding interface test case set according to the case_file, and obtain the file handle of the interface test case set;

[0028] Searching for a corresponding interface test case in the file handle of the interface test case set according to the case_id, and obtaining the interface test case;

[0029] According to the interface test case, the file handle of the interface database file and the test logic corresponding to the test script, the interface request sending, receiving and assertion operations are performed to obtain the test result and the test report.

[0030] In a second aspect, an embodiment of the present invention further provides a device for automatic interface testing, comprising:

[0031] An acquisition and conversion unit, used for acquiring an interface document and converting the interface document into an interface database file, wherein the interface database file is used for storing information of the interface to be tested;

[0032] A design unit, used for manually designing interface test cases based on the interface database file, wherein the interface test cases are used to provide test data of the interface to be tested, and the interface dependency field in the interface test cases is an ordered list, and the ordered list is used to store at least one interface identifier, and if the number of the interface identifiers is more than one, the interface test cases corresponding to the interface identifiers are interface association test cases, so as to realize automated testing of multiple interfaces to be tested that have dependencies;

[0033] An instantiation unit, used to instantiate a corresponding target script template using the interface test case to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic;

[0034] The execution unit is used to execute the test script through the execution module to obtain the test result and the test report.

[0035] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.

[0036] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to execute any method described in the first aspect above.

[0037] In an embodiment of the present invention, a method for automatic interface testing is provided, comprising: obtaining an interface document and converting the interface document into an interface database file, wherein the interface database file is used to store information of the interface to be tested; manually designing an interface test case based on the interface database file, wherein the interface test case is used to provide test data of the interface to be tested, and the interface dependency field in the interface test case is an ordered list, the ordered list is used to store at least one interface identifier, if the number of interface identifiers is more than one, then the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automatic testing of multiple interfaces to be tested with dependencies; using the interface test case to instantiate the corresponding target script template to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic; executing the test script through an execution module to obtain a test result and a test report. From the above description, it can be seen that the interface automation testing method of the present invention is an automation testing technology that adapts to interface association. The interface dependency field in the interface test case is an ordered list, and the ordered list is used to store at least one interface identifier. If the number of interface identifiers is more than one, the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automated testing of multiple interfaces to be tested with dependencies. In addition, the interface test case is used to instantiate the corresponding target script template to obtain the test script, which can realize automated testing of multiple interfaces with dependencies, alleviating the technical problem that traditional technology cannot perform automated testing on multiple interfaces with dependencies. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0039] Figure 1 A flowchart of a method for automatic interface testing provided by an embodiment of the present invention;

[0040] Figure 2 A schematic diagram of converting an interface document into an interface database file provided by an embodiment of the present invention;

[0041] Figure 3 A schematic diagram of manually designing interface test cases based on an interface database file provided by an embodiment of the present invention;

[0042] Figure 4A schematic diagram of instantiating a script template using an interface test case provided in an embodiment of the present invention;

[0043] Figure 5 A schematic diagram of an execution module provided in an embodiment of the present invention executing a test script;

[0044] Figure 6 A schematic diagram of instantiating a script template provided by an embodiment of the present invention;

[0045] Figure 7 A schematic diagram of an interface automation test provided by an embodiment of the present invention;

[0046] Figure 8 A schematic diagram of a device for automatic interface testing provided by an embodiment of the present invention;

[0047] Fig. 9 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0048] The technical solution of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0049] Traditional technologies cannot perform automated testing on multiple interfaces with dependencies.

[0050] Based on this, the interface automation testing method of the present invention is an automation testing technology that adapts to interface association. The interface dependency field in the interface test case is an ordered list, and the ordered list is used to store at least one interface identifier. If the number of interface identifiers is more than one, the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automated testing of multiple interfaces to be tested with dependencies. In addition, the interface test case is used to instantiate the corresponding target script template to obtain the test script, so as to realize automated testing of multiple interfaces with dependencies.

[0051] To facilitate understanding of this embodiment, a method for automatic interface testing disclosed in an embodiment of the present invention is first introduced in detail.

[0052] Embodiment 1:

[0053] According to an embodiment of the present invention, an embodiment of a method for automated interface testing is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0054] Figure 1 is a flow chart of a method for automatic interface testing according to an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:

[0055] Step S102, obtaining an interface document, and converting the interface document into an interface database file, wherein the interface database file is used to store information of the interface to be tested;

[0056] In the embodiment of the present invention, this process can be implemented by an interface list module, refer to Figure 2 , taking the interface document as input, and then converting the interface document into an interface database file for subsequent retrieval of the method of the present invention. The interface document generally exists in the swagger interface development document format in the project. The interface database file can be any mainstream database management system or a simple csv document. The interface database file is used to store the information of the interface to be tested.

[0057] Step S104, manually designing interface test cases based on the interface database file, wherein the interface test cases are used to provide test data for the interface to be tested, and the interface dependency field in the interface test cases is an ordered list, and the ordered list is used to store at least one interface identifier. If the number of interface identifiers is more than one, the interface test cases corresponding to the interface identifiers are interface association test cases, so as to realize automated testing of multiple interfaces to be tested that have dependencies;

[0058] Specifically, this process can be realized through manual design, refer to Figure 3 ,During manual design, refer to the interface database file and manually design interface test cases based on the interface database file.

[0059] The interface dependency field (i.e., the case_api_list field) in the interface test case is an ordered list, which can store at least one interface identifier (i.e., api_indx). If there are more than one interface identifiers, the interface test case corresponding to the interface identifier is an interface association test case to achieve automated testing of multiple dependent interfaces to be tested; if there is only one interface identifier, the interface test case corresponding to the interface identifier is a single interface test case.

[0060] Step S106, using the interface test case to instantiate the corresponding target script template to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic;

[0061] Specifically, this process can be implemented through the test script module, refer to Figure 4 , taking the interface test case as input, the automated test script is automatically generated according to the existing script template. During implementation, the interface test case is used to instantiate the corresponding target script template to obtain the test script.

[0062] Step S108, executing the test script through the execution module to obtain the test results and test report.

[0063] Specifically, the execution module can be constructed using the current mainstream interface automation framework, such as the Python language pytest+allure+request interface automation framework technology. The implementation process is as follows Figure 5 shown.

[0064] In an embodiment of the present invention, a method for automatic interface testing is provided, comprising: obtaining an interface document and converting the interface document into an interface database file, wherein the interface database file is used to store information of the interface to be tested; manually designing an interface test case based on the interface database file, wherein the interface test case is used to provide test data of the interface to be tested, and the interface dependency field in the interface test case is an ordered list, the ordered list is used to store at least one interface identifier, if the number of interface identifiers is more than one, then the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automatic testing of multiple interfaces to be tested with dependencies; using the interface test case to instantiate the corresponding target script template to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic; executing the test script through an execution module to obtain a test result and a test report. From the above description, it can be seen that the interface automation testing method of the present invention is an automation testing technology that adapts to interface association. The interface dependency field in the interface test case is an ordered list, and the ordered list is used to store at least one interface identifier. If the number of interface identifiers is more than one, the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automated testing of multiple interfaces to be tested with dependencies. In addition, the interface test case is used to instantiate the corresponding target script template to obtain the test script, which can realize automated testing of multiple interfaces with dependencies, alleviating the technical problem that traditional technology cannot perform automated testing on multiple interfaces with dependencies.

[0065] The above content briefly introduces the interface automatic testing method of the present invention, and the specific contents involved are described in detail below.

[0066] In an optional embodiment of the present invention, the field information in the interface database file includes: interface identifier, interface path, interface description, request header, request method, request body, request body type, response body, response body type, wherein the interface identifier is unique and each interface identifier corresponds to a request method.

[0067] Specifically, the interface database file needs to store at least the following field information: interface identifier api_indx, interface path api_url, interface description api_desc, request header req_header, request method req_method, request body req_body, request body type req_body_type, response body res_body, response body type res_body_type, etc. The interface identifier api_indx is unique and needs to correspond to the request method field information to facilitate the subsequent judgment of the use case type.

[0068] In an optional embodiment of the present invention, manually designing interface test cases based on the interface database file specifically includes the following steps:

[0069] Script designers design interface test cases based on business scenarios and interface database files;

[0070] Among them, the field information in the interface test case includes: test identifier, test description, interface dependency, request parameters, request body, pre-function, post-function, and verification point.

[0071] Specifically, the interface test case has the following field information: test identifier case_id, test description case_desc, interface dependency case_api_list, request parameter case_req_query, request body case_req_body, pre-function case_pre_func, post-function case_teardown_func, verification point case_assert, etc.

[0072] In an optional embodiment of the present invention, the corresponding target script template is instantiated using an interface test case, which specifically includes the following steps: Figure 6 :

[0073] (1) Determine the use case type of the interface test case according to the interface dependency field in the interface test case;

[0074] Specifically, the case_api_list field in the interface test case can be used to identify the case_type of the interface test case. The case_type types include: cGet, cPost, cPut, cDelete, cPostGet, cPutGet, cDeleteGet, cGetPost, cGetPut, cGetDelete. The case type can be extended according to the business scenario. Each case type uniquely corresponds to a script template, which is used to implement the business logic of a specific case type.

[0075] (2) Determine the target script template corresponding to the use case type according to the use case type;

[0076] (3) Use the interface test case to instantiate the target script template to obtain the test script.

[0077] Specifically, an automated test script for the interface test case is automatically generated according to the target script template and other information of the interface test case except the interface dependency field.

[0078] In an optional embodiment of the present invention, the script template includes three identification variables: db_file, case_file and case_id;

[0079] Among them, db_file is used to identify the interface database file of the test script;

[0080] case_file is used to identify the file where the interface test case of the test script's test data source is located;

[0081] case_id is the test identifier of the interface test case used to identify the source of the test data of the test script.

[0082] Specifically, the test script module of the present invention does not directly put the test data (i.e., interface test case) into the automated test script, but adopts a data-driven approach to construct the automated test script, so it is necessary to create three identification variables db_file, case_file, and case_id. db_file is used to identify the interface database file of the test script. case_file is used to identify the file where the interface test case of the test data source of the test script is located, and case_id is used to identify the test identifier of the interface test case of the test data source of the test script. The three identification variables db_file, case_file, and case_id in the script template do not have specific content, and will only contain specific content after being instantiated using the interface test case.

[0083] In an optional embodiment of the present invention, the test script includes: db_file, case_file and case_id, and the test script is executed by the execution module, which specifically includes the following steps:

[0084] (1) Load the corresponding interface database file according to db_file and obtain the file handle of the interface database file;

[0085] Specifically, the interface database file to be tested is loaded according to the identification variable db_file, and the file handle db_obj of the interface database file is obtained, as shown in Table 1 below.

[0086] (2) Load the corresponding interface test case set according to case_file and obtain the file handle of the interface test case set;

[0087] Specifically, the interface test case set to be tested is loaded according to the identification variable case_file, and the file handle case_set_obj of the interface test case set is obtained. As shown in Table 2 below, each line in Table 2 is an interface test case, and multiple lines constitute an interface test case set.

[0088] (3) Search for the corresponding interface test case in the file handle of the interface test case set according to case_id, and obtain the interface test case;

[0089] Specifically, the corresponding interface test case is searched in case_set_obj according to the identification variable case_id, and the interface test case object case_obj (ie, the interface test case) is obtained.

[0090] (4) Send, receive and assert interface requests according to the interface test case, the file handle of the interface database file and the test logic corresponding to the test script to obtain the test results and test report.

[0091] In order to facilitate a better understanding of the process of the present invention, the process of the present invention is specifically introduced below with specific examples:

[0092] You can use code to obtain specific interface information (i.e., interface identifier, interface path, interface description, request header, request method, request body, request body type, response body, response body type) from an interface document (such as swagger) and store it in the selected interface database file demo_api_db. The database file format selected in this example is the csv file format.

[0093]

[0094] Table 1: demo_api_db

[0095] Wherein, api_indx consists of three parts: fixed string api_request method_number. req_body_type is the custom request body type of the present invention. If the value is query, it indicates that the request body is an additional parameter in api_url (such as https: / / apidemo / getting?var1&=String). Other values ​​(such as json) are all regular request bodies.

[0096] Interface test cases are designed based on the interface database file and business scenarios. The following are the designed interface test cases (each row except the header is an interface test case).

[0097]

[0098] Table 2: demo_case_db

[0099] Case_1001 and case_1002 simply test and verify the interface connectivity, and belong to a single interface test case. It is easy to find that case_1002 cannot verify whether the api_post_1002 interface is actually set successfully. Therefore, it is necessary to design case_1003, an interface test case with dependencies (i.e., an interface association test case). The case_api_list of this interface test case = [api_post_1002, api_get_1001] is an ordered interface dependency list. According to the interface dependency list (case_api_list = [api_post_1002, api_get_1001]), it can be identified that the case type of this interface test case is case_type = cPostGet. The characteristics of the cPostGet type interface test case are: the first interface is a post interface, and the second is a related get interface. The content set by the first Post interface can be obtained through the second get interface. According to the characteristics of the interface test case of the cPostGet case type, a script template scriptstemplate that meets this case type can be developed. A script template python pseudo code snippet that conforms to the cPostGet use case type is given below.

[0100] def cPostGet_scripttemplate:

[0101] db_file = 'demo_api_db'

[0102] case_file = 'demo_case_db'

[0103] case_id = 'case_1003'

[0104] case_obj=case_set_obj[case_file][case_id]

[0105] case_api_list=case_obj.job_list

[0106] post_obj=db_obj[case_api_list[0]]

[0107] get_obj=db_obj[case_api_list[1]]

[0108] response_post=send_request(post_obj,case_obj)#Send request

[0109] check_response(response_post)#Verify response

[0110] response_get=send_request(get_obj,case_obj)

[0111] check_response(response_get)

[0112] #Assert whether the get request is consistent with the post setting

[0113] check_response_body(response_get,response_post)

[0114] The test script module generates a corresponding instantiated python test script according to the script template cPostGet_scripttemplate (as shown below). The test script instantiates the script content according to Table 1 and Table 2, and adds the pytest and allure test frameworks to assist in test case management.

[0115] @allure.epic("demo_case_db")

[0116] @pytest.mark.usefixtures("log_token")

[0117] def test_script_1003:

[0118] ”'

[0119]

Test description

[0120] Verify that the demo data interface can be set successfully

[0121]

API interface

[0122] [api_post_1002,api_get_1001]

[0123]

Prerequisites

[0124] log_token

[0125]

Postconditions

[0126] Nan

[0127] ”'

[0128] db_file = 'demo_api_db'

[0129] case_file = 'demo_case_db'

[0130] case_id = 'case_1003'

[0131] case_obj=case_set_obj[case_file][case_id]

[0132] case_api_list=case_obj.job_list

[0133] post_obj=db_obj[case_api_list[0]]

[0134] get_obj=db_obj[case_api_list[1]]

[0135] response_post=send_request(post_obj,case_obj)#Send request

[0136] check_response(response_post)#Verify response

[0137] response_get=send_request(get_obj,case_obj)

[0138] check_response(response_get)

[0139] #Assert whether the get request is consistent with the post setting

[0140] check_response_body(response_get,response_post)

[0141] The above process completes the interface database file generation, interface test case design, script template development and test script generation processes. The generated test scripts can be batch executed through the execution module to generate test results and test reports. Through the above steps and descriptions, a simple schematic diagram of the technical solution of the present invention can be obtained, as shown in FIG. Figure 7 shown.

[0142] The present invention has the following effects:

[0143] The existing interface automation technology solutions are all based on the interface automation test of a single interface, but in actual projects, each interface is not independent and has certain correlations, and a single interface test often fails to achieve the test purpose. Therefore, based on the shortcomings of the existing interface automation technology and the new requirements of the complexity of the interface test scenario, the present invention proposes a technical solution for interface correlation automation testing.

[0144] 1. Introduce the concept of use case type of interface test cases, classify interface test cases, and express the correlation between interfaces. Define the use case types of all interface test cases according to the types of request methods and the correlation between interfaces in actual projects. A specific use case type represents the correlation between specific interfaces. For example, cPostGet indicates that the interface test case is used to test the associated Post and Get interfaces, and the Get interface is executed after the Post interface is executed to verify whether the Post interface is set successfully. The use case type can be clarified by parsing the case_api_list field in the interface test case. If the case_api_list field has only one interface identifier api_indx, then the interface test case is a single interface test. If the case_api_list field contains multiple api_indx, then the interface test case is a correlation interface test.

[0145] 2. Introduce script template technology to convert the correlation problem between interfaces into script template writing. According to different use case types, write script templates that meet the characteristics of each use case type to form a script template set. When the test script is generated, the interface correlation test corresponding to the use case type is completed. As long as the interface correlation test that meets the use case type can be automatically generated through the script template, the test script can be completed through the execution module. The final interface test is completed. And the separation of test data and test scripts is achieved, that is, the test data comes from the interface test case, and the test logic comes from the script template. The two are independent of each other and meet the characteristics of data-driven.

[0146] The main technical points of the present invention include:

[0147] Main technical point 1: Interface test cases are classified by introducing use case types. Different types of interface test cases represent the correlation between different interfaces.

[0148] Main technical point 2: According to the characteristics of interface testing, the association between interfaces is templated by introducing script templates, and the interface testing of complex business scenarios is solved through script template programming.

[0149] Embodiment 2:

[0150] The embodiment of the present invention further provides an interface automation testing device, which is mainly used to execute the interface automation testing method provided in the first embodiment of the present invention. The interface automation testing device provided in the embodiment of the present invention is specifically introduced below.

[0151] Figure 8 is a schematic diagram of a device for automatic interface testing according to an embodiment of the present invention, such as Figure 8 As shown, the device includes: an acquisition and conversion unit 10, a design unit 20, an instantiation unit 30 and an execution unit 40, wherein:

[0152] An acquisition and conversion unit, used for acquiring an interface document and converting the interface document into an interface database file, wherein the interface database file is used for storing information of the interface to be tested;

[0153] A design unit is used to manually design an interface test case based on an interface database file, wherein the interface test case is used to provide test data of the interface to be tested, and the interface dependency field in the interface test case is an ordered list, and the ordered list is used to store at least one interface identifier. If the number of interface identifiers is more than one, the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automated testing of multiple interfaces to be tested with dependencies;

[0154] An instantiation unit, used to instantiate a corresponding target script template using an interface test case to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic;

[0155] The execution unit is used to execute the test script through the execution module to obtain the test results and test report.

[0156] In an embodiment of the present invention, a device for automatic interface testing is provided, comprising: obtaining an interface document and converting the interface document into an interface database file, wherein the interface database file is used to store information of the interface to be tested; manually designing an interface test case based on the interface database file, wherein the interface test case is used to provide test data of the interface to be tested, and the interface dependency field in the interface test case is an ordered list, the ordered list is used to store at least one interface identifier, if the number of interface identifiers is more than one, then the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automatic testing of multiple interfaces to be tested with dependencies; using the interface test case to instantiate the corresponding target script template to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic; executing the test script through an execution module to obtain a test result and a test report. From the above description, it can be seen that the interface automation testing device of the present invention is an automation testing technology that adapts to interface association. The interface dependency field in the interface test case is an ordered list, and the ordered list is used to store at least one interface identifier. If the number of interface identifiers is more than one, the interface test case corresponding to the interface identifier is an interface association test case, so as to realize automated testing of multiple interfaces to be tested with dependencies. In addition, the interface test case is used to instantiate the corresponding target script template to obtain the test script, which can realize automated testing of multiple interfaces with dependencies, alleviating the technical problem that traditional technology cannot perform automated testing on multiple interfaces with dependencies.

[0157] Optionally, the field information in the interface database file includes: interface identifier, interface path, interface description, request header, request method, request body, request body type, response body, response body type, wherein the interface identifier is unique and each interface identifier corresponds to a request method.

[0158] Optionally, the design unit is also used for: script designers to design interface test cases based on business scenarios and interface database files; wherein the field information in the interface test cases includes: test identifier, test description, interface dependency, request parameters, request body, pre-function, post-function, and verification point.

[0159] Optionally, the instantiation unit is also used to: determine the use case type of the interface test case based on the interface dependency field in the interface test case; determine the target script template corresponding to the use case type based on the use case type; and use the interface test case to instantiate the target script template to obtain a test script.

[0160] Optionally, use case types include: cGet, cPost, cPut, cDelete, cPostGet, cPutGet, cDeleteGet, cGetPost, cGetPut, cGetDelete. The use case types can be extended according to business scenarios, and each use case type uniquely corresponds to a script template.

[0161] Optionally, the script template includes three identification variables: db_file, case_file and case_id; among which, db_file is used to identify the interface database file of the test script; case_file is used to identify the file where the interface test case that is the source of the test data of the test script is located; case_id is used to identify the test identifier of the interface test case that is the source of the test data of the test script.

[0162] Optionally, the test script includes: db_file, case_file and case_id, and the execution unit is also used to: load the corresponding interface database file according to db_file, and obtain the file handle of the interface database file; load the corresponding interface test case set according to case_file, and obtain the file handle of the interface test case set; search for the corresponding interface test case in the file handle of the interface test case set according to case_id, and obtain the interface test case; send, receive and assert interface requests according to the interface test case, the file handle of the interface database file and the test logic corresponding to the test script to obtain test results and a test report.

[0163] The device provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.

[0164] like Fig. 9 As shown, an electronic device 600 provided in an embodiment of the present application includes: a processor 601, a memory 602 and a bus, wherein the memory 602 stores machine-readable instructions executable by the processor 601. When the electronic device is running, the processor 601 communicates with the memory 602 through the bus, and the processor 601 executes the machine-readable instructions to perform the steps of the method for automatic interface testing as described above.

[0165] Specifically, the memory 602 and the processor 601 can be general-purpose memories and processors, which are not specifically limited here. When the processor 601 runs the computer program stored in the memory 602, the method for automatic interface testing can be executed.

[0166] The processor 601 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 601. The above processor 601 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 602, and the processor 601 reads the information in the memory 602 and completes the steps of the above method in combination with its hardware.

[0167] Corresponding to the above-mentioned method for automated interface testing, an embodiment of the present application also provides a computer-readable storage medium, which stores machine-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the steps of the above-mentioned method for automated interface testing.

[0168] The device for interface automation testing provided in the embodiment of the present application can be specific hardware on the device or software or firmware installed on the device. The device provided in the embodiment of the present application, its implementation principle and the technical effect produced are the same as those in the aforementioned method embodiment. For the sake of brief description, the parts not mentioned in the device embodiment can refer to the corresponding contents in the aforementioned method embodiment. It can be clearly understood by technicians in the relevant field that for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above can all refer to the corresponding processes in the aforementioned method embodiment, and will not be repeated here.

[0169] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0170] For another example, the flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the device, method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0171] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0172] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0173] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can essentially or partly contribute to the prior art or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions for an electronic device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the vehicle marking method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.

[0174] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.

[0175] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solution of the present application, rather than to limit it. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the aforementioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solution recorded in the aforementioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solution deviate from the scope of the technical solution of the embodiment of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for automated interface testing, characterized in that: include: Acquire an interface document, and convert the interface document into an interface database file, wherein the interface database file is used to store information of the interface to be tested; Manually designing interface test cases based on the interface database file, wherein the interface test cases are used to provide test data for the interface to be tested, and the interface dependency field in the interface test cases is an ordered list, and the ordered list is used to store at least one interface identifier, and if the number of the interface identifiers is more than one, the interface test cases corresponding to the interface identifiers are interface association test cases, so as to realize automated testing of multiple interfaces to be tested that have dependencies; The interface test case is used to instantiate the corresponding target script template to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic; The test script is executed by the execution module to obtain the test result and the test report.

2. The method according to claim 1, characterized in that The field information in the interface database file includes: interface identifier, interface path, interface description, request header, request method, request body, request body type, response body, response body type, wherein the interface identifier is unique, and each interface identifier corresponds to the request method.

3. The method according to claim 1, characterized in that Manually designing interface test cases based on the interface database file includes: The script designer designs the interface test case according to the business scenario and the interface database file; The field information in the interface test case includes: test identifier, test description, interface dependency, request parameters, request body, pre-function, post-function, and verification point.

4. The method according to claim 1, characterized in that The interface test case is used to instantiate the corresponding target script template, including: Determine the use case type of the interface test case according to the interface dependency field in the interface test case; Determine a target script template corresponding to the use case type according to the use case type; The target script template is instantiated using the interface test case to obtain the test script.

5. The method according to claim 4, characterized in that The use case types include: cGet, cPost, cPut, cDelete, cPostGet, cPutGet, cDeleteGet, cGetPost, cGetPut, and cGetDelete. The use case types can be expanded according to business scenarios, and each of the use case types uniquely corresponds to a script template.

6. The method according to claim 4, characterized in that The script template includes three identification variables: db_file, case_file and case_id; Wherein, db_file is used to identify the interface database file of the test script; case_file is used to identify the file where the interface test case of the test data source of the test script is located; case_id is a test identifier of an interface test case used to identify the source of the test data of the test script.

7. The method according to claim 1, characterized in that The test script includes: db_file, case_file and case_id, and the test script is executed by the execution module, including: Load the corresponding interface database file according to the db_file, and obtain the file handle of the interface database file; Load the corresponding interface test case set according to the case_file, and obtain the file handle of the interface test case set; Searching for a corresponding interface test case in the file handle of the interface test case set according to the case_id, and obtaining the interface test case; According to the interface test case, the file handle of the interface database file and the test logic corresponding to the test script, the interface request sending, receiving and assertion operations are performed to obtain the test result and the test report.

8. A device for interface automation testing, characterized in that: include: An acquisition and conversion unit, used for acquiring an interface document and converting the interface document into an interface database file, wherein the interface database file is used for storing information of the interface to be tested; A design unit, used for manually designing interface test cases based on the interface database file, wherein the interface test cases are used to provide test data of the interface to be tested, and the interface dependency field in the interface test cases is an ordered list, and the ordered list is used to store at least one interface identifier, and if the number of the interface identifiers is more than one, the interface test cases corresponding to the interface identifiers are interface association test cases, so as to realize automated testing of multiple interfaces to be tested that have dependencies; An instantiation unit, used to instantiate a corresponding target script template using the interface test case to obtain a test script, wherein the target script template is a script template corresponding to the interface test case in a preset script template, and the script template is used to provide test logic; The execution unit is used to execute the test script through the execution module to obtain the test result and the test report.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to execute the method according to any one of claims 1 to 7.