API-based test case generation method and device, equipment and storage medium
By building API interface features and data generation models, and generating test case templates and data, the problem of incomplete and high cost of automated test case generation in complex scenarios is solved, data-driven multi-interface regression testing is realized, and the test cycle is shortened and Reduced costs.
Patent Information
- Application Number
- CN202411295653.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2024-12-27
AI Technical Summary
Existing automated generation test case technology may not be comprehensive or biased when facing complex business logic and changing user behavior, and the development and maintenance costs are high, making it difficult to apply to rapidly changing needs, and requires a high technical background and Skill requirements.
By collecting API data sets, extracting API interface features, building template generation models and data generation models, generating test case templates and data, and using intelligent algorithms to optimize data generation, it is suitable for regression testing with multiple interfaces, simplifying the test case generation process.
It realizes data-driven testing, which is suitable for multi-interface regression testing, shortens the test cycle, reduces costs, simplifies the test case generation process, and improves test efficiency and accuracy.
Smart Images

Figure CN119201722A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an API-based test case generation method, device, equipment and storage medium. Background Art
[0002] Automated test case generation is crucial in the field of software testing. It improves test efficiency, reduces human errors, and ensures test accuracy and repeatability by reducing the time spent on manually writing test cases. This approach supports continuous integration and rapid iterative development, allowing the test team to respond to changes in requirements, maintain, and update test cases in a timely manner. Automated test cases also enhance regression testing capabilities, improve software quality, and allow testers to devote their energy to more valuable test design and strategy planning. In addition, it helps to achieve resource optimization, reduce costs, and improve the workflow of the entire test team. Especially when dealing with large amounts of data and complex test scenarios, automated testing demonstrates its indispensable value.
[0003] However, in actual applications, since the automated test case generation technology often requires a detailed model or a large amount of training data as a basis, it may take a lot of time and resources to prepare. Secondly, the automatically generated test cases may not be comprehensive or biased, especially when faced with complex business logic and changing user behavior. In addition, automated testing may find it difficult to capture defects that need to be discovered based on context or specific scenarios. In addition, the development and maintenance of automated testing tools also require certain costs, including the license fees for purchasing tools, the time to develop and maintain automated scripts, and the continuous technical updates and support that may be required. Finally, automated testing may bring high initial setup costs, and the difficulty and cost of maintaining automated test scripts may increase with rapidly changing requirements. The implementation of automated testing also requires testers to have a certain technical background, such as programming skills and understanding of automated tools, which may pose a higher challenge to the team's skill requirements.
[0004] Therefore, how to implement data-driven testing and apply it to regression testing with more interfaces, simplify the process of test case generation, reduce the time of test case generation, thereby shortening the test cycle and reducing costs, is the focus of current research. Summary of the invention
[0005] The main technical problem solved by the present invention is to provide an API-based test case generation method, device, equipment and storage medium to solve the problem of how to implement data-driven testing, and is suitable for regression testing with a large number of interfaces, simplifying the test case generation process, reducing the test case generation time, thereby shortening the test cycle and reducing costs.
[0006] In order to solve the above technical problems, a technical solution adopted by the present invention is to provide a test case generation method, device, equipment and storage medium based on API, wherein the method comprises:
[0007] Collect API data sets and extract the features of API interfaces based on the API data sets; build a template generation model, which generates test case templates based on the features of API interfaces; build a data generation model, which generates test case data based on the test case templates.
[0008] In some embodiments, a template generation model is constructed by: extracting information of an API interface and analyzing parameters of the API interface; designing a structure of a test case based on the information and parameters of the API interface; generating a template of a test case based on the structure of the test case; and associating the template of the test case with a test scenario.
[0009] In some embodiments, a data generation model is constructed by: analyzing the data requirements of each parameter according to the parameters of the test case template; formulating a data generation strategy according to the data requirements of each parameter; selecting an intelligent algorithm according to the data generation strategy, and performing intelligent algorithm fusion; and generating test case data according to the fused intelligent algorithm and data generation strategy.
[0010] In some embodiments, the method further includes: calculating a comprehensive index of the API interface, the comprehensive index is used to evaluate the execution effect of the test case, and the calculation method is:
[0011]
[0012] Where m represents the number of test cases generated by the i-th API interface, y'(j) represents the actual execution effect of the j-th test case, y(j) represents the expected execution effect of the j-th test case, and cos represents the similarity between y'(j) and y(j).
[0013] In some embodiments, the method further includes: calculating a model index y of the data generation model 1 And the data efficiency k 1 , the calculation methods are:
[0014]
[0015] k 1 =c / n;
[0016] Among them, y(i) represents the comprehensive index of the i-th API interface, a(i) represents the weight corresponding to the i-th API interface, c represents the effective number of test cases, and n represents the total number of test cases.
[0017] In some embodiments, the method further includes: optimizing the parameters of the data generation model by:
[0018] If the model index exceeds the first threshold and the data efficiency exceeds the second threshold, there is no need to optimize the parameters of the data generation model.
[0019] Otherwise, adjust the parameters of the data generation model, reconstruct the data generation model, and calculate the model index and data efficiency of the data generation model until the model index of the data generation model exceeds the first threshold and the data efficiency exceeds the second threshold.
[0020] To solve the above technical problems, the present application also provides an API-based test case generation device, comprising:
[0021] The collection and extraction module is used to collect API data sets and extract API interface features based on the API data sets.
[0022] The template generation module is used to build a template generation model, which generates a template for a test case based on the characteristics of the API interface.
[0023] The data generation module is used to build a data generation model, and the data generation model generates test case data according to the test case template.
[0024] In some embodiments, the above-mentioned device also includes: an optimization module, which is used to optimize the parameters of the data generation model.
[0025] To solve the above technical problems, the present application also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and when the computer program is executed by the processor, it implements any one of the above API-based test case generation methods.
[0026] In order to solve the above technical problems, the present application also provides a computer-readable storage medium on which a computer program is stored, and the computer program is used to implement any of the above-mentioned API-based test case generation methods.
[0027] Beneficial effects: The present application discloses a method, device, equipment and storage medium for generating test cases based on an API, wherein the method includes: collecting an API data set, and extracting features of an API interface according to the API data set; constructing a template generation model, wherein the template generation model generates a template for a test case according to the features of the API interface; and constructing a data generation model, wherein the data generation model generates data for the test case according to the template for the test case. The method of the present application can realize data-driven testing, and is suitable for regression testing with a large number of interfaces, which simplifies the process of generating test cases, reduces the time for generating test cases, thereby shortening the test cycle and reducing costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A flowchart of an embodiment of an API-based test case generation method of the present application is given;
[0029] Figure 2 A flowchart of another embodiment of a test case generation method based on an API of the present application is provided;
[0030] Figure 3 A structural schematic diagram of an embodiment of an API-based test case generation device of the present application is provided;
[0031] Figure 4 A structural schematic diagram of another embodiment of an API-based test case generation device of the present application is provided;
[0032] Figure 5 A schematic diagram of the framework of an electronic device of the present application is provided;
[0033] Figure 6 A schematic diagram of a computer-readable storage medium according to an embodiment of the present application is provided. DETAILED DESCRIPTION
[0034] In order to facilitate the understanding of the present invention, the present invention is described in more detail below in conjunction with the accompanying drawings and specific embodiments. Preferred embodiments of the present invention are provided in the accompanying drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described in this specification. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive.
[0035] It should be noted that, unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used in this specification includes any and all combinations of one or more related listed items.
[0036] It should be noted that the "test case" referred to in this application refers to the description of the test task for a specific software product, reflecting the test plan, method, technology and strategy. A test case is a set of test inputs, execution conditions and expected results compiled for a specific goal in order to test a program path or verify whether a specific requirement is met, including test environment, operation steps, test data, expected results and other elements.
[0037] The API (Application Programming Interface) referred to in this application is a software intermediary and an important part of modern software development. The API allows two applications to communicate with each other. The API defines how applications interact with each other, allowing developers to use existing functions or services without having to understand the underlying implementation details.
[0038] Figure 1 A flowchart of an embodiment of an API-based test case generation method of the present application is shown, comprising the steps of:
[0039] Step S1, collecting API data sets, and extracting features of API interfaces according to the API data sets.
[0040] Step S2, constructing a template generation model, the template generation model generates a template of a test case according to the characteristics of the API interface.
[0041] Step S3, constructing a data generation model, the data generation model generates test case data according to the test case template.
[0042] In the method of the present application, the API data set includes various business requirements and function description data, and also includes design documents. The template generation model in the present application generates templates for different test cases according to different API interfaces; the data generation model further generates test case data for the generated templates. Therefore, the method of the present application can implement data-driven testing, and is suitable for regression testing with more API interfaces, which simplifies the test case generation process and reduces the time for test case generation, thereby shortening the test cycle and reducing costs.
[0043] Specifically, in step S1, an API data set is collected, and features of the API interface are extracted according to the API data set, which also includes: preprocessing the API data set, and the preprocessing includes: analyzing the purpose, input parameters, expected output, and possible abnormal situations of the API interface according to the API data set. Further, a parsing tool can be used to parse the design documents in the API data set to extract features of the API interface, and the extracted features include request methods, paths, parameters, request bodies, and response body structures.
[0044] Exemplarily, the parsing tool can be an OpenAPI specification or a Swagger specification. Among them, the OpenAPI specification (OAS) defines a standard, language-independent interface that allows humans and computers to discover and understand the ability of services without accessing source code, documents, or inspecting network traffic. The Swagger specification is a standardized and complete framework for generating, describing, calling, and visualizing interface documents for RESTful Web services. It supports multiple languages and can automatically generate relevant documents after the interface is defined, reducing the workload of manually writing and maintaining API documents. RESTful Web service is a Web service designed based on the REST (Reoresentatona state Trense) architectural principles. REST is a software architectural style that is commonly used to build distributed network applications and services. RESTful Web services operate on resources using various methods of the HTTP protocol (GET, POST, PUT, DELETE, etc.) to provide simple, lightweight, extensible and scalable services.
[0045] Specifically, more key features can be extracted from the definition of the API interface, such as parameter type, optional and / or required attributes, data format, data value range, dimension, etc., and feature extraction can be performed by combining parsing tools with manual extraction. For situations where the API interface is relatively important or sensitive, manual extraction can be used to extract relevant features such as the business significance and design specifications of the API interface; for situations where the API interface has too many parameters, a general confidentiality level, and a large number of interfaces, general tools or small tools based on pattern matching can be used to extract features.
[0046] In some embodiments, a template generation model is constructed by: extracting information of an API interface and analyzing parameters of the API interface; designing a structure of a test case based on the information and parameters of the API interface; generating a template of a test case based on the structure of the test case; and associating the template of the test case with a test scenario.
[0047] Specifically, to extract API interface information, you can also use parsing tools to parse API documents to extract detailed information about the API interface, including request methods, paths, parameters, request body and response body structures, etc. Exemplarily, the parsing tool can be the OpenAPI specification, the Swagger specification, or WSDL, etc., where WSDL (Web Services Description Language) is a public interface that describes Web services. This is an XML-based service description on how to communicate and use Web services; that is, it describes the protocols and information formats that need to be bound when interacting with Web services listed in the directory. WSDL usually uses an abstract language to describe the operations and information supported by the service, and then binds the actual network protocol and information format to the service when used.
[0048] Specifically, the parameters of the API interface are analyzed, including: parameter identification, identifying the type of all parameters in the API interface, whether they are required, default values, and enumeration values; parameter classification, analyzing the types of parameters in the API interface, such as: digital type, text type, image type, non-text file type, streaming media type, etc.; special type processing, for parameters of types such as images, non-text file types, streaming media, etc., set their respective default values and generalization ranges. For example, for parameters of the image type, you can set a default image, and set the upper and lower limit values of the image grayscale, depth, etc., so that the subsequently generated data varies within the range of the upper and lower limit values.
[0049] Specifically, according to the information and parameters of the API interface, the structure of the test case is designed, including the structure of the request part and the response part. For the request part, the structure of the data format, parameter sequence, and verification rules can be designed according to the requirements of the API interface.
[0050] Specifically, data generation tools and technologies can be used to generate test case templates according to the structure of the test cases. Exemplarily, the data generation tools can be Hazy, K2View, Datomize, Faker, Mockaroo, DataFactory, Jenerators, GPT, etc., and the data generation technologies can be variational autoencoders (VAEs), generative adversarial networks (GANs), etc.
[0051] Specifically, the template of the above test case should contain all necessary parameters and structures to facilitate the generation of data for subsequent test cases. Specifically, a test case usually includes the following parts: (1) Test case ID: a number or name used to uniquely identify each test case; (2) Test case title: contains a brief description of the test case, explaining the purpose of the test; (3) Related requirements: the business requirements or functional points corresponding to the test case; (4) Preconditions: conditions that must be met before executing the test case, such as specific configurations, data status, etc.; (5) Test steps: detailed operation steps, including input data and operations performed; (6) Expected results: expected system behavior or output after executing the test steps; (7) Actual results: the actual performance of the system after executing the test steps, used to compare with the expected results; (8) Test status: identifies the execution status of the test case, such as "passed", "failed", "blocked", etc.; (9) Test data: input data required for test case execution; (10) Priority: assign priority based on the importance of the test case and risk assessment; (11) Execution frequency: indicates the frequency with which the test case should be executed during the test cycle; (12) Notes: used for any additional information or special instructions.
[0052] Specifically, the test case template is associated with the test scenario, including:
[0053] The first step is to analyze the API interface scenario, including the complexity of the API interface, the scope of interaction, etc.
[0054] The second step is to design test scenarios based on the analysis results of the API interface scenarios. For example, for the system survival detection interface, only the normal and abnormal processes need to be designed, and there is no need to design special scenarios such as performance and pressure. For the system unified entry interface, in addition to setting the necessary normal and abnormal scenarios, it is also necessary to set up test scenarios such as concurrency, performance, and pressure.
[0055] The third step is to associate test scenarios. Specifically, the test case template is associated with different test scenarios, such as normal process, abnormal process, performance test, etc.
[0056] To further explain, the template generation model can generate different combination templates for the scenario type and parameter type of each test case. The template is a combination of the usage scenario of the current API interface and the number, category, special requirements, etc. of parameters. An API interface may form multiple templates. When filling in the test case data later, multiple forms of data will be filled in for each template. Only test cases generated by multiple combinations can be used for testing tasks.
[0057] In some embodiments, a data generation model is constructed by: analyzing the data requirements of each parameter according to the parameters of the test case template; formulating a data generation strategy according to the data requirements of each parameter; selecting an intelligent algorithm according to the data generation strategy, and performing intelligent algorithm fusion; and generating test case data according to the fused intelligent algorithm and data generation strategy.
[0058] Specifically, according to the parameters of the test case template, the data requirements of each parameter are analyzed, and the data requirements include: data type, range, format, etc.
[0059] Specifically, a data generation strategy is formulated according to the data requirements of each parameter, each data generation strategy is adapted to the parameter, and the data generation strategy includes but is not limited to the valid value of the data, the boundary value of the data, the abnormal value of the data, etc.
[0060] Specifically, intelligent algorithms are selected according to data generation strategies. Intelligent algorithms are used in the test case generation process mainly because intelligent algorithms can simulate human intelligence, handle complex tasks, optimize decision-making processes, and improve the quality and coverage of test cases. Appropriate intelligent algorithms can be selected according to data generation strategies, such as decision trees, genetic algorithms, neural networks, and other intelligent algorithms.
[0061] Specifically, when generating test case data, it is necessary to consider multiple objectives (such as test coverage, test execution time, defect discovery rate, etc.) at the same time. A multi-objective optimization algorithm (such as a multi-objective genetic algorithm) can be used to balance these objectives and generate test data that comprehensively considers multiple factors. A variety of intelligent algorithms can be integrated to obtain a multi-objective optimization algorithm. For example, the two intelligent algorithms of decision tree and neural network can be integrated to generate the final test data. There are many ways to integrate intelligent algorithms. For example, they can be integrated by stacked generalization, model voting, etc. Among them, stacked generalization (sometimes also called Stacking) refers to training a model for combining other models, that is, first training multiple different models, and then training a model with the output of each previously trained model as input to obtain a final output. Model voting is an integrated learning model that follows the principle of minority obeys majority. It reduces variance by integrating multiple models, thereby improving the robustness and generalization ability of the model.
[0062] Specifically, the data of the test case is generated according to the integrated intelligent algorithm and data generation strategy. Since the present application integrates multiple intelligent algorithms for use, the data generation model can be continuously adjusted and improved during use to obtain better test results.
[0063] The template generation model and data generation model in this application are constructed according to the data architecture and the data itself respectively, so they have the characteristics of high cohesion, low coupling, data-driven, strong migration and generalization capabilities, high efficiency, accuracy, convenience, reliability, and flexibility.
[0064] In some embodiments, in order to evaluate the performance of the test case generation method, it also includes: constructing evaluation indicators according to the parameter characteristics of each API interface. The evaluation indicators include comprehensive indicators of the API interface and overall evaluation indicators, and the overall evaluation indicators include model indicators and data efficiency of the data generation model.
[0065] Specifically, generally, an API interface has many templates, and one template may generate multiple test cases. When evaluating the performance of the test case generation method, all test cases can be executed for a certain API interface, and the test results can be counted and calculated, that is, the comprehensive index of the current API interface can be obtained.
[0066] In some embodiments, the method further includes: calculating a comprehensive index of the API interface, the comprehensive index is used to evaluate the execution effect of the test case, and the calculation method is:
[0067]
[0068] Where m represents the number of test cases generated by the i-th API interface, y'(j) represents the actual execution effect of the j-th test case, y(j) represents the expected execution effect of the j-th test case, and cos represents the similarity between y'(j) and y(j).
[0069] In some embodiments, the method further includes: calculating a model index y of the data generation model 1 And the data efficiency k 1 , the calculation methods are:
[0070]
[0071] k 1 =c / n;
[0072] Among them, y(i) represents the comprehensive index of the i-th API interface, a(i) represents the weight corresponding to the i-th API interface, c represents the effective number of test cases, and n represents the total number of test cases.
[0073] Specifically, a(i) can be set in advance, and the weight a(i) corresponding to the i-th API interface can be adjusted to adjust the parameters of the data generation model.
[0074] In some embodiments, the method further includes: optimizing the parameters of the data generation model by:
[0075] If the model index exceeds the first threshold and the data efficiency exceeds the second threshold, that is, y 1 >y 0 And k 1 >k 0 , then there is no need to optimize the parameters of the data generation model. 0 represents the first threshold, k 0 Indicates the second threshold.
[0076] Otherwise, adjust the parameters of the data generation model, reconstruct the data generation model, and calculate the model index and data efficiency of the data generation model until the model index of the data generation model exceeds the first threshold and the data efficiency exceeds the second threshold.
[0077] Specifically, the first threshold and the second threshold may be set when initializing the data to generate the model parameters.
[0078] Specifically, the generated test cases can be executed in the actual test environment and the execution results can be recorded. The execution results include whether the API interface call is successful, whether an exception occurs, whether all possible execution paths are covered, whether all boundaries are tested, etc. Further, the model indicators and data efficiency of the data generation model are calculated; for the i-th API interface, if its comprehensive indicator y(i) is greater than the interface threshold c(i) of the current API interface, that is, y(i)>c(i), then it means that the current test case is valid; otherwise, it means that the current test case is invalid. Further, the model indicators and data efficiency of the data generation model are calculated. If the model indicators exceed the first threshold and the data efficiency exceeds the second threshold, that is, y 1 >y 0 And k 1 >k 0 , it is considered that the current data generation model can meet the requirements and there is no need to optimize the parameters of the data generation model; otherwise, the parameters of the data generation model are adjusted, the data generation model is rebuilt, and the model indicators and data efficiency of the model are regenerated until the data generation model meets the requirements, that is, the model indicators exceed the first threshold and the data efficiency exceeds the second threshold.
[0079] In some embodiments, when the template generation model and data generation model constructed for the current API data set are completed and meet the requirements (i.e., pass the evaluation indicators), in order to make the API-based test case generation method of the present application have stronger versatility and generalization capabilities, as well as a broader usage scenario, the method of the present application can be further improved. The improved method includes: establishing an API data set similarity detection mechanism, establishing a credibility mechanism, and standardizing the API data set and the generated test cases.
[0080] Specifically, an API data set similarity detection mechanism is established. The API interface feature set in the current API data set is used as the basis, and the similarity is compared with the API interface feature set in subsequent use. If the similarity is higher than the similarity threshold, the method is used directly. Otherwise, some special API interfaces are eliminated before using the current method.
[0081] Specifically, a credibility mechanism is established. In the process of using this method, the comprehensive index of each API interface is calculated according to the evaluation index of the API interface, and the comprehensive index of all API interfaces is calculated comprehensively (the comprehensive calculation can be performed using a weighted form or expert scoring, etc.). After normalizing the above results, the overall credibility of the test cases generated in this business scenario can be obtained.
[0082] Specifically, the API data set and the generated test cases are standardized. The API data set includes the format requirements of the data set, the maximum proportion of abnormal data, the maximum response time of the interface, etc. The generated test cases are all test case sets generated for the API data set.
[0083] To further illustrate the method of this application, Figure 2 A flowchart of another embodiment of a method for generating a test case based on an API is provided, comprising the steps of:
[0084] Step S21, collect API data sets; step S22, preprocess API data sets, which is equivalent to "preprocessing API data sets" mentioned above; step S23, interface feature extraction, which is equivalent to "extracting features of API interface according to API data sets" mentioned above; step S24, constructing a template generation model; step S25, constructing a data generation model; step S26, constructing an evaluation function; step S27, optimizing parameters, which is equivalent to "optimizing parameters of data generation model" mentioned above.
[0085] Among them, step S24, constructing a template generation model, includes the following sub-steps: step S241, extracting API interface information; step S242, parameter analysis (equivalent to the above "analyzing the parameters of the API interface"); step S243, use case structure design (equivalent to the above "designing the structure of the test case according to the information and parameters of the API interface"); step S244, use case template generation (equivalent to the above "generating a test case template according to the structure of the test case"); step S245, scenario association (equivalent to the above "associating the test case template with the test scenario"); step S246, construction of the template generation model.
[0086] Among them, step S25, building a data generation model, includes the following sub-steps: step S251, analyzing the data requirements of parameters (equivalent to "analyzing the data requirements of each parameter according to the parameters of the test case template" above); step S252, formulating a data generation strategy (equivalent to "formulating a data generation strategy according to the data requirements of each parameter" above); step S253, selecting an intelligent algorithm (equivalent to "selecting an intelligent algorithm according to the data generation strategy" above); step S254, intelligent algorithm fusion; step S255, building a data generation model.
[0087] For the specific contents of the above steps, please refer to the above text and will not be repeated here.
[0088] Combination Figure 3 The present application also provides an API-based test case generation device, including: a collection and extraction module 41, which is used to collect API data sets and extract API interface features according to the API data sets.
[0089] The template generation module 42 is used to construct a template generation model, and the template generation model generates a template of a test case according to the API interface characteristics.
[0090] The data generation module 43 is used to construct a data generation model, and the data generation model generates test case data according to the test case template.
[0091] In some embodiments, in combination Figure 4 The above device also includes: an optimization module 44, which is used to optimize the parameters of the data generation model.
[0092] The other technical features of the above-mentioned API-based test case generation device are the same as the features disclosed in the above-mentioned embodiment method, and will not be repeated here.
[0093] Combination Figure 5 The present application also provides an electronic device, including a processor 52 and a memory 51, wherein the memory 51 stores a computer program that can be executed by the processor, and when the computer program is executed by the processor 52, any one of the above-mentioned API-based test case generation methods is implemented.
[0094] Specifically, the memory 51 is used to store computer programs or data. The memory 51 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.
[0095] The processor 52 is used to read / write data or computer programs stored in the memory 51 and execute corresponding functions. For example, when the computer program stored in the memory 51 is executed by the processor 52, the API-based test case generation method provided in the embodiment of the present application can be implemented.
[0096] Combination Figure 6 The present application also provides a computer-readable storage medium on which program instructions 601 are stored, and the program instructions 601 are used to implement any of the above-mentioned API-based test case generation methods.
[0097] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation thereof can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0098] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0099] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0100] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0101] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0102] In summary, the present application discloses a method, device, equipment and storage medium for generating test cases based on an API, wherein the method includes: collecting an API data set, and extracting features of an API interface according to the API data set; constructing a template generation model, wherein the template generation model generates a template for a test case according to the features of the API interface; and constructing a data generation model, wherein the data generation model generates data for the test case according to the template for the test case. The method of the present application can realize data-driven testing, and is suitable for regression testing with a large number of interfaces, which simplifies the process of test case generation, reduces the time for test case generation, thereby shortening the test cycle and reducing costs.
[0103] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structural transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A test case generation method based on API, characterized in that: include: Collecting an API data set, and extracting features of the API interface according to the API data set; Constructing a template generation model, wherein the template generation model generates a template of a test case according to the characteristics of the API interface; A data generation model is constructed, wherein the data generation model generates data of the test case according to the template of the test case.
2. The API-based test case generation method according to claim 1, characterized in that: The construction template generates a model by: Extracting information of the API interface and analyzing parameters of the API interface; Design the structure of the test case according to the information and parameters of the API interface; Generate a test case template according to the structure of the test case; The template of the test case is associated with a test scenario.
3. The API-based test case generation method according to claim 1, characterized in that: The method for constructing the data generation model is as follows: According to the parameters of the template of the test case, analyzing the data requirements of each parameter; Formulate data generation strategies based on the data requirements for each of the parameters; Selecting an intelligent algorithm according to the data generation strategy and performing intelligent algorithm fusion; Generate test case data based on the integrated intelligent algorithm and the data generation strategy.
4. The API-based test case generation method according to claim 1, characterized in that: Also includes: Calculate the comprehensive index of the API interface, which is used to evaluate the execution effect of the test case. The calculation method is: Where m represents the number of test cases generated by the i-th API interface, y'(j) represents the actual execution effect of the j-th test case, y(j) represents the expected execution effect of the j-th test case, and cos represents the similarity between y'(j) and y(j).
5. The API-based test case generation method according to claim 4, characterized in that: Also includes: The model index y1 and the data efficiency k1 of the data generation model are calculated by: k1=c / n; Among them, y(i) represents the comprehensive index of the i-th API interface, a(i) represents the weight corresponding to the i-th API interface, c represents the effective number of test cases, and n represents the total number of test cases.
6. The API-based test case generation method according to claim 5, characterized in that: Also includes: Optimizing the parameters of the data generation model by: If the model index exceeds the first threshold and the data efficiency exceeds the second threshold, there is no need to optimize the parameters of the data generation model; Otherwise, adjust the parameters of the data generation model, reconstruct the data generation model, and calculate the model index and data efficiency of the data generation model until the model index of the data generation model exceeds a first threshold and the data efficiency exceeds a second threshold.
7. A test case generation device based on API, characterized in that: include: A collection and extraction module, used to collect API data sets and extract API interface features based on the API data sets; A template generation module, used to construct a template generation model, wherein the template generation model generates a template of a test case according to the API interface features; The data generation module is used to construct a data generation model, and the data generation model generates test case data according to the test case template.
8. The API-based test case generation device according to claim 7, characterized in that: Also includes: An optimization module is used to optimize the parameters of the data generation model.
9. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and when the computer program is executed by the processor, the API-based test case generation method according to any one of claims 1 to 6 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is used to implement the API-based test case generation method described in any one of claims 1 to 6.