Universal interface automated testing method, device, computer equipment and storage medium

Through the data preprocessing and automated testing methods of the interface configuration file, the problem of heavy workload caused by the diversity of the trading system interface protocols is solved, efficient automated testing is achieved, and the need for manual writing is reduced.

CN118394663BActive Publication Date: 2024-10-18ARCHFORCE FINANCIAL TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410825811.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-10-18
Estimated Expiration
2044-06-25

AI Technical Summary

Technical Problem

In the existing technology, the trading system has many types of interface protocols and a large number of interfaces, resulting in complex message routing, which consumes a lot of manpower for interface encapsulation and case writing, and the debugging cycle is long.

Method used

By obtaining the interface configuration file, convert it into a unified data format file based on the data preprocessing strategy, generate the interface code file, use case file and expected result file, use the test executor to conduct automatic testing, and compare the test records to generate a test report, reducing manual work Analyze and write.

Benefits of technology

It reduces the workload caused by multiple protocol types and interfaces, improves the efficiency of automated testing, ensures test accuracy, and reduces the need for manual analysis and case writing for each interface type.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118394663B_ABST
    Figure CN118394663B_ABST
Patent Text Reader

Abstract

The present invention discloses a general interface automatic testing method, device, computer equipment and storage medium. On the one hand, the interface configuration file is converted into a unified data format file based on a data preprocessing strategy, which weakens the differences between protocols and interfaces to solve the problem of heavy workload caused by multiple protocol types and interfaces; on the other hand, an interface code file is generated based on a code generation module, a full-scale use case file with high coverage is generated based on a use case generation module, and an expected result file is generated based on an expected generation module. Further, automatic testing is performed based on a test executor, an interface code file and an initial use case file to obtain an interface test record, which is compared with the expected result file to generate a test report. There is no need to spend a lot of manpower to analyze the interface and write cases for each interface type, which ensures the test accuracy while improving the efficiency of automatic testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of system automation testing, and in particular to a universal interface automation testing method, device, computer equipment and storage medium. Background Art

[0002] At present, trading systems (such as securities trading systems) need to interface with a variety of peripheral inspection terminals (such as clients, centralized operations, unified operation and maintenance platforms, dial-up testing platforms, etc.), and the interface protocol types also vary depending on the docking terminals. When the trading system is docked with a large number of protocol types and a large number of interfaces, it will not only make message routing complicated, but also consume a lot of manpower to encapsulate and encode the interfaces, that is, it will take a lot of manpower to analyze the interfaces and write cases.

[0003] If protocol encapsulation is performed according to the interface dimension for each interface connected to the trading system, then one interface needs to correspond to one encapsulation class, and the case corresponding to one interface is a manually written text description, which generates interface request input parameters by parsing the text description. The interface is expected to be pre-calculated by writing an algorithm module and compared with the response after the test execution.

[0004] When encapsulating the protocol in the interface dimension, the encapsulation workload is large, and when writing the algorithm module to obtain the expected interface, the debugging cycle is long when the requirements or design documents of the trading system are not comprehensive. Summary of the invention

[0005] The embodiments of the present invention provide a general interface automatic testing method, apparatus, computer equipment and storage medium, aiming to solve the problem in the prior art that a large amount of manpower is consumed to analyze the interface and write cases when performing protocol encapsulation according to the interface dimension for each interface connected to the transaction system, thereby increasing the testing difficulty and reducing the testing efficiency.

[0006] In a first aspect, an embodiment of the present invention provides a general interface automated testing method, which includes:

[0007] Obtain an interface configuration file, and based on a protocol type corresponding to the interface configuration file and a preset data preprocessing strategy, convert the interface configuration file to obtain a unified data format file;

[0008] Generate an interface code file corresponding to the unified data format file based on a pre-configured code generation module;

[0009] Based on a pre-configured use case generation module, generate an initial use case file corresponding to the unified data format file;

[0010] Generate an expected result file corresponding to the initial use case file based on a preconfigured expected generation module;

[0011] Obtain a pre-configured test executor, and perform automatic testing based on the test executor, the interface code file, and the initial use case file to obtain an interface test record;

[0012] The interface test record is compared with the expected result file to obtain a test comparison result, and a test report is generated based on the test comparison result.

[0013] In a second aspect, an embodiment of the present invention further provides a general interface automatic testing device, which includes:

[0014] A unified data format file acquisition unit, used to acquire an interface configuration file, and based on a protocol type corresponding to the interface configuration file and a preset data preprocessing strategy, convert the interface configuration file to obtain a unified data format file;

[0015] An interface code file acquisition unit, used to generate an interface code file corresponding to the unified data format file based on a pre-configured code generation module;

[0016] An initial use case file generating unit, configured to generate an initial use case file corresponding to the unified data format file based on a pre-configured use case generating module;

[0017] An expected result file generating unit, used to generate an expected result file corresponding to the initial use case file based on a pre-configured expected generation module;

[0018] The automatic test execution unit is used to obtain a pre-configured test executor, and perform automatic testing based on the test executor, the interface code file and the initial use case file to obtain an interface test record;

[0019] The test report generating unit is used to compare the interface test record with the expected result file to obtain a test comparison result, and generate a test report based on the test comparison result.

[0020] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the method described in the first aspect is implemented.

[0021] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the method described in the first aspect above can be implemented.

[0022] The embodiments of the present invention provide a general interface automatic testing method, apparatus, computer equipment and storage medium. On the one hand, the interface configuration file is converted into a unified data format file based on a data preprocessing strategy, which weakens the differences in protocols and interfaces to solve the problem of heavy workload caused by multiple protocol types and interfaces; on the other hand, an interface code file is generated based on a code generation module, a full-scale use case file with high coverage is generated based on a use case generation module, and an expected result file is generated based on an expected generation module. Further, automatic testing is performed based on a test executor, an interface code file and an initial use case file to obtain an interface test record, which is compared with the expected result file to generate a test report. There is no need to spend a lot of manpower to analyze the interface and write cases for each interface type, which ensures the test accuracy while also improving the efficiency of automatic testing. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0024] Figure 1 A schematic diagram of an application scenario of the general interface automatic testing method provided by an embodiment of the present invention;

[0025] Figure 2 A schematic diagram of a flow chart of a general interface automated testing method provided by an embodiment of the present invention;

[0026] Figure 3 A schematic diagram of a sub-process of a general interface automated testing method provided by an embodiment of the present invention;

[0027] Figure 4 A schematic diagram of another sub-process of the general interface automatic testing method provided by an embodiment of the present invention;

[0028] Figure 5 A schematic diagram of another sub-process of the general interface automatic testing method provided by an embodiment of the present invention;

[0029] Figure 6 A schematic block diagram of a general interface automatic testing device provided by an embodiment of the present invention;

[0030] Figure 7 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not 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.

[0032] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0033] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0034] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0035] Please also see Figure 1 and Figure 2 , Figure 1 Schematic diagram of a scenario of a general interface automatic testing method according to an embodiment of the present invention. Figure 2 1 is a flow chart of a general interface automated testing method provided by an embodiment of the present invention. The method is applied to a server 10, which can be connected to a peripheral inspection terminal 20 for communication, and can also be connected to a downstream device under test 30 (such as a new standard client, an old centralized client, etc.). Figure 2 As shown, the method includes the following steps S110-S160.

[0036] S110: Acquire an interface configuration file, and based on a protocol type corresponding to the interface configuration file and a preset data preprocessing strategy, convert the interface configuration file to obtain a file in a unified data format.

[0037] In this embodiment, the technical solution is described with the server (such as a test server) as the execution subject, and a general interface automation test system (which can also be understood as a general interface automation test tool) is deployed in the server. After the tester logs in to the general interface automation test system using a user terminal (such as a smart phone, tablet computer, or laptop computer), he can upload or import an interface configuration file as the object to be tested.

[0038] The unified data format file may include declaration protocols, interfaces, fields, data types, and data value options.

[0039] Among them, the interface configuration file is written and saved according to the interface granularity during pre-configuration. For example, the file name of the interface configuration file is specifically in the form of: protocol_interface number_interface type; wherein the interface number is the requested interface number (the request can be understood as the automated test request corresponding to the interface configuration file, and can be triggered by the user terminal sending the interface configuration file to the general interface automated testing system), and the response interface needs to be configured at the same time; if the interface configuration file is an interface configuration file of a financial trading system (such as a securities trading system) as an example, the interface type can be divided into four categories during specific implementation: transaction, query, configuration change, and asset adjustment. Of course, the interface type can be configured and adjusted accordingly in other application scenarios, and is not limited to the above examples.

[0040] The interface configuration file includes not only request information, but also parameter information, and the parameter information includes multiple fields (each field corresponds to a specific basic attribute). The field value of each field in the parameter information determines the content of the case set of the subsequent use case file. For example, when the interface configuration file adopts the YAML format (YAML is a concise non-markup language), the specific content of an interface configuration file (named AMQ_InterfaceA_trade) that adopts the AMQ protocol (AMQ protocol is a Java message service used to send and receive core protocol messages) and the interface number is interface A is as follows:

[0041] request:

[0042] - name: Interface A

[0043] gateway: #There may be a situation where an interface needs to send to multiple downstream DUTs and needs to be marked. When generating use cases later, it needs to be grouped according to the downstream DUTs.

[0044] - "oldtrade" #oldtrade

[0045] - "newtrade" #New Generation

[0046] - "B2B" #Pure KCXP Gateway

[0047] - "opera" #centralized operation

[0048] - "ISE" #Old Schedule

[0049] - "newClient" #New standard client

[0050] - "others" #Other systems (OTC / Financial management platform / Scripture Library / Bank side / Escrow system)

[0051] expect_return:

[0052] -code: 0

[0053] desc: "normal return value of the call"

[0054] params:

[0055] - name: param1

[0056] # tag: The tag value corresponding to the KV type protocol. The byte stream type protocol does not have this attribute.

[0057] type: string # char, array type is considered as a limited length string

[0058] len: 10 # Variable length strings do not need to set the length

[0059] required: Y # Y indicates a required field

[0060] valid: #Normal value, the first normal value will be used as the default value

[0061] - "value1"

[0062] - "value2"

[0063] boundary: #boundary value

[0064] - "value1"

[0065] - "value2" #

[0066] overflow: #abnormal value, abnormal value can be given as exceeded length, abnormal precision, etc.

[0067] - value: "value1"

[0068] error_code: 219 # If no error code check is required, no configuration is required here

[0069] error_desc: "--"

[0070] - value: "value2"

[0071] error_code: 10007

[0072] error_desc: "--"

[0073] In the above example, request corresponds to the request information in the interface configuration file, and params corresponds to the parameter information in the interface configuration file. In the above example, only the parameter information including one field, namely param1, is shown. In specific implementation, the parameter information may include multiple fields (such as param2, param3, ... paramN, etc., where N is a positive integer). Each field includes basic attributes (such as naming, type, length, etc.) and field values. The basic attributes of each field are used for interface message parsing, and the field values ​​are used for use case generation and expectation comparison; the field values ​​of each field can be divided into valid values ​​and invalid values. Valid values ​​= {normal values, boundary values}, and invalid values ​​= abnormal values. Use case generation only depends on the input of the request interface (such as interface A in the above example). All generated use cases will generate a corresponding number of copies according to the configuration of the gateway (i.e., gateway). In the interface configuration file, the full amount of information required by the subsequent generation modules (such as code generation module, use case generation module, expectation generation module, etc.) is included, so that each generation module can extract the corresponding data of concern from the interface configuration file. Moreover, in order to avoid redundant processing of data in the interface configuration file by each generator and ensure the consistency of data source, interface configuration files of different protocols are classified and integrated through data preprocessing strategy to obtain a unified data format file.

[0074] It can be seen that through the interface configuration file, the traversal range of each input parameter field of the interface can be clarified, including normal values, abnormal values ​​and boundary values, and the cross-product combination relationship between different input parameter fields can be clarified to assist the subsequent use case generation module to generate the full amount of use cases after the combined cross-product traversal.

[0075] In the financial transaction system scenario, the protocol of the automated test request includes not only the AMQ protocol, but also the BPKV protocol, the vertical line XP protocol, etc., and each of the above protocols corresponds to a protocol type. Because the interface configuration files of the above protocols are different, they can be converted into a unified data format file after data preprocessing through a data preprocessing strategy.

[0076] In one embodiment, the data preprocessing strategy is a data preprocessor class; step S110 includes:

[0077] Based on the data preprocessor class, the interface definition file of the interface configuration file is obtained and parsed to obtain the parsing result as the unified data format file.

[0078] In this embodiment, a data preprocessing plug-in can be used for the specific implementation of the data preprocessing strategy. The data preprocessing plug-in is specifically a data preprocessor class such as DataHandlerBasedonProtocol (which is a class for processing any specified protocol file). When the data preprocessor class is specialized, the specific protocol type to be processed must be specified, and all interface definition files corresponding to the specified protocol type are searched and parsed according to the specified protocol type, and the parsing results are integrated and output to different JSON files to obtain a unified data format file. The unified data format file includes an interface definition file, an interface value file, a field relationship file, a dictionary mapping file, etc., and the interface definition file, the interface value file, the field relationship file, and the dictionary mapping file can all be in JSON format.

[0079] The interface definition file is written and saved according to the protocol granularity, and the file is named in the "functions_protocol" format, which is mainly used for interface code generation of streaming protocols. For example, in the above example, the protocol in the interface configuration file of AMQ_interface A_trade is AMQ protocol, and the corresponding converted interface definition file is named functions_AMQ. The basic attributes corresponding to param1 in the parameter information in the interface configuration file of AMQ_interface A_trade are name: param1, type: string, and len: 10. In addition to the basic attributes corresponding to param1 (such as {"name": "Interface A","params": [{"name": "param1","type": "string","len": 10}]}), the corresponding interface definition file also needs to include the basic attributes of the response parameter information corresponding to param1 ({"name": "Response of Interface A","params":[{"name": "param101","type": "string","len": 10}]}).

[0080] The interface value file is named in the format of "cases_protocol_interface type". It is mainly used for use case generation, and use cases of different protocols, different interface types, and different gateways will be generated into separate use case output files. For example, the interface value file includes the file name (such as interface A), the receiving file name (such as the response of interface A), the gateway (such as "oldtrade", "newtrade", "B2B", "opera", "ISE", "newClient", "others" and other gateways named by custom systems), the return value, the parameter information (including multiple fields, each field has a specific field value), etc. For example, still referring to the above example, in the interface value file corresponding to the interface configuration file AMQ_Interface A_trade, the basic attributes corresponding to param1 in the parameter information are {"name": "param1","required": "Y","valid":["value1", "value2"],"overflow": [("value1", 219), ("value2",10007)]}. Among them, valid represents the normal value of param1, and overflow represents the abnormal value of param1.

[0081] The file name of the field relationship file is in the format of "mappings_protocol_interface type", which is mainly used for expected value generation, and the field relationships of different protocols and different interface types will be generated into different template files. The field relationship file includes the file name (such as the response of interface A), the request file name (such as interface A), parameter information (including multiple fields, each field has a specific field value), etc. For example, still referring to the above example, in the field relationship file corresponding to the interface configuration file AMQ_interface A_trade, the basic attribute corresponding to param1 in the parameter information is {"name": "param1","mapping_name": "param1","type": "direct"}. Among them, direct means that the field relationship of param1 is a direct field relationship.

[0082] The dictionary mapping file is named in the "dicts_protocol" format, which is mainly used for expected value generation, and the dictionary mapping relationships of different protocols will be generated in different template files. For example, still referring to the above example, the dictionary mapping file corresponding to the interface configuration file AMQ_interfaceA_trade includes information such as "interfaceA": {"param1": ["Q","W"]}, which means that there is a bidirectional mapping relationship in the parameter information param1 (that is, Q and W represent a bidirectional mapping relationship).

[0083] In the data preprocessor class DataHandlerBasedonProtocol, parallel file processing is implemented through ThreadPoolExecutor; in the start method, an independent thread threading.Thread is used to start the file processing process, which is separated from the main thread, so that multiple class processors (i.e., ThreadPoolExecutor) can run at the same time; at the same time, the _post_process method is added for flexible post-processing to achieve data integration and output after all input files are processed. That is, when the data preprocessor class obtains the interface definition file of the interface configuration file and parses it, and then integrates and outputs the parsing results to different JSON files after obtaining the parsing results, multiple JSON files are first read through the general auxiliary class JsonUtils class, and then the _post_process method is used to integrate multiple JSON files to obtain the unified data format file. Through this conversion process of the interface configuration file, the differences between the interface protocols are weakened, and only general encapsulation is required through the general interface automation test system.

[0084] This embodiment converts protocols such as AMQ, BPKV, and vertical line XP into a unified data format file.

[0085] S120. Generate an interface code file corresponding to the unified data format file based on a preconfigured code generation module.

[0086] In this embodiment, after the unified data format file corresponding to the interface configuration file is determined, it is input into a code generation module (also understood as a code generator) to generate an interface code file corresponding to the unified data format file.

[0087] Among them, if the code generator can be encapsulated into a universal interface, the unified data format file in JSON format can be converted into the protocol format of the protocol type corresponding to the interface configuration file, which is equivalent to using the sub-generator corresponding to each protocol type to classify and integrate the unified data format file into files of different types of protocols. If there are some other protocol types (that is, other protocols other than AMQ protocol, BPKV protocol, and vertical line XP protocol) that cannot generate code files based on the code generator in the form of a universal interface, the code generator can be designed based on Python3 and code_generator, using the parsed xml file as the interface of the code generator, and implementing the conversion of each JSON field into the corresponding protocol format in the interface.

[0088] In one embodiment, before step S110 or step S120, the method further includes:

[0089] Acquire a protocol template file and a system configuration file, and store the protocol template file and the system configuration file in a memory.

[0090] For example, by using a universal format yml file during test analysis, you only need to load all yml files into memory at one time and append them to the list according to the interface and protocol, without worrying about the specific interface and the differences between the interfaces.

[0091] In this embodiment, the protocol template file is a configuration file that the general interface automation test tool needs to load in order to perform message automation encoding and decoding. Specifically, an AMQ protocol template file, a BPKV protocol template file, a vertical line XP protocol template file, etc. can be set, that is, the protocol template file is named according to the protocol type such as AMQ protocol, BPKV protocol, vertical line XP protocol, etc. After the general interface automation test tool obtains the protocol type of the interface configuration file, the corresponding encoder can be selected to send the message.

[0092] When creating a protocol template file, you can directly create a .proto file as the protocol template file, and define the message format according to the protocol type. Then you can use protocol buffers to process the .proto file to automatically generate python code, and implement the sender and receiver message processing classes by serializing and deserializing the message code. Among them, when using Protocol Buffers (which can serialize structured data) to process the .proto file to automatically generate python code, run the protoc command (protoc --python_out=. / custom directory. / custom directory / ASPmessage.proto) to generate an ASPmessage_pb2.py file in the specified custom directory. This ASPmessage_pb2.py file is the python code corresponding to the protocol template file.

[0093] The system configuration file is the configuration content that needs to be loaded when the interface automation test tool is running, such as the path of the loaded file and the communication server IP and other information. The system configuration file allows the user to modify the specific information of the configuration. If the test environment is fixed, it does not need to be modified frequently. The protocol template files and system configuration files stored in the memory can be pre-loaded before the interface automation test tool starts to perform automated testing on the use case file.

[0094] S130. Generate an initial use case file corresponding to the unified data format file based on a preconfigured use case generation module.

[0095] In this embodiment, after the unified data format file corresponding to the interface configuration file is determined, it is input into a use case generation module (also understood as a use case generator) to generate an initial use case file corresponding to the unified data format file.

[0096] When the generated initial use case file is executed in the subsequent test, not only each case in the initial use case file needs to be executed one by one, but each use case needs to be observable, modifiable and maintainable. The generated initial use case file can be stored in the database to obtain a case data table (whose table name can be represented by protocol_interface type_gateway). Each row of case data in the case data table represents a case in the initial use case file, and each case data includes at least the use case number (such as represented by case_id), gateway (such as represented by gateway), protocol (such as represented by protocol), interface type (such as represented by func_type), interface name (such as represented by func_name) and interface information (such as represented by func_info).

[0097] Moreover, when each use case is generated in the initial use case file, it can be automatically labeled. Specifically, it is labeled according to the interface, protocol, and routing dimensions. When performing subsequent tests, batch use cases can be selected and regressed according to different dimensions without having to select them one by one.

[0098] In one embodiment, if Figure 3 As shown, step S130 includes:

[0099] S131, obtaining a normal value set corresponding to each field in the interface value file of the unified data format file;

[0100] S132, cross-producting the normal value sets corresponding to the fields in the interface value file and filling the queried customer data to obtain a normal value case coverage result;

[0101] S133, obtaining abnormal values ​​corresponding to each field in the interface value file of the unified data format file, and combining them with the normal value set corresponding to other fields in the interface value file excluding the field to fill the queried customer data, to obtain abnormal value case coverage results;

[0102] S134. The normal value case coverage results and the abnormal value case coverage results constitute the initial use case file.

[0103] In this embodiment, the use case generator can be implemented based on Python, using libraries such as json, numpy, pandas, pymysql, and pymssql. According to the JSON file corresponding to the interface value file "cases_protocol_interface type", the dictionary list therein is traversed to generate use cases for each interface to file or store them in the library. In addition, the valid value, boundary value, and invalid value of each field need to be obtained, where the first bit of the valid value is the default value, and the valid value and boundary value are combined and reorganized into a complete normal value. For example, the parameter information in the interface value file includes multiple fields, for example, respectively recorded as param1-paramN; wherein param1 includes N1 normal values, param2 includes N2 normal values, ..., paramN includes Nx normal values ​​(where N and N1-Nx are all positive integers). The normal values ​​of different fields of the same interface are cross-producted (Cartesian product) to form normal value case coverage, the number is N1×N2×…×Nx; for an abnormal value of any field of the same interface, it will form abnormal value case coverage with a normal value (default normal value) of other fields, the number is M1+M2+…+Mx. In the above process of generating the initial use case file, manual intervention in expected writing and coverage checking is reduced. Before requesting in the control system, all case feasibility is traversed by the cross-product method, so that the case coverage can be automatically checked. After making a traversal request to the control system, all responses are recorded as the response expectations of the system under test.

[0104] S140. Based on the pre-configured expectation generation module, generate an expected result file corresponding to the initial use case file.

[0105] In this embodiment, after the unified data format file corresponding to the interface configuration file is determined, and the initial use case file corresponding to the unified data format file is generated based on the use case generation module, each use case in the initial use case file needs to be input into the expectation generation module (which can also be understood as the expectation generator) to generate the expected results.

[0106] Among them, a dependent field dictionary mapping table is pre-configured in the expected generation module, which includes multiple dependent field dictionary mapping data. The dependent field dictionary mapping table is converted into a field mapping file by the data preprocessing strategy (i.e., the data preprocessor class). It only defines the fields and value contents with specific mapping relationships in the request and response. The dictionary type field values ​​without specific mapping relationships are set in the interface configuration file.

[0107] The expected result file can also be understood as an interface test expectation template. The interface test expectations in the interface test expectation template mainly include transparent transmission class, fixed result class and calculation result class. The above three categories can be marked in the interface configuration file. The specific calculation results of the calculation result class will be further edited and filled in when the use case file is generated and observed (because the calculation result class may be calculated through the fields of other interfaces, or it may be calculated based on the specific situation of customer data in the system, and it needs to be edited according to the information in the generated use case file).

[0108] For transparent transmission classes, you can directly fill in the field name in the request according to the interface configuration file. For fixed result classes, you need to manually select a result to fill in. For calculated result classes, you need to manually fill in a specific value or give a value range. The interface test expectation template determines the expectation of subsequent verification, and there is no need to write an assertion algorithm or perform correctness verification.

[0109] The interface test expectation template is stored in the database to facilitate the rendering and display of the front-end page. The interface test expectation template is stored in the same database as the corresponding use case. For example, in the database corresponding to AMQ_trade_oldtrade, the expected values ​​of the fields of all response messages will be stored in the same data table expectation_templates. For example, the data table expectation_templates includes the following header number (indicated by id), interface number (indicated by func_id), interface name (indicated by func_name), request interface name (indicated by req_func_name), field name (indicated by field_name), and field type (indicated by field_type, which is used by the front-end to verify the input legality of the expected value of the calculation class).

[0110] In one embodiment, if Figure 4 As shown, step S140 includes:

[0111] S141, performing a pre-data query on each use case included in the initial use case file based on the expected generation module, and marking the use case for which customer information is queried as being in execution status;

[0112] S142. Write the use cases with execution status in the initial use case file into a database based on the dictionary mapping file in the unified data format file to obtain the expected result file.

[0113] In this embodiment, the expected generation module first reads each use case included in the initial use case file, then performs a pre-data query for each use case, marks the use case that obtains customer information as an execution state (marks the use case that does not obtain customer information as a skip state), and fills the customer information into the corresponding use case. After that, all use cases in the execution state are combined with the mapping dictionary mapping file to perform expected response assembly, obtain the expected result file, and write it into the database.

[0114] An http sub-thread is also set up in the expected generation module, which is used for expected value update requests (calculated value filling, fixed value selection) after front-end intervention / user configuration reading, and assembles the complete expected response content into the database.

[0115] This embodiment performs automated expectations through an expectation generation module, without the need for manual intervention in expectation writing.

[0116] S150: Obtain a pre-configured test executor, and perform automatic testing based on the test executor, the interface code file, and the initial use case file to obtain an interface test record.

[0117] In this embodiment, the test executor calls the interface code and the initial use case file to automatically send requests to each downstream device under test that is connected to the general interface automation test system for communication and obtain response results, which are recorded in the test record file to obtain an interface test record.

[0118] For example, the test executor sends the key and value in the corresponding protocol in a list structure to reach the new standard client, the old centralized client and other downstream clients for testing.

[0119] In the interface test record, each use case corresponds to a JSON file, which records all request data and response data corresponding to the test execution process. The file storage path naming rule of the interface test record is: first-level category name / second-level category name / interface function number / , such as: oldtrade / old2new_realtime / 700800 / , and each JSON file is named based on the test case number corresponding to the use case number of the use case, such as testcase001.

[0120] In one embodiment, if Figure 5 As shown, step S150 includes:

[0121] S151, based on the test executor, obtaining the interface type corresponding to each use case in the initial use case file and loading the corresponding interface library file for instantiation to obtain an instantiated use case file;

[0122] S152, obtaining, based on the test executor, a precondition execution result of each instantiated use case in the instantiated use case file;

[0123] S153, obtaining request data and response data of each instantiated use case in the instantiated use case file based on the test executor;

[0124] S154, obtaining, based on the test executor, the post-condition execution result of each instantiated use case in the instantiated use case file;

[0125] S155. The actual test results of each instantiated use case are composed of the pre-condition execution results, request data, response data and post-condition execution results of each instantiated use case in the instantiated use case file, and the interface test record is obtained.

[0126] In this embodiment, when automatically testing each use case in the initial use case file based on the test executor, it is necessary to first instantiate each use case separately, then send a request to each downstream device under test and obtain a response result, and record it in the test record file to obtain an interface test record.

[0127] For example, caseid=1, that is, the case numbered 1, is automatically tested, and the actual test results generated are in JSON format, and the actual test results of caseid1 include the precondition execution results, request data, response data, and postcondition execution results corresponding to the case numbered 1.

[0128] In the above test process, the interface differences are weakened. It is only necessary to load all interface configuration files into the memory and convert them into unified data format files according to the interface and protocol type for automated testing.

[0129] In this embodiment, a connection manager module may also be included to complete the communication and encoding and decoding implementation of different protocols and open it to the test executor for calling.

[0130] S160: Compare the interface test record with the expected result file to obtain a test comparison result, and generate a test report based on the test comparison result.

[0131] In this embodiment, the interface test record includes actual test results corresponding to multiple use cases, and the expected result file also includes expected results corresponding to multiple use cases. After comparing the actual test results of the same use case with the expected results, a test comparison result can be formed. Each use case included in the interface test record corresponds to a comparison result, and the test comparison result is formed by the multiple comparison results obtained.

[0132] In one embodiment, step S160 includes:

[0133] Based on the test comparison result and a preset template engine, the test report including the initial use case file, the interface test record, the expected result file and the test comparison result is generated.

[0134] In this embodiment, the jinja2 template engine can be used to generate the test report including at least the initial use case file, the interface test record, the expected result file and the test comparison result. The test report is finally output as a test report in HTML format, and can optionally support the generation of a word or pdf version of the test report.

[0135] In the test report, for each use case, a summary use case consisting of downstream client name + protocol + interface is provided, and the specific use case is provided in the form of a hyperlink and attachment.

[0136] This embodiment may also include a database comparison plug-in for completing the checkpoint verification of the part other than the interface. When the database comparison test is performed separately, a database comparison test report may be generated separately.

[0137] Based on the general interface automated testing solution in this embodiment, the tester only needs to do test analysis to complete automated test execution and regression.

[0138] It can be seen from the above technical scheme that, on the one hand, the present application converts the interface configuration file into a unified data format file based on the data preprocessing strategy, weakens the differences between protocols and interfaces, so as to solve the problem of heavy workload caused by multiple protocol types and interfaces; on the other hand, the interface code file is generated based on the code generation module, the full use case file with high coverage is generated based on the use case generation module, and the expected result file is generated based on the expectation generation module. Further, automatic testing is performed based on the test executor, the interface code file and the initial use case file to obtain the interface test record, and the record is compared with the expected result file to generate a test report. There is no need to spend a lot of manpower to analyze the interface and write cases for each interface type, which ensures the accuracy of the test while improving the efficiency of automated testing.

[0139] Figure 6 1 is a schematic block diagram of a general interface automatic testing device provided by an embodiment of the present invention. Figure 6 As shown, corresponding to the above general interface automated testing method, the present invention also provides a general interface automated testing device 100. The general interface automated testing device 100 comprises: a unified data format file acquisition unit 110, an interface code file acquisition unit 120, an initial use case file generation unit 130, an expected result file generation unit 140, an automatic test execution unit 150 and a test report generation unit 160.

[0140] The unified data format file acquisition unit 110 is used to acquire an interface configuration file, and based on a protocol type corresponding to the interface configuration file and a preset data preprocessing strategy, convert the interface configuration file to obtain a unified data format file.

[0141] In this embodiment, the technical solution is described with the server (such as a test server) as the execution subject, and a general interface automation test system (which can also be understood as a general interface automation test tool) is deployed in the server. After the tester logs in to the general interface automation test system using a user terminal (such as a smart phone, tablet computer, or laptop computer), he can upload or import an interface configuration file as the object to be tested.

[0142] The unified data format file may include declaration protocols, interfaces, fields, data types, and data value options.

[0143] Among them, the interface configuration file is written and saved according to the interface granularity during pre-configuration. For example, the file name of the interface configuration file is specifically in the form of: protocol_interface number_interface type; wherein the interface number is the requested interface number (the request can be understood as the automated test request corresponding to the interface configuration file, and can be triggered by the user terminal sending the interface configuration file to the general interface automated testing system), and the response interface needs to be configured at the same time; if the interface configuration file is an interface configuration file of a financial trading system (such as a securities trading system) as an example, the interface type can be divided into four categories during specific implementation: transaction, query, configuration change, and asset adjustment. Of course, the interface type can be configured and adjusted accordingly in other application scenarios, and is not limited to the above examples.

[0144] The interface configuration file includes not only request information but also parameter information, and the parameter information includes multiple fields (each field corresponds to a specific basic attribute), and the field value of each field in the parameter information determines the content of the case set of the use case file generated later. For example, when the interface configuration file adopts the YAML format (YAML is a concise non-markup language), the specific content of an interface configuration file (whose file name is AMQ_Interface A_trade) that adopts the AMQ protocol (AMQ protocol is a Java message service for sending and receiving core protocol messages) and the interface number is interface A refers to the example in the method embodiment.

[0145] In the above example, request corresponds to the request information in the interface configuration file, and params corresponds to the parameter information in the interface configuration file. In the above example, only the parameter information including one field, namely param1, is shown. In specific implementation, the parameter information may include multiple fields (such as param2, param3, ... paramN, etc., where N is a positive integer). Each field includes basic attributes (such as naming, type, length, etc.) and field values. The basic attributes of each field are used for interface message parsing, and the field values ​​are used for use case generation and expectation comparison; the field values ​​of each field can be divided into valid values ​​and invalid values. Valid values ​​= {normal values, boundary values}, and invalid values ​​= abnormal values. Use case generation only depends on the input of the request interface (such as interface A in the above example). All generated use cases will generate a corresponding number of copies according to the configuration of the gateway (i.e., gateway). In the interface configuration file, the full amount of information required by the subsequent generation modules (such as code generation module, use case generation module, expectation generation module, etc.) is included, so that each generation module can extract the corresponding data of concern from the interface configuration file. Moreover, in order to avoid redundant processing of data in the interface configuration file by each generator and ensure the consistency of data source, interface configuration files of different protocols are classified and integrated through data preprocessing strategy to obtain a unified data format file.

[0146] It can be seen that through the interface configuration file, the traversal range of each input parameter field of the interface can be clarified, including normal values, abnormal values ​​and boundary values, and the cross-product combination relationship between different input parameter fields can be clarified to assist the subsequent use case generation module to generate the full amount of use cases after the combined cross-product traversal.

[0147] In the financial transaction system scenario, the protocol of the automated test request includes not only the AMQ protocol, but also the BPKV protocol, the vertical line XP protocol, etc., and each of the above protocols corresponds to a protocol type. Because the interface configuration files of the above protocols are different, they can be converted into a unified data format file after data preprocessing through a data preprocessing strategy.

[0148] In one embodiment, the data preprocessing strategy is a data preprocessor class; the unified data format file acquisition unit 110 is specifically used to:

[0149] Based on the data preprocessor class, the interface definition file of the interface configuration file is obtained and parsed to obtain the parsing result as the unified data format file.

[0150] In this embodiment, a data preprocessing plug-in can be used for the specific implementation of the data preprocessing strategy. The data preprocessing plug-in is specifically a data preprocessor class such as DataHandlerBasedonProtocol (which is a class for processing any specified protocol file). When the data preprocessor class is specialized, the specific protocol type to be processed must be specified, and all interface definition files corresponding to the specified protocol type are searched and parsed according to the specified protocol type, and the parsing results are integrated and output to different JSON files to obtain a unified data format file. The unified data format file includes an interface definition file, an interface value file, a field relationship file, a dictionary mapping file, etc., and the interface definition file, the interface value file, the field relationship file, and the dictionary mapping file can all be in JSON format.

[0151] The interface definition file is written and saved according to the protocol granularity, and the file is named in the "functions_protocol" format, which is mainly used for interface code generation of streaming protocols. For example, in the above example, the protocol in the interface configuration file of AMQ_interface A_trade is AMQ protocol, and the corresponding converted interface definition file is named functions_AMQ. The basic attributes corresponding to param1 in the parameter information in the interface configuration file of AMQ_interface A_trade are name: param1, type: string, and len: 10. In addition to the basic attributes corresponding to param1 (such as {"name": "Interface A","params": [{"name": "param1","type": "string","len": 10}]}), the corresponding interface definition file also needs to include the basic attributes of the response parameter information corresponding to param1 ({"name": "Response of Interface A","params":[{"name": "param101","type": "string","len": 10}]}).

[0152] The interface value file is named in the format of "cases_protocol_interface type". It is mainly used for use case generation, and use cases of different protocols, different interface types, and different gateways will be generated into separate use case output files. For example, the interface value file includes the file name (such as interface A), the receiving file name (such as the response of interface A), the gateway (such as "oldtrade", "newtrade", "B2B", "opera", "ISE", "newClient", "others" and other gateways named by custom systems), the return value, the parameter information (including multiple fields, each field has a specific field value), etc. For example, still referring to the above example, in the interface value file corresponding to the interface configuration file AMQ_Interface A_trade, the basic attributes corresponding to param1 in the parameter information are {"name": "param1","required": "Y","valid":["value1", "value2"],"overflow": [("value1", 219), ("value2",10007)]}. Among them, valid represents the normal value of param1, and overflow represents the abnormal value of param1.

[0153] The file name of the field relationship file is in the format of "mappings_protocol_interface type", which is mainly used for expected value generation, and the field relationships of different protocols and different interface types will be generated into different template files. The field relationship file includes the file name (such as the response of interface A), the request file name (such as interface A), parameter information (including multiple fields, each field has a specific field value), etc. For example, still referring to the above example, in the field relationship file corresponding to the interface configuration file AMQ_interface A_trade, the basic attribute corresponding to param1 in the parameter information is {"name": "param1","mapping_name": "param1","type": "direct"}. Among them, direct means that the field relationship of param1 is a direct field relationship.

[0154] The dictionary mapping file is named in the "dicts_protocol" format, which is mainly used for expected value generation, and the dictionary mapping relationships of different protocols will be generated in different template files. For example, still referring to the above example, the dictionary mapping file corresponding to the interface configuration file AMQ_interfaceA_trade includes information such as "interfaceA": {"param1": ["Q","W"]}, which means that there is a bidirectional mapping relationship in the parameter information param1 (that is, Q and W represent a bidirectional mapping relationship).

[0155] In the data preprocessor class DataHandlerBasedonProtocol, parallel file processing is implemented through ThreadPoolExecutor; in the start method, an independent thread threading.Thread is used to start the file processing process, which is separated from the main thread, so that multiple class processors (i.e., ThreadPoolExecutor) can run at the same time; at the same time, the _post_process method is added for flexible post-processing to achieve data integration and output after all input files are processed. That is, when the data preprocessor class obtains the interface definition file of the interface configuration file and parses it, and then integrates and outputs the parsing results to different JSON files after obtaining the parsing results, multiple JSON files are first read through the general auxiliary class JsonUtils class, and then the _post_process method is used to integrate multiple JSON files to obtain the unified data format file. Through this conversion process of the interface configuration file, the differences between the interface protocols are weakened, and only general encapsulation is required through the general interface automation test system.

[0156] This embodiment converts protocols such as AMQ, BPKV, and vertical line XP into a unified data format file.

[0157] The interface code file acquisition unit 120 is used to generate an interface code file corresponding to the unified data format file based on a pre-configured code generation module.

[0158] In this embodiment, after the unified data format file corresponding to the interface configuration file is determined, it is input into a code generation module (also understood as a code generator) to generate an interface code file corresponding to the unified data format file.

[0159] Among them, if the code generator can be encapsulated into a universal interface, the unified data format file in JSON format can be converted into the protocol format of the protocol type corresponding to the interface configuration file, which is equivalent to using the sub-generator corresponding to each protocol type to classify and integrate the unified data format file into files of different types of protocols. If there are some other protocol types (that is, other protocols other than AMQ protocol, BPKV protocol, and vertical line XP protocol) that cannot generate code files based on the code generator in the form of a universal interface, the code generator can be designed based on Python3 and code_generator, using the parsed xml file as the interface of the code generator, and implementing the conversion of each JSON field into the corresponding protocol format in the interface.

[0160] In one embodiment, the universal interface automatic testing device 100 further includes:

[0161] The system file acquisition unit is used to acquire a protocol template file and a system configuration file, and store the protocol template file and the system configuration file in a memory.

[0162] For example, by using a universal format yml file during test analysis, you only need to load all yml files into memory at one time and append them to the list according to the interface and protocol, without worrying about the specific interface and the differences between the interfaces.

[0163] In this embodiment, the protocol template file is a configuration file that the general interface automation test tool needs to load in order to perform message automation encoding and decoding. Specifically, an AMQ protocol template file, a BPKV protocol template file, a vertical line XP protocol template file, etc. can be set, that is, the protocol template file is named according to the protocol type such as AMQ protocol, BPKV protocol, vertical line XP protocol, etc. After the general interface automation test tool obtains the protocol type of the interface configuration file, the corresponding encoder can be selected to send the message.

[0164] When creating a protocol template file, you can directly create a .proto file as the protocol template file, and define the message format according to the protocol type. Then you can use protocol buffers to process the .proto file to automatically generate python code, and implement the sender and receiver message processing classes by serializing and deserializing the message code. Among them, when using Protocol Buffers (which can serialize structured data) to process the .proto file to automatically generate python code, run the protoc command (protoc --python_out=. / custom directory. / custom directory / ASPmessage.proto) to generate an ASPmessage_pb2.py file in the specified custom directory. This ASPmessage_pb2.py file is the python code corresponding to the protocol template file.

[0165] The system configuration file is the configuration content that needs to be loaded when the interface automation test tool is running, such as the path of the loaded file and the communication server IP and other information. The system configuration file allows the user to modify the specific information of the configuration. If the test environment is fixed, it does not need to be modified frequently. The protocol template files and system configuration files stored in the memory can be pre-loaded before the interface automation test tool starts to perform automated testing on the use case file.

[0166] The initial use case file generating unit 130 is used to generate an initial use case file corresponding to the unified data format file based on a pre-configured use case generating module.

[0167] In this embodiment, after the unified data format file corresponding to the interface configuration file is determined, it is input into a use case generation module (also understood as a use case generator) to generate an initial use case file corresponding to the unified data format file.

[0168] When the generated initial use case file is executed in the subsequent test, not only each case in the initial use case file needs to be executed one by one, but each use case needs to be observable, modifiable and maintainable. The generated initial use case file can be stored in the database to obtain a case data table (whose table name can be represented by protocol_interface type_gateway). Each row of case data in the case data table represents a case in the initial use case file, and each case data includes at least the use case number (such as represented by case_id), gateway (such as represented by gateway), protocol (such as represented by protocol), interface type (such as represented by func_type), interface name (such as represented by func_name) and interface information (such as represented by func_info).

[0169] Moreover, when each use case is generated in the initial use case file, it can be automatically labeled. Specifically, it is labeled according to the interface, protocol, and routing dimensions. When performing subsequent tests, batch use cases can be selected and regressed according to different dimensions without having to select them one by one.

[0170] In one embodiment, the initial use case file generating unit 130 is specifically used for:

[0171] Obtain a set of normal values ​​corresponding to each field in the interface value file of the unified data format file;

[0172] The normal value sets corresponding to the fields in the interface value file are cross-multiplied and then filled with the queried customer data to obtain the normal value case coverage result;

[0173] Obtain the abnormal value corresponding to each field in the interface value file of the unified data format file, and fill the queried customer data with the normal value set corresponding to other fields in the interface value file excluding the field, to obtain the abnormal value case coverage result;

[0174] The initial use case file is composed of the normal value case coverage results and the abnormal value case coverage results.

[0175] In this embodiment, the use case generator can be implemented based on Python, using libraries such as json, numpy, pandas, pymysql, and pymssql. According to the JSON file corresponding to the interface value file "cases_protocol_interface type", the dictionary list therein is traversed to generate use cases for each interface to file or store them in the library. In addition, the valid value, boundary value, and invalid value of each field need to be obtained, where the first bit of the valid value is the default value, and the valid value and boundary value are combined and reorganized into a complete normal value. For example, the parameter information in the interface value file includes multiple fields, for example, respectively recorded as param1-paramN; wherein param1 includes N1 normal values, param2 includes N2 normal values, ..., paramN includes Nx normal values ​​(where N and N1-Nx are all positive integers). The normal values ​​of different fields of the same interface are cross-producted (Cartesian product) to form normal value case coverage, the number is N1×N2×…×Nx; for an abnormal value of any field of the same interface, it will form abnormal value case coverage with a normal value (default normal value) of other fields, the number is M1+M2+…+Mx. In the above process of generating the initial use case file, manual intervention in expected writing and coverage checking is reduced. Before requesting in the control system, all case feasibility is traversed by the cross-product method, so that the case coverage can be automatically checked. After making a traversal request to the control system, all responses are recorded as the response expectations of the system under test.

[0176] The expected result file generating unit 140 is used to generate an expected result file corresponding to the initial use case file based on a pre-configured expected generation module.

[0177] In this embodiment, after the unified data format file corresponding to the interface configuration file is determined, and the initial use case file corresponding to the unified data format file is generated based on the use case generation module, each use case in the initial use case file needs to be input into the expectation generation module (which can also be understood as the expectation generator) to generate the expected results.

[0178] Among them, a dependent field dictionary mapping table is pre-configured in the expected generation module, which includes multiple dependent field dictionary mapping data. The dependent field dictionary mapping table is converted into a field mapping file by the data preprocessing strategy (i.e., the data preprocessor class). It only defines the fields and value contents with specific mapping relationships in the request and response. The dictionary type field values ​​without specific mapping relationships are set in the interface configuration file.

[0179] The expected result file can also be understood as an interface test expectation template. The interface test expectations in the interface test expectation template mainly include transparent transmission class, fixed result class and calculation result class. The above three categories can be marked in the interface configuration file. The specific calculation results of the calculation result class will be further edited and filled in when the use case file is generated and observed (because the calculation result class may be calculated through the fields of other interfaces, or it may be calculated based on the specific situation of customer data in the system, and it needs to be edited according to the information in the generated use case file).

[0180] For transparent transmission classes, you can directly fill in the field name in the request according to the interface configuration file. For fixed result classes, you need to manually select a result to fill in. For calculated result classes, you need to manually fill in a specific value or give a value range. The interface test expectation template determines the expectation of subsequent verification, and there is no need to write an assertion algorithm or perform correctness verification.

[0181] The interface test expectation template is stored in the database to facilitate the rendering and display of the front-end page. The interface test expectation template is stored in the same database as the corresponding use case. For example, in the database corresponding to AMQ_trade_oldtrade, the expected values ​​of the fields of all response messages will be stored in the same data table expectation_templates. For example, the data table expectation_templates includes the following header number (indicated by id), interface number (indicated by func_id), interface name (indicated by func_name), request interface name (indicated by req_func_name), field name (indicated by field_name), and field type (indicated by field_type, which is used by the front-end to verify the input legality of the expected value of the calculation class).

[0182] In one embodiment, the expected result file generating unit 140 is specifically used for:

[0183] Performing a pre-data query on each use case included in the initial use case file based on the expected generation module, and marking the use case for which the customer information is queried as an execution state;

[0184] The use cases with execution status in the initial use case file are written into a database based on the dictionary mapping file in the unified data format file to obtain the expected result file.

[0185] In this embodiment, the expected generation module first reads each use case included in the initial use case file, then performs a pre-data query for each use case, marks the use case that obtains customer information as an execution state (marks the use case that does not obtain customer information as a skip state), and fills the customer information into the corresponding use case. After that, all use cases in the execution state are combined with the mapping dictionary mapping file to perform expected response assembly, obtain the expected result file, and write it into the database.

[0186] An http sub-thread is also set up in the expected generation module, which is used for expected value update requests (calculated value filling, fixed value selection) after front-end intervention / user configuration reading, and assembles the complete expected response content into the database.

[0187] This embodiment performs automated expectations through an expectation generation module, without the need for manual intervention in expectation writing.

[0188] The automatic test execution unit 150 is used to obtain a pre-configured test executor, and perform automatic testing based on the test executor, the interface code file and the initial use case file to obtain an interface test record.

[0189] In this embodiment, the test executor calls the interface code and the initial use case file to automatically send requests to each downstream device under test that is connected to the general interface automation test system for communication and obtain response results, which are recorded in the test record file to obtain an interface test record.

[0190] For example, the test executor sends the key and value in the corresponding protocol in a list structure to reach the new standard client, the old centralized client and other downstream clients for testing.

[0191] In the interface test record, each use case corresponds to a JSON file, which records all request data and response data corresponding to the test execution process. The file storage path naming rule of the interface test record is: first-level category name / second-level category name / interface function number / , such as: oldtrade / old2new_realtime / 700800 / , and each JSON file is named based on the test case number corresponding to the use case number of the use case, such as testcase001.

[0192] In one embodiment, the automatic test execution unit 150 is specifically used for:

[0193] Based on the test executor, the interface type corresponding to each use case in the initial use case file is obtained and the corresponding interface library file is loaded for instantiation to obtain an instantiated use case file;

[0194] Acquire, based on the test executor, a precondition execution result of each instantiated use case in the instantiated use case file;

[0195] Acquiring request data and response data of each instantiated use case in the instantiated use case file based on the test executor;

[0196] Acquire, based on the test executor, the post-condition execution result of each instantiated use case in the instantiated use case file;

[0197] The actual test results of each instantiated use case are composed of the pre-condition execution results, request data, response data and post-condition execution results of each instantiated use case in the instantiated use case file, and the interface test record is obtained.

[0198] In this embodiment, when automatically testing each use case in the initial use case file based on the test executor, it is necessary to first instantiate each use case separately, then send a request to each downstream device under test and obtain a response result, and record it in the test record file to obtain an interface test record.

[0199] For example, caseid=1, that is, the case numbered 1, is automatically tested, and the actual test results generated are in JSON format, and the actual test results of caseid1 include the precondition execution results, request data, response data, and postcondition execution results corresponding to the case numbered 1.

[0200] In the above test process, the interface differences are weakened. It is only necessary to load all interface configuration files into the memory and convert them into unified data format files according to the interface and protocol type for automated testing.

[0201] In this embodiment, a connection manager module may also be included to complete the communication and encoding and decoding implementation of different protocols and open it to the test executor for calling.

[0202] The test report generating unit 160 is used to compare the interface test record with the expected result file to obtain a test comparison result, and generate a test report based on the test comparison result.

[0203] In this embodiment, the interface test record includes actual test results corresponding to multiple use cases, and the expected result file also includes expected results corresponding to multiple use cases. After comparing the actual test results of the same use case with the expected results, a test comparison result can be formed. Each use case included in the interface test record corresponds to a comparison result, and the test comparison result is formed by the multiple comparison results obtained.

[0204] In one embodiment, the test report generating unit 160 is specifically used for:

[0205] Based on the test comparison result and a preset template engine, the test report including the initial use case file, the interface test record, the expected result file and the test comparison result is generated.

[0206] In this embodiment, the jinja2 template engine can be used to generate the test report including at least the initial use case file, the interface test record, the expected result file and the test comparison result. The test report is finally output as a test report in HTML format, and can optionally support the generation of a word or pdf version of the test report.

[0207] In the test report, for each use case, a summary use case consisting of downstream client name + protocol + interface is provided, and the specific use case is provided in the form of a hyperlink and attachment.

[0208] This embodiment may also include a database comparison plug-in for completing the checkpoint verification of the part other than the interface. When the database comparison test is performed separately, a database comparison test report may be generated separately.

[0209] Based on the general interface automated testing solution in this embodiment, the tester only needs to do test analysis to complete automated test execution and regression.

[0210] It can be seen from the above technical scheme that, on the one hand, the present application converts the interface configuration file into a unified data format file based on the data preprocessing strategy, weakens the differences between protocols and interfaces, so as to solve the problem of heavy workload caused by multiple protocol types and interfaces; on the other hand, the interface code file is generated based on the code generation module, the full use case file with high coverage is generated based on the use case generation module, and the expected result file is generated based on the expectation generation module. Further, automatic testing is performed based on the test executor, the interface code file and the initial use case file to obtain the interface test record, and the record is compared with the expected result file to generate a test report. There is no need to spend a lot of manpower to analyze the interface and write cases for each interface type, which ensures the accuracy of the test while improving the efficiency of automated testing.

[0211] The above-mentioned general interface automatic testing device can be implemented in the form of a computer program. The computer program can be used in Figure 7 Runs on the computer device shown.

[0212] See also Figure 7 , Figure 7 The present invention provides a schematic block diagram of a computer device provided by an embodiment of the present invention. The computer device integrates any universal interface automatic testing device provided by an embodiment of the present invention.

[0213] See also Figure 7The computer device includes a processor 402 , a memory and a network interface 405 connected via a system bus 401 , wherein the memory may include a storage medium 403 and an internal memory 404 .

[0214] The storage medium 403 can store an operating system 4031 and a computer program 4032. The computer program 4032 includes program instructions, and when the program instructions are executed, the processor 402 can execute the above-mentioned general interface automatic testing method.

[0215] The processor 402 is used to provide computing and control capabilities to support the operation of the entire computer device.

[0216] The internal memory 404 provides an environment for the operation of the computer program 4032 in the storage medium 403. When the computer program 4032 is executed by the processor 402, the processor 402 can execute the above-mentioned general interface automatic testing method.

[0217] The network interface 405 is used to communicate with other devices over the network. Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0218] The processor 402 is used to run a computer program 4032 stored in the memory to implement the general interface automatic testing method as described above.

[0219] It should be understood that in the embodiment of the present invention, the processor 402 may be a central processing unit (CPU), and the processor 402 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0220] It can be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiment can be completed by instructing the relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiment of the above method.

[0221] Therefore, the present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes the general interface automatic testing method as described above.

[0222] The computer-readable storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk, etc., which are computer-readable storage media that can store program codes.

[0223] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0224] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and 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.

[0225] The steps in the method of the embodiment of the present invention can be adjusted in order, combined and deleted according to actual needs. The units in the device of the embodiment of the present invention can be combined, divided and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0226] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all 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 and includes several instructions for a computer device (which can be a personal computer, terminal, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.

[0227] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A general interface automated testing method, characterized in that: include: Obtain an interface configuration file, and based on the protocol type corresponding to the interface configuration file and a preset data preprocessing strategy, convert the interface configuration file to obtain a unified data format file; wherein the data preprocessing strategy is a data preprocessor class; the conversion of the interface configuration file to obtain a unified data format file based on the protocol type corresponding to the interface configuration file and the preset data preprocessing strategy includes: searching for all interface definition files corresponding to each protocol type in the interface configuration file based on the data preprocessor class, parsing all interface definition files corresponding to each protocol type to obtain each parsing result, integrating and outputting each parsing result to different files, reading each file based on a general auxiliary class, and integrating each read file through a post_process method to obtain the unified data format file; wherein the interface configuration file includes the full amount of information required by a code generation module, a use case generation module, and an expected generation module; the unified data format file includes an interface definition file for generating an interface code file for a streaming protocol, an interface value file for generating a use case file, a field relationship file for generating an expected result file, and a dictionary mapping file; wherein the post_process method is a post-processing method for performing data integration and output after all input files are processed; Based on the pre-configured code generation module, generate an interface code file corresponding to the unified data format file; Based on the pre-configured use case generation module, an initial use case file corresponding to the unified data format file is generated, including: obtaining a normal value set corresponding to each field in the interface value file of the unified data format file; performing cross product on the normal value set corresponding to each field in the interface value file and filling the queried customer data to obtain a normal value case coverage result; obtaining an abnormal value corresponding to each field in the interface value file of the unified data format file, and combining the abnormal value set corresponding to other fields in the interface value file except the field and filling the queried customer data to obtain an abnormal value case coverage result; the normal value case coverage result and the abnormal value case coverage result form the initial use case file; Based on the pre-configured expected generation module, generate an expected result file corresponding to the initial use case file; Obtain a pre-configured test executor, and perform automatic testing based on the test executor, the interface code file and the initial use case file to obtain an interface test record; wherein, the automatic testing based on the test executor, the interface code file and the initial use case file to obtain an interface test record includes: obtaining the interface type corresponding to each use case in the initial use case file based on the test executor and loading the corresponding interface library file for instantiation to obtain an instantiated use case file; obtaining the pre-condition execution result of each instantiated use case in the instantiated use case file based on the test executor; obtaining the request data and response data of each instantiated use case in the instantiated use case file based on the test executor; obtaining the post-condition execution result of each instantiated use case in the instantiated use case file based on the test executor; the actual test result of each instantiated use case is composed of the pre-condition execution result, request data, response data and post-condition execution result of each instantiated use case in the instantiated use case file, and obtaining the interface test record; The interface test record is compared with the expected result file to obtain a test comparison result, and a test report is generated based on the test comparison result.

2. The method according to claim 1, characterized in that Before the step of obtaining the interface configuration file and converting the interface configuration file to obtain a unified data format file based on the protocol type corresponding to the interface configuration file and a preset data preprocessing strategy, or before the step of generating an interface code file corresponding to the unified data format file based on the pre-configured code generation module, the method further includes: Acquire a protocol template file and a system configuration file, and store the protocol template file and the system configuration file in a memory.

3. The method according to claim 1, characterized in that The generating of the expected result file corresponding to the initial use case file based on the pre-configured expected generation module includes: Performing a pre-data query on each use case included in the initial use case file based on the expected generation module, and marking the use case for which the customer information is queried as an execution state; The use cases with execution status in the initial use case file are written into a database based on the dictionary mapping file in the unified data format file to obtain the expected result file.

4. The method according to claim 1, characterized in that: The generating of a test report based on the test comparison result includes: Based on the test comparison result and a preset template engine, the test report including the initial use case file, the interface test record, the expected result file and the test comparison result is generated.

5. A universal interface automatic testing device, characterized in that: include: A unified data format file acquisition unit is used to acquire an interface configuration file, and based on the protocol type corresponding to the interface configuration file and a preset data preprocessing strategy, convert the interface configuration file to obtain a unified data format file; wherein the data preprocessing strategy is a data preprocessor class; the conversion of the interface configuration file to obtain a unified data format file based on the protocol type corresponding to the interface configuration file and the preset data preprocessing strategy includes: searching for all interface definition files corresponding to each protocol type in the interface configuration file based on the data preprocessor class, parsing all interface definition files corresponding to each protocol type to obtain each parsing result, integrating and outputting each parsing result to different files, reading each file based on a general auxiliary class, and integrating each read file through a post_process method to obtain the unified data format file; wherein the interface configuration file includes the full amount of information required by a code generation module, a use case generation module, and an expected generation module; the unified data format file includes an interface definition file for generating an interface code file for a streaming protocol, an interface value file for generating a use case file, a field relationship file and a dictionary mapping file for generating an expected result file; wherein the post_process method is a post-processing method for executing data integration and output after all input files are processed; An interface code file acquisition unit, configured to generate an interface code file corresponding to the unified data format file based on the pre-configured code generation module; The initial use case file generation unit is used to generate an initial use case file corresponding to the unified data format file based on the pre-configured use case generation module, including: obtaining a normal value set corresponding to each field in the interface value file of the unified data format file; performing cross product on the normal value set corresponding to each field in the interface value file and filling the queried customer data to obtain a normal value case coverage result; obtaining an abnormal value corresponding to each field in the interface value file of the unified data format file, and combining the abnormal value set corresponding to other fields in the interface value file except the field and filling the queried customer data to obtain an abnormal value case coverage result; the normal value case coverage result and the abnormal value case coverage result form the initial use case file; An expected result file generating unit, configured to generate an expected result file corresponding to the initial use case file based on the pre-configured expected generation module; An automatic test execution unit, used to obtain a pre-configured test executor, and perform automatic testing based on the test executor, the interface code file and the initial use case file to obtain an interface test record; wherein, the automatic testing based on the test executor, the interface code file and the initial use case file to obtain an interface test record includes: obtaining the interface type corresponding to each use case in the initial use case file based on the test executor and loading the corresponding interface library file for instantiation to obtain an instantiated use case file; obtaining the pre-condition execution result of each instantiated use case in the instantiated use case file based on the test executor; obtaining the request data and response data of each instantiated use case in the instantiated use case file based on the test executor; obtaining the post-condition execution result of each instantiated use case in the instantiated use case file based on the test executor; the actual test result of each instantiated use case is composed of the pre-condition execution result, request data, response data and post-condition execution result of each instantiated use case in the instantiated use case file, and the interface test record is obtained; The test report generating unit is used to compare the interface test record with the expected result file to obtain a test comparison result, and generate a test report based on the test comparison result.

6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the general interface automatic testing method according to any one of claims 1 to 4 is implemented.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the universal interface automatic testing method according to any one of claims 1 to 4 can be implemented.

Citation Information

Patent Citations

  • Server, automatic interface testing method and storage medium

    CN109558290A

  • Signal equipment testing method and external equipment interface

    CN111897306A

  • Test script development method and device

    CN112988601A

  • Interface testing method and device, equipment and storage medium

    CN115687145A

  • Interface multi-protocol universal automation realization system

    CN116204435A