A parameter verification method, device, equipment and computer-readable storage medium
Through automated testing and verification methods, the missing and error problems of manual parameter verification have been solved, and high -efficiency and flexible parameter checks are achieved, and test coverage and work efficiency are improved.
Patent Information
- Application Number
- CN202411535366.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-10-31
AI Technical Summary
Manual parameter verification is prone to omissions and errors, and it is difficult to cope with the needs of complex verification logic and changes.
By obtaining the testing needs of the test scene, the application programming interface of the test platform to extracts the keyword cluster of the parameters, and query the test case generator that matches the keyword cluster from the test request to the keyword cluster according to the test needs. Carry out automation verification.
The automated verification test of the parameter has been implemented, the user's self -judgment work is reduced, the test coverage and work efficiency are improved, and the test case can be automatically adjusted when the interface parameter changes.
Smart Images

Figure CN119046173B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing technology, and in particular to a parameter verification method, device, equipment and computer-readable storage medium. Background Art
[0002] Parameter verification is an essential part of the development process. If parameter verification is missing or missing, it is likely to cause serious damage to the stability and security of the system. Currently, manual verification is used to test parameters. The advantage of this method is that it is highly flexible and can write test cases according to specific needs and specific verification rules.
[0003] However, manual verification requires manually writing a lot of verification logic, which is prone to omissions and errors. It also causes redundant automated test code, poor readability, and difficulty in dealing with complex verification logic and changing requirements.
[0004] It can be seen that how to complete parameter verification conveniently and efficiently is a problem that technical personnel in this field need to solve. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to provide a parameter verification method, device, equipment and computer-readable storage medium, which can solve the problem that manual verification is prone to omissions and errors and is difficult to cope with complex verification logic and changing requirements.
[0006] In order to solve the above technical problems, an embodiment of the present invention provides a parameter verification method, including:
[0007] Obtain test requirements for test scenarios;
[0008] Traverse the testbed’s application programming interface to extract keyword clusters for input;
[0009] According to the test requirements, a test case generator matching the keyword cluster is searched from a test case generation library, and a corresponding test case is generated according to the test case generator matching the keyword cluster; wherein the test case generation library includes various test case generators, and various test case generators are test case generators constructed according to verification methods of different types of parameters; different keyword clusters correspond to different test case generators;
[0010] The test case is used to verify each keyword included in the keyword cluster to obtain a verification result.
[0011] On the one hand, with respect to the construction of various test case generators in the test case generation library, the method further includes:
[0012] Based on the verification attributes of different types of parameters, the verification logic corresponding to each type of parameter is determined;
[0013] Encapsulate the verification logic corresponding to each type of parameter into a test case generator;
[0014] Establish a mapping relationship between various parameters and their corresponding test case generators.
[0015] On the one hand, based on the verification attributes of different types of parameters, the verification logic corresponding to each type of parameter is determined, including:
[0016] When the verification attribute of the target parameter includes mandatory parameter verification, a parameter legal value verification process is set; wherein the target parameter is any parameter of different types;
[0017] When the verification attribute of the target parameter includes data length verification, the data length verification process is set according to the theoretical length of the data;
[0018] When the verification attribute of the target parameter includes parameter type verification, the parameter type verification process is set according to the data format of different parameter types;
[0019] In the case where the verification data of the target parameter includes enumeration verification, the enumeration verification process is set according to all enumeration values corresponding to the target parameter.
[0020] On the one hand, when the validation attribute of the target parameter includes mandatory parameter validation, the process of setting the parameter legal value validation includes:
[0021] When the target parameter has a required flag and the target parameter is empty, set the check interface to return a non-empty check; when the target parameter has a required flag and the target parameter is not empty, set the check interface to return a successful check;
[0022] Set the check interface to return a successful check when the target parameter does not have a required flag and the target parameter is passed empty.
[0023] On the one hand, when the verification attribute of the target parameter includes data length verification, setting the data length verification process according to the theoretical length of the data includes:
[0024] Get the data length of the target parameter;
[0025] When the data length of the target parameter matches its corresponding theoretical length, a check interface is set to return a successful check;
[0026] When the data length of the target parameter does not match its corresponding theoretical length, a parameter legal value verification process is executed.
[0027] On the one hand, we traverse the test platform’s application programming interface to extract keyword clusters including:
[0028] Traversing the application programming interface of the test platform to obtain all input parameters of the test platform;
[0029] According to the validation attributes of different types of parameters, matching keywords are extracted from the parameter descriptions corresponding to each input parameter to build a keyword cluster.
[0030] On the one hand, according to the test requirement, searching a test case generator matching the keyword cluster from a test case generation library includes:
[0031] Determine the verification attributes corresponding to each type of keyword in the keyword cluster according to the test requirements of the test scenario;
[0032] Based on the verification attributes corresponding to each type of keyword, a test case generator matching each type of keyword is obtained from the test case generation library.
[0033] On the one hand, after verifying each keyword included in the keyword cluster using the test case to obtain a verification result, the method further includes:
[0034] According to the verification results of each test case and its corresponding expected results, the keyword cluster and its corresponding test case are optimized to obtain a test tool;
[0035] The test tool is used to test the parameters to be verified to obtain parameter verification results.
[0036] On the one hand, according to the verification results of each test case and its corresponding expected result, the keyword cluster and its corresponding test case are optimized to obtain the test tool including:
[0037] Determine the cause of the test case execution failure based on the deviation between the verification result of the target test case and the expected result;
[0038] An optimization strategy matching the reason for the failure of the test case execution is obtained, and the keyword cluster and the corresponding test case are optimized according to the optimization strategy to obtain a test tool.
[0039] On the one hand, according to the deviation between the verification result of the target test case and the expected result, the reasons for the failure of the test case execution are determined to include:
[0040] When the verification result of the target test case is inconsistent with the expected result, it is determined that the test case execution fails; wherein the verification result includes the interface access result, the error code returned by the interface, and the error information returned by the interface;
[0041] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is an access failure, it is determined that the reason for the failure of the test case execution is that parameter verification is not added;
[0042] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is successful access, it is determined that the reason for the failure of the test case execution is that more parameter verification is added;
[0043] When the error code returned by the interface is inconsistent with the expected error code, the reason for the failure of the test case execution is determined to be that the parameter verification accuracy does not meet the standard;
[0044] When the error message returned by the interface is inconsistent with the expected error message, it is determined that the reason for the failure of the test case execution is incorrect prompt information.
[0045] On the one hand, obtaining an optimization strategy that matches the reason for the failure of the test case execution, optimizing the keyword cluster and the corresponding test case to obtain a test tool including:
[0046] Determine whether there is an optimization strategy matching the cause of the test case execution failure in the pre-established strategy library;
[0047] In the case where there is an optimization strategy matching the cause of the test case execution failure in the pre-established strategy library, obtaining the optimization strategy matching the cause of the test case execution failure from the pre-established strategy library;
[0048] In the case where there is no optimization strategy matching the reason for the failure of the test case execution in the pre-established strategy library, the reason for the failure of the test case execution is displayed to the user terminal to obtain the optimization strategy fed back by the user terminal;
[0049] The keyword cluster and its corresponding test cases are optimized according to the optimization strategy to obtain a test tool.
[0050] On the one hand, after searching a test case generator matching the keyword cluster from a test case generation library according to the test requirement, and generating a corresponding test case according to the test case generator matching the keyword cluster, the method further includes:
[0051] When a change is detected in the target application programming interface of the test platform, re-extracting the target keyword of the target application programming interface input parameter;
[0052] According to the test case generator matched with the target keyword, the test case corresponding to the target application programming interface is adjusted.
[0053] The embodiment of the present invention also provides a parameter verification device, including an acquisition unit, an extraction unit, a query unit, a generation unit and a verification unit;
[0054] The acquisition unit is used to acquire the test requirements of the test scenario;
[0055] The extraction unit is used to traverse the application programming interface of the test platform to extract the keyword clusters for input;
[0056] The query unit is used to query the test case generator matching the keyword cluster from the test case generation library according to the test requirements, wherein the test case generation library includes various test case generators, and the various test case generators are test case generators constructed according to the verification methods of different types of parameters; different keyword clusters correspond to different test case generators;
[0057] The generating unit is used to generate corresponding test cases according to the test case generator matched by the keyword cluster;
[0058] The verification unit is used to verify each keyword included in the keyword cluster using the test case to obtain a verification result.
[0059] On the one hand, for the construction of various test case generators in the test case generation library, the device also includes a verification logic determination unit, an encapsulation unit and a mapping unit;
[0060] The verification logic determination unit is used to determine the verification logic corresponding to each type of parameter based on the verification attributes of each type of parameter;
[0061] The encapsulation unit is used to encapsulate the verification logic corresponding to each type of parameter into a test case generator;
[0062] The mapping unit is used to establish a mapping relationship between various parameters and their corresponding test case generators.
[0063] On the one hand, the verification logic determination unit includes a first setting subunit, a second setting subunit, a third setting subunit and a fourth setting subunit; the first setting subunit is used to set a parameter legal value verification process when the verification attribute of the target parameter includes a required parameter verification; wherein the target parameter is any one of different types of parameters;
[0064] The second setting subunit is used to set the data length verification process according to the theoretical length of the data when the verification attribute of the target parameter includes data length verification;
[0065] The third setting subunit is used to set the parameter type verification process according to the data formats of different parameter types when the verification attribute of the target parameter includes parameter type verification;
[0066] The fourth setting subunit is used to set the enumeration verification process according to all enumeration values corresponding to the target parameter when the verification data of the target parameter includes enumeration verification.
[0067] On the one hand, the first setting subunit is used to set the check interface to return a non-empty check when the target parameter has a required flag and the target parameter is empty, and to set the check interface to return a success check when the target parameter has a required flag and the target parameter is not empty;
[0068] Set the check interface to return a successful check when the target parameter does not have a required flag and the target parameter is passed empty.
[0069] On the one hand, the second setting subunit is used to obtain the data length of the target parameter;
[0070] When the data length of the target parameter matches its corresponding theoretical length, a check interface is set to return a successful check;
[0071] When the data length of the target parameter does not match its corresponding theoretical length, a parameter legal value verification process is executed.
[0072] In one aspect, the extraction unit includes an acquisition subunit and a construction subunit;
[0073] The acquisition subunit is used to traverse the application programming interface of the test platform to obtain all input parameters of the test platform;
[0074] The construction subunit is used to extract matching keywords from the parameter descriptions corresponding to each input parameter according to the respective verification attributes of different types of parameters, so as to construct a keyword cluster.
[0075] On the one hand, the query unit is used to determine the verification attributes corresponding to each type of keyword in the keyword cluster according to the test requirements of the test scenario; based on the verification attributes corresponding to each type of keyword, obtain the test case generator matching each type of keyword from the test case generation library.
[0076] On the one hand, it also includes optimization units and testing units;
[0077] The optimization unit is used to optimize the keyword cluster and its corresponding test case according to the verification result of each test case and its corresponding expected result, so as to obtain a test tool;
[0078] The testing unit is used to test the parameters to be verified using the testing tool to obtain parameter verification results.
[0079] In one aspect, the optimization unit includes a cause determination subunit and an obtaining subunit;
[0080] The cause determination subunit is used to determine the cause of the test case execution failure based on the deviation between the verification result of the target test case and the expected result;
[0081] The obtaining subunit is used to obtain an optimization strategy that matches the reason for the failure of the test case execution, and optimize the keyword cluster and the corresponding test case according to the optimization strategy to obtain a test tool.
[0082] On the one hand, the cause determination subunit is used to determine that the test case execution fails when the verification result of the target test case is inconsistent with the expected result; wherein the verification result includes the interface access result, the error code returned by the interface, and the error information returned by the interface;
[0083] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is an access failure, it is determined that the reason for the failure of the test case execution is that parameter verification is not added;
[0084] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is successful access, it is determined that the reason for the failure of the test case execution is that more parameter verification is added;
[0085] When the error code returned by the interface is inconsistent with the expected error code, the reason for the failure of the test case execution is determined to be that the parameter verification accuracy does not meet the standard;
[0086] When the error message returned by the interface is inconsistent with the expected error message, it is determined that the reason for the failure of the test case execution is incorrect prompt information.
[0087] On the one hand, the obtaining subunit is used to determine whether there is an optimization strategy matching the reason for the failure of the test case execution in the pre-established strategy library;
[0088] In the case where there is an optimization strategy matching the cause of the test case execution failure in the pre-established strategy library, obtaining the optimization strategy matching the cause of the test case execution failure from the pre-established strategy library;
[0089] In the case where there is no optimization strategy matching the reason for the failure of the test case execution in the pre-established strategy library, the reason for the failure of the test case execution is displayed to the user terminal to obtain the optimization strategy fed back by the user terminal;
[0090] The keyword cluster and its corresponding test cases are optimized according to the optimization strategy to obtain a test tool.
[0091] On the one hand, it also includes an adjustment unit;
[0092] The extraction unit is also used to re-extract the target keyword of the target application programming interface input parameter when it is detected that the target application programming interface of the test platform has changed;
[0093] The adjustment unit is used to adjust the test case corresponding to the target application programming interface according to the test case generator matched by the target keyword.
[0094] The embodiment of the present invention further provides a parameter verification device, including:
[0095] Memory for storing computer programs;
[0096] A processor is used to execute the computer program to implement the steps of the parameter verification method as described above.
[0097] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the parameter verification method described above are implemented.
[0098] An embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the above parameter verification method when executed by a processor.
[0099] It can be seen from the above technical solution that the test requirements of the test scenario are obtained; the application programming interface of the test platform is traversed to extract the keyword clusters for input. According to the test requirements, the test case generator that matches the keyword cluster is queried from the test case generation library. The test case generation library includes various types of test case generators, and various types of test case generators can be constructed according to the verification methods of different types of parameters. Since the test case generator contains the verification logic of the parameters, the test case generator that matches the keyword cluster can generate the corresponding test case; the test case is used to automatically verify each keyword contained in the keyword cluster to obtain the verification result.
[0100] The beneficial effect of the present invention is that by constructing a test case generator corresponding to various parameters, and linking with the test platform, combined with keyword drive, test cases can be automatically generated, thereby completing the automated verification test of the parameters. Compared with manually writing the verification logic, this solution reduces the work of user self-judgment and improves test coverage and work efficiency. In addition, different keyword clusters correspond to different test case generators. When the interface parameters of the test platform change, the test cases for parameter verification can also be automatically adjusted, which improves the flexibility of automated verification testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0101] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. 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.
[0102] Figure 1 A flow chart of a parameter verification method provided by an embodiment of the present invention;
[0103] Figure 2 A flowchart of a method for constructing a test case generator provided by an embodiment of the present invention;
[0104] Figure 3 A flowchart of a method for determining the cause of a test case execution failure provided by an embodiment of the present invention;
[0105] Figure 4 A schematic diagram of the structure of a parameter verification device provided by an embodiment of the present invention;
[0106] Figure 5 A structural diagram of a parameter verification device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0107] 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 only 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.
[0108] The terms "including" and "having" in the specification of the present invention and the above-mentioned drawings, as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not limited to the listed steps or units, but may include steps or units that are not listed.
[0109] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0110] Next, a parameter verification method provided by an embodiment of the present invention is introduced in detail. Figure 1 A flow chart of a parameter verification method provided by an embodiment of the present invention, the method comprising:
[0111] S101: Obtain test requirements for a test scenario.
[0112] Different test scenarios may have different test requirements, so the test cases called may also be different. In the embodiment of the present invention, when executing the parameter verification, the test requirements of the test scenario may be obtained first.
[0113] S102: Traverse the application programming interface of the test platform to extract keyword clusters as input parameters.
[0114] In actual applications, the application programming interface (API) of the test platform can be traversed to obtain all input parameters of the test platform. According to the verification attributes of different types of parameters, matching keywords are extracted from the parameter descriptions corresponding to each input parameter to build a keyword cluster.
[0115] Keywords may include required parameters, parameter types, parameter values, parameter restrictions, etc.
[0116] The required parameters are not fixed. For example, the user name is a required parameter when creating a user interface.
[0117] There can be many restrictions on parameters, for example, the parameter cannot start with the set information or the parameter can only start with the set information, or the maximum length of the parameter cannot exceed the set upper limit of the length, and the minimum length of the parameter cannot be less than the set lower limit of the length, etc.
[0118] In the embodiment of the present invention, by accessing the API design, development, and testing integrated collaboration platform developed, all input parameters in the API are traversed, and keywords such as required parameters, parameter types, parameter values, and parameter restrictions are extracted from the parameter description of each input parameter. Keywords corresponding to all input parameters are summarized to obtain keyword clusters.
[0119] S103: According to the test requirements, a test case generator matching the keyword cluster is searched from a test case generation library, and a corresponding test case is generated according to the test case generator matching the keyword cluster.
[0120] Different keyword clusters correspond to different test case generators. There can be multiple test case generators corresponding to a keyword cluster, and each test case generator can generate one or more test cases.
[0121] In the embodiment of the present invention, a test case generation library can be pre-built, and the test case generation library includes various test case generators. Various test case generators can be built according to the verification methods of different types of parameters. The construction method of the test case generator can be referred to Figure 2 The introduction of will not be elaborated here.
[0122] Different test requirements will result in different parameter verification methods, and the verification attributes can reflect the verification methods corresponding to the parameters. In practical applications, the verification attributes corresponding to the various keywords in the keyword cluster can be determined based on the test requirements. The various test case generators in the test case generation library contain the verification methods of the parameters. Therefore, based on the verification attributes corresponding to the various keywords, the test case generators matching the various keywords can be obtained from the test case generation library.
[0123] S104: Verify each keyword included in the keyword cluster using the test case to obtain a verification result.
[0124] There can be multiple test cases corresponding to different types of parameters, and automatic verification of such parameters can be achieved by running the test cases.
[0125] As can be seen from the above technical solution, the test requirements of the test scenario are obtained; the application programming interface of the test platform is traversed to extract the keyword clusters of the input parameters. According to the test requirements, the test case generator matching the keyword cluster is queried from the test case generation library. The test case generation library includes various test case generators, and various test case generators can be constructed according to the verification methods of different types of parameters. Since the test case generator contains the verification logic of the parameters, the test case generator matching the keyword cluster can generate the corresponding test case; the test case is used to automatically verify the keywords contained in the keyword cluster to obtain the verification result. The beneficial effect of the present invention is that by constructing the test case generator corresponding to various parameters, and linking with the test platform, the test case can be automatically generated in combination with the keyword driver, so as to complete the automatic verification test of the parameters. Compared with manually writing the verification logic, this solution reduces the work of user self-judgment and improves the test coverage and work efficiency. And different keyword clusters correspond to different test case generators. When the interface parameters of the test platform change, the test case of the parameter verification can also be automatically adjusted, which improves the flexibility of the automatic verification test.
[0126] Figure 2A flowchart of a method for constructing a test case generator provided by an embodiment of the present invention, the method comprising:
[0127] S201: Based on the verification attributes of different types of parameters, the verification logic corresponding to each type of parameter is determined.
[0128] Different validation attributes are used to represent different validation methods. Common validation attributes may include mandatory parameter validation, data length validation, parameter type validation, enumeration validation, etc. In practical applications, as validation requirements increase, validation attributes may be continuously updated and improved.
[0129] In the embodiment of the present invention, the manner of determining the verification logic of various types of parameters is similar, and an introduction is made by taking any one type of parameters among different types of parameters, namely, target parameters, as an example.
[0130] If the validation attributes of the target parameters include mandatory parameter validation, set the parameter legal value validation process.
[0131] The parameter legal value verification process may include setting the check interface to return a non-empty check when the target parameter has a required flag and the target parameter is passed empty, setting the check interface to return a successful check when the target parameter has a required flag and the target parameter is not empty; and setting the check interface to return a successful check when the target parameter does not have a required flag and the target parameter is passed empty.
[0132] When the verification attribute of the target parameter includes data length verification, the data length verification process is set according to the theoretical length of the data.
[0133] The data length verification process may include obtaining the data length of the target parameter, setting a check interface to return a successful verification when the data length of the target parameter matches its corresponding theoretical length, and executing a parameter legal value verification process when the data length of the target parameter does not match its corresponding theoretical length.
[0134] When the verification attribute of the target parameter includes parameter type verification, the parameter type verification process is set according to the data format of different parameter types.
[0135] Common parameter types (Pram_type) include integer (int), string (string), Boolean variable (Bool), enumeration value (Enum), etc.
[0136] The parameter type verification process may include identifying the current type of the parameter and determining whether the current type of the parameter is consistent with its theoretical type. If they are consistent, the parameter type verification is successful; if they are inconsistent, the parameter type is illegal.
[0137] In the case where the verification data of the target parameter includes enumeration verification, the enumeration verification process is set according to all enumeration values corresponding to the target parameter.
[0138] Enumeration check can be performed when the number of values of the target parameter is limited. For example, the "sort" parameter in the query interface can have values of "forward", "reverse", or "empty", so enumeration check can be performed on the sort parameter.
[0139] S202: Encapsulate the verification logic corresponding to each type of parameter into a test case generator.
[0140] By encapsulating the verification logic corresponding to each type of parameter into a test case generator, the test can be driven according to the verification logic contained in the test case generator.
[0141] S203: Establish a mapping relationship between various parameters and their corresponding test case generators.
[0142] To facilitate subsequent calls to the test case generator, various parameters can be mapped to the corresponding test case generator in sequence.
[0143] After the test case generator based on keyword cluster matching generates the corresponding test case, when it is detected that the target application programming interface of the test platform has changed, the target keyword of the target application programming interface input parameter can be re-extracted; according to the test case generator based on target keyword matching, the test case corresponding to the target application programming interface can be adjusted.
[0144] In the embodiment of the present invention, by constructing test case generators corresponding to various types of parameters, the required test case generator can be automatically adjusted when the interface parameters under development change, thereby providing support for adapting to the verification of different parameters.
[0145] After using test cases to verify each keyword included in the keyword cluster to obtain verification results, the keyword cluster and its corresponding test cases can be optimized based on the verification results of each test case and its corresponding expected results to obtain a test tool; the test tool is used to test the parameters to be verified to obtain parameter verification results.
[0146] In practical applications, the cause of the failure of the test case execution can be determined based on the deviation between the verification result of the target test case and the expected result; an optimization strategy matching the cause of the failure of the test case execution is obtained, and the keyword cluster and its corresponding test case are optimized according to the optimization strategy to obtain a test tool.
[0147] In order to improve the optimization speed of test cases, a strategy library can be built for the common reasons for test case execution failure, which contains the optimization methods corresponding to the reasons for various test case execution failures.
[0148] After determining the reason for the test case execution failure, it can be determined whether there is an optimization strategy matching the reason for the test case execution failure in a pre-established strategy library.
[0149] In the case where there is an optimization strategy matching the reason for the test case execution failure in the pre-established strategy library, the optimization strategy matching the reason for the test case execution failure can be obtained from the pre-established strategy library. In the case where there is no optimization strategy matching the reason for the test case execution failure in the pre-established strategy library, the reason for the test case execution failure can be displayed to the user terminal to obtain the optimization strategy fed back by the user terminal. The keyword cluster and its corresponding test case are optimized according to the optimization strategy to obtain a test tool.
[0150] By building a strategy library, we can quickly determine the optimization method that matches the reason for the test case execution failure, so as to automatically complete the optimization of the keyword cluster and its corresponding test case. When there is no optimization strategy that matches the reason for the test case execution failure in the strategy library, the optimization of the keyword cluster and its corresponding test case can be completed by using the optimization strategy with manual feedback, so as to obtain a test tool that is easy to directly call and use in the future.
[0151] Figure 3 A flowchart of a method for determining the cause of a test case execution failure provided by an embodiment of the present invention, the method comprising:
[0152] S301: When the verification result of the target test case is inconsistent with the expected result, it is determined that the test case execution fails.
[0153] The verification result may include the interface access result (status), the error code (error_code) returned by the interface, and the error message (error_message) returned by the interface. The interface access result may include access success and access failure.
[0154] S302: Determine whether the interface access result is consistent with the expected interface access result.
[0155] If the interface access result is inconsistent with the expected interface access result, S303 is executed; if the interface access result is inconsistent with the expected interface access result, S306 is executed.
[0156] S303: Determine whether the expected interface access result is successful access.
[0157] When the expected interface access result is access failure, it indicates that the reason for the test case execution failure is that parameter verification is not added, that is, S304 is executed when the expected interface access result is access failure.
[0158] When the expected interface access result is a successful access, it indicates that the reason for the failure of the test case execution is that more parameter verification is added, that is, when the expected interface access result is a successful access, S305 is executed.
[0159] S304: Determine that the reason for the failure of the test case execution is that parameter verification is not added.
[0160] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is an access failure, it is determined that the reason for the failure of the test case execution is that parameter verification is not added.
[0161] S305: Determine that the reason for the failure of the test case execution is that too many parameter checks are added.
[0162] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is successful access, it is determined that the reason for the failure of the test case execution is that more parameter checks are added.
[0163] S306: Determine whether the error code returned by the interface is consistent with the expected error code.
[0164] When the error code returned by the interface is inconsistent with the expected error code, it indicates that the reason for the failure of the test case execution is inaccurate parameter verification, that is, when the error code returned by the interface is inconsistent with the expected error code, S307 is executed.
[0165] When the error code returned by the interface is consistent with the expected error code, it can be further determined whether the error information returned by the interface is consistent with the expected error information, that is, S308 is executed.
[0166] S307: Determine that the reason for the failure of the test case execution is that the parameter verification accuracy does not meet the standard.
[0167] S308: Determine whether the error information returned by the interface is consistent with the expected error information.
[0168] When the error information returned by the interface is inconsistent with the expected error information, it indicates that the reason for the failure of the test case execution is incorrect prompt information, that is, when the error information returned by the interface is inconsistent with the expected error information, S309 is executed.
[0169] When the error information returned by the interface is inconsistent with the expected error information, the reason for the failure of the test case execution cannot be determined. At this time, manual intervention can be performed to determine the specific reason for the failure of the test case execution.
[0170] S309: Determine that the reason for the failure of the test case execution is incorrect prompt information.
[0171] The test tool is equivalent to a test model. The more detailed the division of the failure reasons during the optimization process of the test model, the more targeted the optimization of the model can be. By analyzing the reasons for the failure of the test case execution, the test tool can be optimized more targetedly, so that the test tool can quickly meet the accuracy of parameter verification. Among similar products on the market, the test tool trained by the embodiment of the present invention has wide coverage and high accuracy, which can effectively improve the competitiveness of the product.
[0172] In an embodiment of the present invention, in order to make the test tool more in line with current testing requirements, after using the test tool to test the parameters to be verified to obtain the parameter verification results, the test tool can be further optimized based on the deviation between the parameter verification results and the theoretical test results corresponding to the parameters to be verified, thereby obtaining an optimized test tool.
[0173] When new parameters to be verified that belong to the same test scenario as the parameters to be verified are obtained, the optimized test tool can be used to test the new parameters to be verified to obtain the parameter verification results corresponding to the new parameters to be verified. By analogy, for the same test scenario, each time a parameter to be verified is obtained, the test tool can be further optimized based on the deviation between the parameter verification result and the theoretical test result corresponding to the parameter to be verified, thereby continuously improving and optimizing the test tool, making the test tool more in line with current test requirements and improving the test accuracy of the test tool.
[0174] Figure 4 A schematic diagram of the structure of a parameter verification device provided by an embodiment of the present invention, comprising an acquisition unit 41, an extraction unit 42, a query unit 43, a generation unit 44 and a verification unit 45;
[0175] An acquisition unit 41 is used to acquire the test requirements of the test scenario;
[0176] An extraction unit 42, used for traversing the application programming interface of the test platform to extract the keyword clusters of the input parameters;
[0177] A query unit 43 is used to query a test case generator matching the keyword cluster from a test case generation library according to the test requirements, wherein the test case generation library includes various test case generators, and various test case generators are test case generators constructed according to verification methods of different types of parameters; different keyword clusters correspond to different test case generators;
[0178] A generating unit 44, configured to generate corresponding test cases according to the test case generator matched by the keyword cluster;
[0179] The verification unit 45 is used to verify each keyword included in the keyword cluster using a test case to obtain a verification result.
[0180] In some embodiments, for the construction of various types of test case generators in the test case generation library, the apparatus further includes a verification logic determination unit, a packaging unit, and a mapping unit;
[0181] A verification logic determination unit, used to determine the verification logic corresponding to each type of parameter based on the verification attributes of each type of parameter;
[0182] The encapsulation unit is used to encapsulate the verification logic corresponding to each type of parameter into a test case generator;
[0183] The mapping unit is used to establish a mapping relationship between various parameters and their corresponding test case generators.
[0184] In some embodiments, the verification logic determination unit includes a first setting subunit, a second setting subunit, a third setting subunit, and a fourth setting subunit; the first setting subunit is used to set a parameter legal value verification process when the verification attribute of the target parameter includes a required parameter verification; wherein the target parameter is any one of the different types of parameters;
[0185] A second setting subunit is used to set a data length check process according to a theoretical length of the data when the check attribute of the target parameter includes a data length check;
[0186] A third setting subunit is used to set a parameter type verification process according to data formats of different parameter types when the verification attribute of the target parameter includes parameter type verification;
[0187] The fourth setting subunit is used to set the enumeration verification process according to all enumeration values corresponding to the target parameter when the verification data of the target parameter includes enumeration verification.
[0188] In some embodiments, the first setting subunit is used to set the check interface to return a non-empty check when the target parameter has a required flag and the target parameter is empty, and to set the check interface to return a success check when the target parameter has a required flag and the target parameter is not empty;
[0189] Set the check interface to return a successful check when the target parameter does not have a required flag and the target parameter is passed empty.
[0190] In some embodiments, the second setting subunit is used to obtain the data length of the target parameter;
[0191] Set the check interface to return a successful check when the data length of the target parameter matches its corresponding theoretical length;
[0192] When the data length of the target parameter does not match its corresponding theoretical length, the parameter legal value verification process is executed.
[0193] In some embodiments, the extracting unit includes an acquiring subunit and a constructing subunit;
[0194] The acquisition subunit is used to traverse the application programming interface of the test platform to obtain all input parameters of the test platform;
[0195] The construction subunit is used to extract matching keywords from the parameter description corresponding to each input parameter according to the respective verification attributes of different types of parameters, so as to construct a keyword cluster.
[0196] In some embodiments, the query unit is used to determine the verification attributes corresponding to each type of keyword in the keyword cluster according to the test requirements of the test scenario; based on the verification attributes corresponding to each type of keyword, obtain a test case generator matching each type of keyword from the test case generation library.
[0197] In some embodiments, an optimization unit and a testing unit are also included;
[0198] An optimization unit, used to optimize the keyword cluster and its corresponding test case according to the verification result of each test case and its corresponding expected result, so as to obtain a test tool;
[0199] The test unit is used to test the parameters to be verified using a test tool to obtain parameter verification results.
[0200] In some embodiments, the optimization unit includes a cause determination subunit and a obtaining subunit;
[0201] The cause determination subunit is used to determine the cause of the test case execution failure based on the deviation between the verification result of the target test case and the expected result;
[0202] A subunit is obtained, which is used to obtain an optimization strategy that matches the reason for the failure of the test case execution, and optimize the keyword cluster and the corresponding test case according to the optimization strategy to obtain a test tool.
[0203] In some embodiments, the cause determination subunit is used to determine that the test case execution fails when the verification result of the target test case is inconsistent with the expected result; wherein the verification result includes the interface access result, the error code returned by the interface, and the error information returned by the interface;
[0204] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is an access failure, it is determined that the reason for the failure of the test case execution is that parameter verification is not added;
[0205] When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is successful access, it is determined that the reason for the failure of the test case execution is that more parameter verification is added;
[0206] When the error code returned by the interface is inconsistent with the expected error code, the reason for the failure of the test case execution is determined to be that the parameter verification accuracy does not meet the standard;
[0207] When the error message returned by the interface is inconsistent with the expected error message, it is determined that the reason for the failure of the test case execution is incorrect prompt information.
[0208] In some embodiments, the obtaining subunit is used to determine whether there is an optimization strategy matching the cause of the test case execution failure in the pre-established strategy library;
[0209] When there is an optimization strategy matching the cause of the test case execution failure in the pre-established strategy library, obtaining the optimization strategy matching the cause of the test case execution failure from the pre-established strategy library;
[0210] When there is no optimization strategy matching the reason for the test case execution failure in the pre-established strategy library, the reason for the test case execution failure is displayed to the user terminal to obtain the optimization strategy fed back by the user terminal;
[0211] The keyword clusters and their corresponding test cases are optimized according to the optimization strategy to obtain a test tool.
[0212] In some embodiments, an adjustment unit is also included;
[0213] The extraction unit is also used to re-extract the target keyword of the target application programming interface input parameter when detecting that the target application programming interface of the test platform has changed;
[0214] The adjustment unit is used to adjust the test cases corresponding to the target application programming interface according to the test case generator matched by the target keyword.
[0215] Figure 4 The description of the features in the corresponding embodiments can be found in Figure 1 The relevant descriptions of the corresponding embodiments will not be repeated here one by one.
[0216] As can be seen from the above technical solution, the test requirements of the test scenario are obtained; the application programming interface of the test platform is traversed to extract the keyword clusters of the input parameters. According to the test requirements, the test case generator matching the keyword cluster is queried from the test case generation library. The test case generation library includes various test case generators, and various test case generators can be constructed according to the verification methods of different types of parameters. Since the test case generator contains the verification logic of the parameters, the test case generator matching the keyword cluster can generate the corresponding test case; the test case is used to automatically verify the keywords contained in the keyword cluster to obtain the verification result. The beneficial effect of the present invention is that by constructing the test case generator corresponding to various parameters, and linking with the test platform, the test case can be automatically generated in combination with the keyword driver, so as to complete the automatic verification test of the parameters. Compared with manually writing the verification logic, this solution reduces the work of user self-judgment and improves the test coverage and work efficiency. And different keyword clusters correspond to different test case generators. When the interface parameters of the test platform change, the test case of the parameter verification can also be automatically adjusted, which improves the flexibility of the automatic verification test.
[0217] Figure 5 A structural diagram of a parameter verification device provided by an embodiment of the present invention, such as Figure 5 As shown, the parameter verification device includes: a memory 50 for storing a computer program;
[0218] The processor 51 is used to implement the steps of the parameter verification method in the above embodiment when executing a computer program.
[0219] The parameter verification device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.
[0220] Among them, the processor 51 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 51 may be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 51 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 51 may be integrated with a graphics processing unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 51 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.
[0221] The memory 50 may include one or more computer-readable storage media, which may be non-transitory. The memory 50 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 50 is at least used to store the following computer program 501, wherein, after the computer program is loaded and executed by the processor 51, the relevant steps of the parameter verification method disclosed in any of the aforementioned embodiments can be implemented. In addition, the resources stored in the memory 50 may also include an operating system 502 and data 503, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 502 may include Windows, Unix, Linux, etc. Data 503 may include but is not limited to a test case generation library, a keyword cluster, etc.
[0222] In some embodiments, the parameter verification device may further include a display screen 52 , an input / output interface 53 , a communication interface 54 , a power supply 55 , and a communication bus 56 .
[0223] Those skilled in the art will understand that Figure 5 The structure shown in the figure does not constitute a limitation on the parameter verification device, and may include more or fewer components than those shown in the figure.
[0224] It is understandable that if the parameter verification method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the current technology or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk and other media that can store program codes.
[0225] Based on this, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned parameter verification method are implemented.
[0226] An embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the above parameter verification method when executed by a processor.
[0227] The above is a detailed introduction to a parameter verification method, device, equipment, computer-readable storage medium and computer program product provided by an embodiment of the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0228] Professionals may further 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 the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may 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.
[0229] The above is a detailed introduction to a parameter verification method, device, equipment, computer-readable storage medium and computer program product provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the present invention.
Claims
1. A parameter verification method, characterized in that: include: Obtain test requirements for test scenarios; Traverse the testbed’s API to extract keyword clusters for input; According to the test requirements, a test case generator matching the keyword cluster is searched from a test case generation library, and a corresponding test case is generated according to the test case generator matching the keyword cluster; wherein the test case generation library includes various test case generators, and various test case generators are test case generators constructed according to verification methods of different types of parameters; different keyword clusters correspond to different test case generators; Using the test case to verify each keyword included in the keyword cluster to obtain a verification result; The traversal of the application programming interface of the test platform to extract the keyword clusters for input parameters includes: Traversing the application programming interface of the test platform to obtain all input parameters of the test platform; According to the validation attributes of different types of parameters, matching keywords are extracted from the parameter descriptions corresponding to each input parameter to build a keyword cluster. Querying a test case generator matching the keyword cluster from a test case generation library includes: Determine the verification attributes corresponding to each type of keyword in the keyword cluster according to the test requirements of the test scenario; Based on the verification attributes corresponding to each type of keyword, a test case generator matching each type of keyword is obtained from the test case generation library.
2. The parameter verification method according to claim 1, characterized in that: With respect to the construction of various test case generators in the test case generation library, the method further includes: Based on the verification attributes of different types of parameters, the verification logic corresponding to each type of parameter is determined; Encapsulate the verification logic corresponding to each type of parameter into a test case generator; Establish a mapping relationship between various parameters and their corresponding test case generators.
3. The parameter verification method according to claim 2, characterized in that: Based on the validation properties of different types of parameters, the validation logic corresponding to each type of parameter is determined to include: When the verification attribute of the target parameter includes mandatory parameter verification, a parameter legal value verification process is set; wherein the target parameter is any parameter of different types; When the verification attribute of the target parameter includes data length verification, the data length verification process is set according to the theoretical length of the data; When the verification attribute of the target parameter includes parameter type verification, the parameter type verification process is set according to the data format of different parameter types; In the case where the verification data of the target parameter includes enumeration verification, the enumeration verification process is set according to all enumeration values corresponding to the target parameter.
4. The parameter verification method according to claim 3, characterized in that: When the validation attributes of the target parameter include mandatory parameter validation, the process of setting the parameter legal value validation includes: When the target parameter has a required flag and the target parameter is empty, set the check interface to return a non-empty check; when the target parameter has a required flag and the target parameter is not empty, set the check interface to return a successful check; Set the check interface to return a successful check when the target parameter does not have a required flag and the target parameter is passed empty.
5. The parameter verification method according to claim 3, characterized in that: When the verification attribute of the target parameter includes data length verification, the data length verification process is set according to the theoretical length of the data, including: Get the data length of the target parameter; When the data length of the target parameter matches its corresponding theoretical length, a check interface is set to return a successful check; When the data length of the target parameter does not match its corresponding theoretical length, a parameter legal value verification process is executed.
6. The parameter verification method according to any one of claims 1 to 5, characterized in that: After verifying each keyword included in the keyword cluster by using the test case to obtain a verification result, the method further includes: According to the verification results of each test case and its corresponding expected results, the keyword cluster and its corresponding test case are optimized to obtain a test tool; The test tool is used to test the parameters to be verified to obtain parameter verification results.
7. The parameter verification method according to claim 6, characterized in that: According to the verification results of each test case and its corresponding expected result, the keyword cluster and its corresponding test case are optimized to obtain the test tool including: Determine the cause of the test case execution failure based on the deviation between the verification result of the target test case and the expected result; An optimization strategy matching the reason for the failure of the test case execution is obtained, and the keyword cluster and the corresponding test case are optimized according to the optimization strategy to obtain a test tool.
8. The parameter verification method according to claim 7, characterized in that: According to the deviation between the verification result of the target test case and the expected result, the reasons for the failure of the test case execution are determined to include: When the verification result of the target test case is inconsistent with the expected result, it is determined that the test case execution fails; wherein the verification result includes the interface access result, the error code returned by the interface, and the error information returned by the interface; When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is an access failure, it is determined that the reason for the failure of the test case execution is that parameter verification is not added; When the interface access result is inconsistent with the expected interface access result, and the expected interface access result is successful access, it is determined that the reason for the failure of the test case execution is that more parameter verification is added; When the error code returned by the interface is inconsistent with the expected error code, the reason for the failure of the test case execution is determined to be that the parameter verification accuracy does not meet the standard; When the error message returned by the interface is inconsistent with the expected error message, it is determined that the reason for the failure of the test case execution is incorrect prompt information.
9. The parameter verification method according to claim 7, characterized in that: Obtaining an optimization strategy that matches the reason for the test case execution failure, optimizing the keyword cluster and the corresponding test case to obtain a test tool including: Determine whether there is an optimization strategy matching the cause of the test case execution failure in the pre-established strategy library; In the case where there is an optimization strategy matching the cause of the test case execution failure in the pre-established strategy library, obtaining the optimization strategy matching the cause of the test case execution failure from the pre-established strategy library; In the case where there is no optimization strategy matching the reason for the failure of the test case execution in the pre-established strategy library, the reason for the failure of the test case execution is displayed to the user terminal to obtain the optimization strategy fed back by the user terminal; The keyword cluster and its corresponding test cases are optimized according to the optimization strategy to obtain a test tool.
10. The parameter verification method according to claim 1, characterized in that: After searching a test case generator matching the keyword cluster from a test case generation library according to the test requirement, and generating a corresponding test case according to the test case generator matching the keyword cluster, the method further includes: When a change is detected in the target application programming interface of the test platform, re-extracting the target keyword of the target application programming interface input parameter; According to the test case generator matched with the target keyword, the test case corresponding to the target application programming interface is adjusted.
11. A parameter verification device, characterized in that: It includes an acquisition unit, an extraction unit, a query unit, a generation unit and a verification unit; The acquisition unit is used to acquire the test requirements of the test scenario; The extraction unit is used to traverse the application programming interface of the test platform to extract the keyword clusters for input; The query unit is used to query the test case generator matching the keyword cluster from the test case generation library according to the test requirements; wherein the test case generation library includes various test case generators, and the various test case generators are test case generators constructed according to the verification methods of different types of parameters; different keyword clusters correspond to different test case generators; The generating unit is used to generate corresponding test cases according to the test case generator matched by the keyword cluster; The verification unit is used to verify each keyword included in the keyword cluster using the test case to obtain a verification result; The extraction unit includes an acquisition subunit and a construction subunit; The acquisition subunit is used to traverse the application programming interface of the test platform to obtain all input parameters of the test platform; The construction subunit is used to extract matching keywords from the parameter descriptions corresponding to each input parameter according to the respective verification attributes of different types of parameters, so as to construct a keyword cluster; The query unit is used to determine the verification attributes corresponding to each type of keyword in the keyword cluster according to the test requirements of the test scenario; based on the verification attributes corresponding to each type of keyword, obtain the test case generator matching each type of keyword from the test case generation library.
12. A parameter verification device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the parameter verification method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the parameter verification method according to any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
A product data automatic verification platform and a method based on a data verification template
CN109408381A
Interface test case generation method and device based on Bayesian classification algorithm
CN115934571A