Interface testing method and device
By parsing and generating test case sets through the pre-formatted json data model, it solves the problems of excessive communication and automation lag in interface testing, and achieves efficient interface testing and use case maintenance.
Patent Information
- Application Number
- CN202010614759.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2040-06-30
AI Technical Summary
Existing interface testing methods have problems such as excessive interface communication and lagging automation, resulting in high test case maintenance costs and low efficiency.
By obtaining the parameter information of the business interface, the input and output parameters are determined to comply with the preset format according to the preset format json data model, parsed and generated test case sets, and these use case sets are used to automatically test the business interface, supporting rapid maintenance and parameter changes Accurately match test cases.
It reduces the time of manually writing automated code, reduces the maintenance cost of test cases, improves the efficiency of automated writing and the speed of use case generation, and ensures the efficiency and accuracy of interface testing.
Smart Images

Figure CN111752846B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of financial technology (Fintech), and in particular to an interface testing method and device. Background Art
[0002] With the development of computer technology, more and more technologies are applied in the financial field. Traditional finance is gradually transforming into financial technology. However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology. In the financial field, in order to ensure that application software (transactions, payments, etc.) can run normally and efficiently, a software testing environment is usually built to test these application software.
[0003] At present, the existing interface tests are mainly conducted through postman, jmeter and other tools to send request packets. There is a lack of mature platforms for interface automation, and the interface automation test platform is mainly encapsulated through programming languages such as python, php, and java. The main process of the conventional encapsulated automation framework is: test data and URL configuration → send request → return interface verification. Among them, the configuration of test data is mainly divided into two types: hard-coded data in the code and configuration files. However, this processing method requires configuring test cases one by one according to the test data, and conventional interface automation is introduced late in the R&D process, and the benefits are not high.
[0004] In summary, there is an urgent need for an interface testing method to solve the problem of multiple conventional interface communications and lagging automation in the prior art. Summary of the invention
[0005] The embodiment of the present invention provides an interface testing method and device, which are used to solve the problem of multiple conventional interface communications and delayed automation in the prior art.
[0006] In a first aspect, an embodiment of the present invention provides an interface testing method, comprising:
[0007] Obtain parameter information for setting a service interface; the parameter information includes input parameters and output parameters;
[0008] According to the json data model in the preset format, the input parameter is determined as the json input parameter conforming to the preset format, and the output parameter is determined as the json output parameter conforming to the preset format;
[0009] Parse the json input parameters and json output parameters that conform to the preset format to obtain the parsed json input parameters and json output parameters that conform to the preset format, and generate a test case set for the parsed json input parameters that conform to the preset format according to a preset test parameter generation method;
[0010] The service interface is tested using the test case set to obtain test results.
[0011] In the above technical scheme, by determining the input parameters as json input parameters that conform to the preset format and the output parameters as json output parameters that conform to the preset format based on the json data model in the preset format, the meaning and rules of each parameter field can be constrained, which helps to reduce the communication of business interfaces, and parse the json input parameters and json output parameters that conform to the preset format to obtain the parsed json input parameters and json output parameters that conform to the preset format, and generate a test case set for the parsed json input parameters that conform to the preset format according to the preset test parameter generation method, and use the test case set to test the business interface to obtain the test results. The test case set can be automatically generated and used to test the business interface, which helps to save time in manually writing automation code, thereby solving the problem of frequent communication in conventional interfaces and lagging automation in the prior art.
[0012] Optionally, the method further comprises:
[0013] When it is determined that the parameter information has changed, the usage parameters in the json data model of the preset format are modified, and based on the modified json data model, the input parameters are determined as the json input parameters that conform to the preset format, and the output parameters are determined as the json output parameters that conform to the preset format.
[0014] In the above technical solution, when it is determined that the interface parameter information has changed, it is only necessary to modify the usage parameters in the preset format of the json data model to quickly complete the maintenance of the interface automation use case, without having to maintain the automation use cases one by one, greatly reducing the maintenance cost of the test cases.
[0015] Optionally, generating a test case set from the parsed JSON input parameters conforming to a preset format according to a preset test parameter generation method includes:
[0016] According to the preset test parameter generation method, the number of values of each parsed JSON input parameter that conforms to the preset format is calculated and classified;
[0017] According to the number of values of the parsed JSON input parameters that conform to the preset format, the parsed JSON input parameters that conform to the preset format are processed to obtain factor values, level values and the number of experiments;
[0018] determining whether there is an experimental table template matching the factor value and the level value in the database;
[0019] If so, then according to the matching experiment table template in the database, according to the factor value, the level value and the number of experiments, the actual parameter data of the json input parameter that conforms to the preset format is filled into the matching experiment table template to generate the test case set; otherwise, an experiment table template with the same factor value and a level value larger than the level value is selected from the database, and according to the factor value, level value and number of experiments in the selected experiment table template, the actual parameter data of the json input parameter that conforms to the preset format is filled into the selected experiment table template to generate the test case set.
[0020] Optionally, the processing of each parsed JSON input parameter conforming to a preset format according to the number of values of each parsed JSON input parameter conforming to a preset format to obtain a factor value, a level value and a number of experiments includes:
[0021] If the number of values of the json input parameters that conform to the preset format after each parsing is the same, the total number of parameters of the json input parameters that conform to the preset format after each parsing is determined as the factor value, the number of values is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
[0022] Optionally, according to the number of values of the parsed JSON input parameters conforming to the preset format, the parsed JSON input parameters conforming to the preset format are processed to obtain factor values, level values and the number of experiments, including:
[0023] If the number of parameter values in the parsed JSON input parameters that conform to the preset format is different, the parsed JSON input parameters that conform to the preset format are sorted according to the number of parameters, and the largest number of parameters in the parsed JSON input parameters that conform to the preset format is determined as the factor value, the sum of the number of values of the parsed JSON input parameters that conform to the preset format is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
[0024] In the above technical scheme, the number of values of each parsed json input parameter that conforms to the preset format is calculated and classified, and different processing is performed according to the same or different number of values of each parsed json input parameter that conforms to the preset format, so as to obtain the factor value, level value and number of experiments, and then the factor value and level value are matched with the experimental table template in the database to match the experimental table template that conforms to the factor value and level value, and according to the experimental table template, the actual parameter data of the json input parameter that conforms to the preset format is filled into the experimental table template according to the factor value, level value and number of experiments, to generate a test case set. Compared with the prior art, in addition to covering all test cases, this method also supports accurate matching of test cases, and can match accurate test cases according to the experimental table template in the database, thereby helping to reduce the generation time of test cases while improving the efficiency of automated writing.
[0025] Optionally, the using the test case set to test the business interface to obtain a test result includes:
[0026] The access address, request method, request header field and test data in the test case set are combined into a message, and the message is sent to the server for processing, so that the server returns the processing result; the processing result is the result of the test.
[0027] In the above technical solution, a message is formed by the query address, request method, request header field and test data in the test case set, and the message is sent to the server, so that the server uses the test data to test the business interface and obtain the test results, which can provide support for subsequent verification of the test results according to the test rules.
[0028] Optionally, after obtaining the test result, the method further includes:
[0029] The test result is verified to obtain a verification result, and the verification result is stored in a database.
[0030] Optionally, the test result includes a message return code and a response result;
[0031] The verifying the test result includes:
[0032] Determine whether the message return code verification is successful, and if so, determine whether the test data in the test case set meets the input parameter rules in the json data model in the preset format;
[0033] If so, according to the business logic rules in the json data model in the preset format, when it is determined that the business logic verification of the parameters in the test case set is successful, the response result is verified based on the parsed json output parameters that conform to the preset format.
[0034] In the above technical scheme, the message return code is verified to determine whether the business interface executes the test case successfully. When it is determined to be successful, it is determined whether the test data in the test case set meets the input parameter rules in the json data model of the preset format. When it is determined to be satisfied, according to the business logic rules in the json data model of the preset format, when it is determined that the business logic verification of the parameters in the test case set is successful, the response result is verified according to the parsed json output parameters that conform to the preset format, and the results of the verification success or failure are stored in the database, which can provide reference support for identifying the execution status of the test case of the business interface.
[0035] In a second aspect, an embodiment of the present invention further provides an interface testing device, comprising:
[0036] An acquisition unit, used to acquire parameter information for setting a service interface; the parameter information includes input parameters and output parameters;
[0037] A processing unit is used to determine the input parameters as JSON input parameters that comply with a preset format and the output parameters as JSON output parameters that comply with a preset format based on a JSON data model in a preset format; parse the JSON input parameters and JSON output parameters that comply with the preset format to obtain the parsed JSON input parameters and JSON output parameters that comply with the preset format, and generate a test case set for the parsed JSON input parameters that comply with the preset format according to a preset test parameter generation method; use the test case set to test the business interface to obtain a test result.
[0038] Optionally, the processing unit is further configured to:
[0039] When it is determined that the parameter information has changed, the usage parameters in the json data model of the preset format are modified, and based on the modified json data model, the input parameters are determined as the json input parameters that conform to the preset format, and the output parameters are determined as the json output parameters that conform to the preset format.
[0040] Optionally, the processing unit is specifically configured to:
[0041] According to the preset test parameter generation method, the number of values of each parsed JSON input parameter that conforms to the preset format is calculated and classified;
[0042] According to the number of values of the parsed JSON input parameters that conform to the preset format, the parsed JSON input parameters that conform to the preset format are processed to obtain factor values, level values and the number of experiments;
[0043] determining whether there is an experimental table template matching the factor value and the level value in the database;
[0044] If so, then according to the matching experiment table template in the database, according to the factor value, the level value and the number of experiments, the actual parameter data of the json input parameter that conforms to the preset format is filled into the matching experiment table template to generate the test case set; otherwise, an experiment table template with the same factor value and a level value larger than the level value is selected from the database, and according to the factor value, level value and number of experiments in the selected experiment table template, the actual parameter data of the json input parameter that conforms to the preset format is filled into the selected experiment table template to generate the test case set.
[0045] Optionally, the processing unit is specifically configured to:
[0046] If the number of values of the json input parameters that conform to the preset format after each parsing is the same, the total number of parameters of the json input parameters that conform to the preset format after each parsing is determined as the factor value, the number of values is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
[0047] Optionally, the processing unit is specifically configured to:
[0048] If the number of parameter values in the parsed JSON input parameters that conform to the preset format is different, the parsed JSON input parameters that conform to the preset format are sorted according to the number of parameters, and the largest number of parameters in the parsed JSON input parameters that conform to the preset format is determined as the factor value, the sum of the number of values of the parsed JSON input parameters that conform to the preset format is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
[0049] Optionally, the processing unit is specifically configured to:
[0050] The access address, request method, request header field and test data in the test case set are combined into a message, and the message is sent to the server for processing, so that the server returns the processing result; the processing result is the result of the test.
[0051] Optionally, the processing unit is further configured to:
[0052] After obtaining the test result, the test result is verified to obtain the verification result, and the verification result is stored in a database.
[0053] Optionally, the test result includes a message return code and a response result;
[0054] The processing unit is specifically used for:
[0055] Determine whether the message return code verification is successful, and if so, determine whether the test data in the test case set meets the input parameter rules in the json data model in the preset format;
[0056] If so, according to the business logic rules in the json data model in the preset format, when it is determined that the business logic verification of the parameters in the test case set is successful, the response result is verified based on the parsed json output parameters that conform to the preset format.
[0057] In a third aspect, an embodiment of the present invention provides a computing device, including:
[0058] Memory for storing computer programs;
[0059] The processor is used to call the computer program stored in the memory and execute the interface testing method according to the obtained program.
[0060] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer-executable program, and the computer-executable program is used to enable a computer to execute an interface testing method. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0062] Figure 1 A schematic diagram of a system architecture provided for an embodiment of the present invention;
[0063] Figure 2 A flowchart of an interface testing method provided by an embodiment of the present invention;
[0064] Figure 3 A schematic diagram of a process for generating a test case set provided by an embodiment of the present invention;
[0065] Figure 4 A schematic diagram of a process for verifying a message return code and a response result provided by an embodiment of the present invention;
[0066] Figure 5 A schematic diagram of the structure of an interface testing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all 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.
[0068] Figure 1 A system architecture is provided for an embodiment of the present invention. Figure 1 As shown, the system architecture may include an editor 101 , a compiler 102 , a linker 103 and a checker 104 .
[0069] Among them, editor 101 is used to position the input parameters and output parameters of the business interface as a json data structure model in a preset format according to requirements or interface documents, define the json data model in a preset format in editor 101, and editor 101 supports json data parsing or single component nesting settings.
[0070] The compiler 102 is used to parse the received json data model in a preset format and generate a test case set. Each type of data corresponds to a basic function library and a business function library, and the basic function library and the business function library provide a method for generating test parameters for the input parameters.
[0071] The linker 103 is used to assemble information such as test data, URL, request method, request header, etc. into a message in the get, post or RMB format, and send the message in the get, post or RMB format to the server for processing to obtain the test information returned by the server.
[0072] The verifier 104 is used to verify the message return code and response result in the test information returned by the server.
[0073] It should be noted that the above Figure 1 The structure shown is only an example and is not limited to this embodiment of the present invention.
[0074] Based on the above description, Figure 2The flow of an interface testing method provided by an embodiment of the present invention is exemplarily shown, and the flow can be executed by an interface testing device.
[0075] like Figure 2 As shown in the figure, the process specifically includes:
[0076] Step 201, obtaining parameter information for setting a service interface.
[0077] In the embodiment of the present invention, the parameter information may include input parameters and output parameters, wherein the developer or tester may define the input parameters and output parameters of the business interface according to the requirements or interface documents.
[0078] Step 202: According to a JSON data model in a preset format, the input parameter is determined as a JSON input parameter that complies with a preset format, and the output parameter is determined as a JSON output parameter that complies with a preset format.
[0079] In the embodiment of the present invention, according to the json data model in a preset format, the input parameter is determined as the json input parameter that conforms to the preset format, and the output parameter is determined as the json output parameter that conforms to the preset format. That is to say, when defining the requirements, the product, development, and testing are connected as a line, and the product personnel, developers, or testers can define the json data model in a preset format for the interface. Through the json data model in a preset format, the meaning and rules of each parameter field can be constrained, which helps to reduce the communication of the business interface. Specifically, the developer or tester can locate the input parameters and output parameters of the business interface as the json data structure model in a preset format according to the requirements or interface documents, and define the json data model in a preset format in the editor, and the editor supports json data parsing or single component nesting settings. In addition, when it is determined that the parameter information of the business interface has changed, it is only necessary to modify the use parameters in the json data model in the preset format, and according to the modified json data model, the input parameters are determined as the json input parameters that conform to the preset format, and the output parameters are determined as the json output parameters that conform to the preset format, so that the maintenance of the interface automation use case can be quickly completed without maintaining the automation use case one by one, which greatly reduces the maintenance cost of the test case.
[0080] It should be noted that the structure of the json data model in the preset format can be expressed as:
[0081]
[0082] The property description of the structure of the json data model in the preset format may be as shown in Table 1.
[0083] Table 1
[0084]
[0085]
[0086] In addition, the constant values of type type can be shown in Table 2.
[0087] Table 2
[0088] type value Corresponding data types object json structure array Arrays enum Enumeration Values integer Integer number Floating point null None boolean Boolean Type string String Function Methods are defined by the interface platform and correspond to the backend methods. weobject The business structure is independently defined by the interface platform and is extensible
[0089] Furthermore, the extended fields of data of type type are described, and the specific description can be as follows:
[0090] (1) object: The keyword is an object, which contains one or more sub-attributes. The extended attributes are as follows:
[0091] properties: used to define sub-properties. The rules for nested sub-properties are the same as those for parent node properties.
[0092] (2)array: The keyword is an array, and the extended attributes are as follows:
[0093] items: The keyword can be a json or a group of json data.
[0094] (3)enum: The keyword is enumeration, and the extended attributes are as follows:
[0095] type: indicates the enumerated data type, such as integer, string, json, etc.
[0096] items: in array form, such as ["name", "age"].
[0097] (4) integer: The keyword is an integer, and the extended attributes are as follows:
[0098] Maximum: Maximum value, indicating that the parameter value must be less than this value.
[0099] exclusiveMaximum: minimum value, indicating that the parameter value is less than or equal to this value.
[0100] Minimum: minimum value, indicating that the parameter value must be greater than this value.
[0101] exclusiveMinimum: minimum value, indicating that the parameter must be greater than or equal to this value.
[0102] (5) number: The keyword is a floating point type. The extended field contains four integer fields and the following extended attributes:
[0103] Digit: The number of decimal places.
[0104] (6) null: The keyword is a null value and has no extended attributes.
[0105] (7) boolean: Boolean type, with values of false and true, and no extended attributes.
[0106] (8) string: The keyword is a string, and the extended attributes are as follows:
[0107] Maxlength: Maximum length, indicating that the parameter value cannot be greater than this length.
[0108] Minlength: The shortest length, indicating that the parameter value cannot be less than this length.
[0109] Pattern: regular expression, indicating that the string conforms to the regular expression.
[0110] Format: The format of the keyword, including date, datetime, email, hostname, ipv4, ipv6, etc.
[0111] (9) function: corresponds to the background method. The data array returned by the background method is the data of the parameter. The extended attributes are as follows:
[0112] funname: the method name corresponding to the background.
[0113] (10)weobject: Metadata structure of various objects corresponding to the business. The background defines various fields and data sources. The extended attributes are as follows:
[0114] wename: The class name corresponding to the background, the data can be initialized by the class.
[0115] Step 203, parse the json input parameters and json output parameters that conform to the preset format to obtain the parsed json input parameters and json output parameters that conform to the preset format, and generate a test case set for the parsed json input parameters that conform to the preset format according to the preset test parameter generation method.
[0116] In the embodiment of the present invention, the json input parameters and json output parameters that conform to the preset format are parsed to obtain the parsed json input parameters and json output parameters that conform to the preset format, and the number of values of each parsed json input parameter that conforms to the preset format is calculated and classified according to the preset test parameter generation method. If the number of values of each parsed json input parameter that conforms to the preset format is the same, the total number of parameters of each parsed json input parameter that conforms to the preset format is determined as the factor value, the number of values is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments; if the number of parameter values of each parsed json input parameter that conforms to the preset format is different, the parsed json input parameters that conform to the preset format are sorted according to the number of parameters, and the largest number of parameters in each parsed json input parameter that conforms to the preset format is determined as the factor value, the sum of the number of values of each parsed json input parameter that conforms to the preset format is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments. Then determine whether there is an experimental table template matching the factor value and the level value in the database. If so, fill the actual parameter data of the json input parameter in the preset format into the matching experimental table template according to the factor value, the level value and the number of experiments in accordance with the matching experimental table template in the database to generate a test case set. Otherwise, select an experimental table template with the same factor value and a level value greater than the level value of the json input parameter in the preset format from the database, and fill the actual parameter data of the json input parameter in the preset format into the selected experimental table template according to the factor value, the level value and the number of experiments in the selected experimental table template to generate a test case set. Compared with the prior art, in addition to covering all test cases, this method also supports accurate matching of test cases. It can match accurate test cases according to the experimental table template in the database, thereby helping to reduce the generation time of test cases while improving the efficiency of automated writing, and having sufficient test cases for development self-testing in the development and joint debugging stage, which helps to solve the problem of lagging automated writing of conventional interfaces and provide guarantee for R&D quality.
[0117] Specifically, in the compiler, the received json input parameters and json output parameters that conform to the preset format are parsed to obtain the parsed json input parameters and json output parameters that conform to the preset format, and according to the preset test parameter generation method, the parsed json input parameters that conform to the preset format are used to generate a test case set. Among them, each type of data corresponds to a basic function library and a business function library, and the basic function library and the business function library provide a method for generating test parameters for the json input parameters that conform to the preset format. The test data generation rules of the basic type can be shown in Table 3.
[0118] Table 3
[0119]
[0120] Before accurately generating test cases based on json input parameters that conform to the preset format, it is necessary to maintain the experimental table template in the database in advance. First, complete the parameter range according to the json input parameters that conform to the preset format, and then calculate and classify the parameter data set to obtain the level value (number of values) and factor value (number of parameters). If they belong to the same category of values, you can directly obtain n / m / k (m is the number of parameters, k is the number of values, and n is the number of experiments). For example, there are three parameters A, B, and C, and each parameter has two values. Then parameters A, B, and C belong to the same category of values, m=3, k=2, and n=m*(k-1)+1=3*(2-1)+1=4. If there are different types of values, you need to sort them by the number of parameters before obtaining n / m / k. For example, there are two different types of values. One type has four parameters, each with one value, and the other type has three parameters, each with two values, that is, [(4,1), (3,2)]. Sorting by the number of parameters will change to [(3,2), (4,1)]. Then calculate n / m / k, m = max(m 1 , m 2 ,...)=max(3,4)=4,k=(k 1 +k 2 +…)=(1+2)=3, n=k 1 *(m 1 -1)+k 2 *(m 2 -1)+1=2*(3-1)+1*(4-1)+1=8. Then, by matching the factor value and level value with the experimental table template in the database, it is determined whether there is a completely matching experimental table template in the database. If it can be completely matched, the actual parameter data of the json input parameters that conform to the preset format are filled into the matching experimental table template according to the matching experimental table template in the database, based on the factor value, level value and number of experiments, to generate a test case set. If the experimental table template cannot be matched, the experimental table template greater than or equal to n / m / k in the database is selected, and then the experimental table template with the least number of experiments is selected from it, and the actual parameter data of the json input parameters that conform to the preset format are filled into the experimental table template according to the factor value, level value and number of experiments in the experimental table template with the least number of experiments. For the test cases that are filled with more actual parameter data (i.e., the test cases that are not filled with actual parameter data), None is given priority, and then all None test cases are eliminated, and default test cases are added to finally generate a test case set.
[0121] Step 204: Use the test case set to test the business interface to obtain a test result.
[0122] In an embodiment of the present invention, the access address, request method, request header field and test data in the test case set are composed into a message, and the message is sent to the server for processing, so that the server returns the result of the processing; the result of the processing is the result of the test, which can provide support for the subsequent verification of the test result according to the test rules, wherein the test result can include the message return code and the response result. After obtaining the test result, the test result is verified, that is, it is determined whether the message return code verification is successful. If so, it is determined whether the test data in the test case set meets the input parameter rules in the json data model of the preset format. If so, according to the business logic rules in the json data model of the preset format, and when it is determined that the business logic verification of the parameters in the test case set is successful, the response result is verified according to the parsed json output parameters that meet the preset format, and then the verification results are stored in the database, which can provide reference support for identifying the execution of the test case of the business interface.
[0123] Specifically, the linker assembles the test data, URL, request method, request header and other information into a message in the format of GET, POST or RMB, and sends the message in the format of GET, POST or RMB to the server for processing, obtains the test information returned by the server, and verifies the message return code and response result in the test information returned by the server in the verifier. The specific verification rules may be:
[0124] a. Verification code: This part mainly determines whether the interface can be executed successfully. For example, for http request, the return code is 200.
[0125] b. Verify test data rules: According to the specifications of the JSON input parameters in the preset format, determine whether the current test data meets the input parameter rules in the JSON data model in the preset format.
[0126] c. Business logic verification rules: According to the logicCheck rules in the preset json data model, determine whether the business logic of the parameters in the test case set has been verified.
[0127] d. Verification template for verification matching: the verification rule of response (response result), that is, the JSON output parameter rule that conforms to the preset format, matches the response result with the JSON output parameter rule that conforms to the preset format, and determines whether the match is successful or failed.
[0128] By using the above verification rules, the execution result of a test case can be judged by referring to Table 4.
[0129] Table 4
[0130] code check rule check response check Use case results 0 0 0 success 0 0 1 fail 0 1 0 fail 0 1 1 fail 1 0 0 fail 1 0 1 success 1 1 0 success 1 1 1 success
[0131] In order to better explain the embodiment of generating a test case set of the present invention, a process of generating a test case set provided by an embodiment of the present invention is described below through a specific implementation scenario.
[0132] like Figure 3 As shown, the process includes the following steps:
[0133] Step 301, obtain the number of parameters and the number of values.
[0134] Calculate and classify the actual parameter data set of the parameters to obtain the number of parameters (factor values) and the number of values (level values).
[0135] Step 302, whether the number of parameter values is exactly the same, if so, execute step 304, if not, execute step 303.
[0136] After calculating and classifying the actual parameter data set of the parameters, it is determined whether the number of values of each parameter is the same, that is, the orthogonal table with different numbers of values of each parameter is a mixed-level orthogonal table, and the orthogonal table with the same number of values of each parameter is a single-level orthogonal table.
[0137] Step 303: sort by the number of parameters.
[0138] When it is determined that the number of values of each parameter is not completely the same, the classified parameters are sorted according to the number of parameters.
[0139] Step 304, obtain the number of parameters / number of values / number of experiments.
[0140] If the number of values of each parameter is completely the same or not completely the same, the number of parameters, the number of values and the number of experiments are calculated according to different processing methods.
[0141] Step 305 , whether there is a completely matching experimental table template in the database, if so, execute step 306 , if not, execute step 307 .
[0142] After obtaining the number of parameters / values / experiments, it is determined whether there is a completely matching experimental table template in the database, that is, whether there is an experimental table template matching the factor value and level value in the database.
[0143] Step 306: Fill the actual parameter data of the parameter into the matching experiment table template.
[0144] After determining that there is a completely matching experimental table template in the database, according to the matching experimental table template in the database, the actual parameter data of the json input parameters that conform to the preset format are filled into the matching experimental table template according to the factor value, level value and number of experiments.
[0145] Step 307, matching an experiment table template that is greater than or equal to the number of parameters / number of values / number of experiments.
[0146] After determining that no experimental table template is matched in the database, an experimental table template with the same factor value and a level value greater than the level value of the json input parameter that conforms to the preset format is selected from the database.
[0147] Step 308, selecting the experiment table template with the least number of experiments.
[0148] Select the experiment table template with the least number of experiments from the selected experiment table template set.
[0149] Step 309, fill the actual parameter data of the parameter into the experimental table template, and fill the test cases that are not filled with actual parameter data with None.
[0150] Fill the actual parameter data of the json input parameter that conforms to the preset format into the experimental table template, and give priority to None for the test cases that are excessive during the filling process (i.e., the test cases that are not filled).
[0151] Step 310, remove all None test cases.
[0152] Step 311, generate a test case set.
[0153] Eliminate all None test cases, add default test cases, and finally generate a test case set.
[0154] The above embodiment shows that by calculating and classifying the number of values of each parsed json input parameter that conforms to the preset format, and performing different processing according to the same or different number of values of each parsed json input parameter that conforms to the preset format, so as to obtain the factor value, level value and number of experiments, and then matching the factor value and level value with the experiment table template in the database, matching the experiment table template that conforms to the factor value and level value, and according to the experiment table template, according to the factor value, level value and number of experiments, filling the actual parameter data of the json input parameter that conforms to the preset format into the experiment table template, and generating a test case set. Compared with the prior art, in addition to covering all test cases, this method also supports accurate matching of test cases, and can match accurate test cases according to the experiment table template in the database, thereby helping to reduce the generation time of test cases while improving the efficiency of automated writing.
[0155] In order to better explain an embodiment of the present invention for verifying a message return code and a response result, a process for verifying a message return code and a response result provided by an embodiment of the present invention is described below through a specific implementation scenario.
[0156] like Figure 4 As shown, the process includes the following steps:
[0157] Step 401, obtaining the message return code and response result.
[0158] Get the message return code and response result of sending the message to the server for processing and returning, and then verify the message return code and response result.
[0159] Step 402, determine whether the message return code verification is successful, if so, execute step 403, if not, execute step 406.
[0160] Step 403, determine whether the current test data meets the input parameter rules, if so, execute step 404, if not, execute step 406.
[0161] According to the input parameter rules of the JSON data model in the database, determine whether the current test data meets the input parameter rules in the JSON data model of the preset format.
[0162] Step 404, determine whether the business logic verification of the parameters in the test case set is successful, if so, execute step 405, if not, execute step 406.
[0163] According to the logicCheck rules of the json data model in the database, determine whether the business logic of the parameters in the test case set has been verified.
[0164] Step 405, determine whether the response result matches the verification rule of response successfully, if so, execute step 406, if not, execute step 406.
[0165] According to the verification rule of the response in the database, that is, the JSON output parameter rule that conforms to the preset format, the response result is matched with the JSON output parameter rule that conforms to the preset format, and the match is determined to be successful or failed.
[0166] Step 406, storing the verification result in the database.
[0167] The above embodiment shows that by verifying the message return code, it is determined whether the business interface executes the test case successfully. When it is determined to be successful, it is determined whether the test data in the test case set meets the input parameter rules in the json data model of the preset format. When it is determined to be satisfied, according to the business logic rules in the json data model of the preset format, when it is determined that the business logic verification of the parameters in the test case set is successful, the response result is verified according to the parsed json output parameters that conform to the preset format, and the results of the verification success or failure are stored in the database, which can provide reference support for identifying the execution status of the test case of the business interface.
[0168] Based on the same technical concept, Figure 5 An interface testing device provided by an embodiment of the present invention is exemplarily shown, and the device can execute the process of the interface testing method.
[0169] like Figure 5 As shown, the device comprises:
[0170] The acquisition unit 501 is used to acquire parameter information for setting a service interface; the parameter information includes input parameters and output parameters;
[0171] The processing unit 502 is used to determine the input parameters as JSON input parameters that comply with the preset format and the output parameters as JSON output parameters that comply with the preset format based on the JSON data model in the preset format; parse the JSON input parameters and JSON output parameters that comply with the preset format to obtain the parsed JSON input parameters and JSON output parameters that comply with the preset format, and generate a test case set for the parsed JSON input parameters that comply with the preset format according to a preset test parameter generation method; use the test case set to test the business interface to obtain the test result.
[0172] Optionally, the processing unit 502 is further configured to:
[0173] When it is determined that the parameter information has changed, the usage parameters in the json data model of the preset format are modified, and based on the modified json data model, the input parameters are determined as the json input parameters that conform to the preset format, and the output parameters are determined as the json output parameters that conform to the preset format.
[0174] Optionally, the processing unit 502 is specifically configured to:
[0175] According to the preset test parameter generation method, the number of values of each parsed JSON input parameter that conforms to the preset format is calculated and classified;
[0176] According to the number of values of the parsed JSON input parameters that conform to the preset format, the parsed JSON input parameters that conform to the preset format are processed to obtain factor values, level values and the number of experiments;
[0177] determining whether there is an experimental table template matching the factor value and the level value in the database;
[0178] If so, then according to the matching experiment table template in the database, according to the factor value, the level value and the number of experiments, the actual parameter data of the json input parameter that conforms to the preset format is filled into the matching experiment table template to generate the test case set; otherwise, an experiment table template with the same factor value and a level value larger than the level value is selected from the database, and according to the factor value, level value and number of experiments in the selected experiment table template, the actual parameter data of the json input parameter that conforms to the preset format is filled into the selected experiment table template to generate the test case set.
[0179] Optionally, the processing unit 502 is specifically configured to:
[0180] If the number of values of the json input parameters that conform to the preset format after each parsing is the same, the total number of parameters of the json input parameters that conform to the preset format after each parsing is determined as the factor value, the number of values is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
[0181] Optionally, the processing unit 502 is specifically configured to:
[0182] If the number of parameter values in the parsed JSON input parameters that conform to the preset format is different, the parsed JSON input parameters that conform to the preset format are sorted according to the number of parameters, and the largest number of parameters in the parsed JSON input parameters that conform to the preset format is determined as the factor value, the sum of the number of values of the parsed JSON input parameters that conform to the preset format is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
[0183] Optionally, the processing unit 502 is specifically configured to:
[0184] The access address, request method, request header field and test data in the test case set are combined into a message, and the message is sent to the server for processing, so that the server returns the processing result; the processing result is the result of the test.
[0185] Optionally, the processing unit 502 is further configured to:
[0186] After obtaining the test result, the test result is verified to obtain the verification result, and the verification result is stored in a database.
[0187] Optionally, the test result includes a message return code and a response result;
[0188] The processing unit 502 is specifically used for:
[0189] Determine whether the message return code verification is successful, and if so, determine whether the test data in the test case set meets the input parameter rules in the json data model in the preset format;
[0190] If so, according to the business logic rules in the json data model in the preset format, when it is determined that the business logic verification of the parameters in the test case set is successful, the response result is verified based on the parsed json output parameters that conform to the preset format.
[0191] Based on the same technical concept, an embodiment of the present invention provides a computing device, including:
[0192] Memory for storing computer programs;
[0193] The processor is used to call the computer program stored in the memory and execute the interface testing method according to the obtained program.
[0194] Based on the same technical concept, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer-executable program, and the computer-executable program is used to enable a computer to execute an interface testing method.
[0195] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0196] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0197] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0198] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0199] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0200] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of this application and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. An interface testing method, characterized in that: include: Get parameter information for setting business interface; The parameter information includes input parameters and output parameters; According to the json data model in the preset format, the input parameter is determined as the json input parameter conforming to the preset format, and the output parameter is determined as the json output parameter conforming to the preset format; Parsing the json input parameter and the json output parameter that conform to the preset format to obtain the parsed json input parameter and the json output parameter that conform to the preset format; According to the preset test parameter generation method, the number of values of the parsed JSON input parameters that conform to the preset format is calculated and classified; According to the number of values of the parsed JSON input parameters that conform to the preset format, the parsed JSON input parameters that conform to the preset format are processed to obtain factor values, level values and the number of experiments; Determine whether there is an experimental table template matching the factor value and the level value in the database; If yes, then fill the actual parameter data of the json input parameter conforming to the preset format into the matching experiment table template in the database according to the factor value, the level value and the number of experiments to generate a test case set; If not, select the experimental table templates with a number greater than or equal to the number of experiments / number of parameters / number of values in the database, select the experimental table template with the least number of experiments, and fill the actual parameter data of the json input parameters that conform to the preset format into the experimental table template according to the factor values, level values and number of experiments in the experimental table template with the least number of experiments, set None to the test cases that are not filled with actual parameter data, remove all None test cases, add default test cases, and generate a test case set; The service interface is tested using the test case set to obtain test results.
2. The method according to claim 1, characterized in that The method further comprises: When it is determined that the parameter information has changed, the usage parameters in the json data model of the preset format are modified, and based on the modified json data model, the input parameters are determined as the json input parameters that conform to the preset format, and the output parameters are determined as the json output parameters that conform to the preset format.
3. The method according to claim 1, characterized in that According to the number of values of the parsed JSON input parameters that conform to the preset format, the parsed JSON input parameters that conform to the preset format are processed to obtain factor values, level values and the number of experiments, including: If the number of values of the json input parameters that conform to the preset format after each parsing is the same, the total number of parameters of the json input parameters that conform to the preset format after each parsing is determined as the factor value, the number of values is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
4. The method according to claim 1, characterized in that According to the number of values of the parsed JSON input parameters that conform to the preset format, the parsed JSON input parameters that conform to the preset format are processed to obtain factor values, level values and the number of experiments, including: If the number of parameter values in the parsed JSON input parameters that conform to the preset format is different, the parsed JSON input parameters that conform to the preset format are sorted according to the number of parameters, and the largest number of parameters in the parsed JSON input parameters that conform to the preset format is determined as the factor value, the sum of the number of values of the parsed JSON input parameters that conform to the preset format is determined as the level value, and the factor value and the level value are calculated to obtain the number of experiments.
5. The method according to claim 1, characterized in that The using the test case set to test the business interface to obtain the test result includes: The access address, request method, request header field and test data in the test case set are combined into a message, and the message is sent to the server for processing, so that the server returns the processing result; the processing result is the result of the test.
6. The method according to any one of claims 1 to 5, characterized in that: After obtaining the test result, the method further includes: The test result is verified to obtain a verification result, and the verification result is stored in a database.
7. The method according to claim 6, characterized in that The test result includes a message return code and a response result; The verifying the test result includes: Determine whether the message return code verification is successful, and if so, determine whether the test data in the test case set meets the input parameter rules in the json data model in the preset format; If so, according to the business logic rules in the json data model in the preset format, when it is determined that the business logic verification of the parameters in the test case set is successful, the response result is verified based on the parsed json output parameters that conform to the preset format.
8. An interface testing device, characterized in that: include: An acquisition unit, used to acquire parameter information of a setting service interface; The parameter information includes input parameters and output parameters; A processing unit, configured to determine the input parameter as a JSON input parameter conforming to a preset format, and determine the output parameter as a JSON output parameter conforming to a preset format, according to a JSON data model in a preset format; Parsing the json input parameter and the json output parameter that conform to the preset format to obtain the parsed json input parameter and the json output parameter that conform to the preset format; According to the preset test parameter generation method, the number of values of the parsed JSON input parameters that conform to the preset format is calculated and classified; According to the number of values of the parsed JSON input parameters that conform to the preset format, the parsed JSON input parameters that conform to the preset format are processed to obtain factor values, level values and the number of experiments; Determine whether there is an experimental table template matching the factor value and the level value in the database; If yes, then fill the actual parameter data of the json input parameter conforming to the preset format into the matching experiment table template in the database according to the factor value, the level value and the number of experiments to generate a test case set; If not, select the experimental table templates with a number greater than or equal to the number of experiments / number of parameters / number of values in the database, select the experimental table template with the least number of experiments, and fill the actual parameter data of the json input parameters that conform to the preset format into the experimental table template according to the factor values, level values and number of experiments in the experimental table template with the least number of experiments, set None to the test cases that are not filled with actual parameter data, remove all None test cases, add default test cases, and generate a test case set; The service interface is tested using the test case set to obtain test results.
9. A computing device, characterized in that include: Memory for storing computer programs; A processor, configured to call a computer program stored in the memory, and execute the method according to any one of claims 1 to 7 according to the obtained program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer-executable program, and the computer-executable program is used to enable a computer to execute the method according to any one of claims 1 to 7.
