Interface test method and device for generating test case based on interface description document

Through automatic collection and analysis of interface description documents, interface models and parameter models are generated, and test cases are automatically generated and executed, the problems of low efficiency and insufficient coverage in the existing interface testing process are solved, and the highly automated and efficient coverage of interface testing is achieved.

CN120029891APending Publication Date: 2025-05-23RICHFIT INFORMATION TECH +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202311520884.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-15
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

The existing interface testing process relies on manual design, analysis and execution use cases, is inefficient and has insufficient testing coverage.

Method used

Through the automatic collection and analysis of interface description documents, interface models and parameter models are generated, and general, boundary and exception use cases are automatically generated based on these models, parameter values ​​and assertion rules are set, and the use case library is stored to realize batch automatic execution of use cases and automatic generation of test reports.

Benefits of technology

It improves the timeliness and efficiency of test cases generation, maximizes the coverage of test scenarios with various parameter combinations, reduces manual repetitive design work, reduces test costs and error rates, and realizes a high degree of automation of the entire interface test process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120029891A_ABST
    Figure CN120029891A_ABST
Patent Text Reader

Abstract

The invention discloses an interface test method and device for generating a test case based on an interface description document. The method comprises the following steps: generating an interface model and a parameter model according to an obtained interface description document; generating a plurality of test cases based on the interface model and the parameter model, and setting a parameter value of each test case; according to the interface model and the parameter model, generating a test step for each test case, and setting an expected result and an assertion rule; all the test cases and the corresponding interface models and parameter models are stored in a case library; and obtaining a test report based on all the test cases and the case library. According to the method, the interface description document is automatically collected and analyzed, the test case is generated and executed to obtain the test report, high automation of the whole interface test process is achieved, and the test frequency and quality are greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer software testing, and in particular to an interface testing method and device for generating test cases based on an interface description document. Background Art

[0002] The interface testing method provides testers with a friendly and efficient testing process. The interface testing method can adapt to multiple projects more quickly and improve testing efficiency. The interface testing method usually involves interface information collection, test case writing, test case execution, and test report generation.

[0003] In the current mainstream interface testing process, testers need to manually analyze the interface description document, understand interface-related information such as input parameters, output parameters and business logic, and then design test plans and a large number of test cases. They import interfaces or write interface information for storage, manually write various parameters and assertions in interface test cases, and manually execute and verify the results. The interface testing method has the configuration required to complete the interface test to meet the work needs of testers. Testers go to the interface testing platform based on the configuration information, detailed interface content, test case parameter design and assertion conditions, and execute the test suite according to the test task management organization, and finally generate a test report. Summary of the invention

[0004] In order to achieve more efficient and accurate interface testing, an embodiment of the present invention provides an interface testing method and device for generating test cases based on an interface description document.

[0005] In a first aspect, an embodiment of the present invention provides an interface testing method for generating test cases based on an interface description document, the method comprising:

[0006] Generate interface model and parameter model according to the obtained interface description document;

[0007] Generate multiple test cases based on the interface model and the parameter model, and set the parameter value of each test case;

[0008] Generate test steps, set expected results and assertion rules for each test case according to the interface model and the parameter model;

[0009] Storing all the test cases and the corresponding interface models and parameter models in a test case library;

[0010] Based on all the test cases and the test case library, a test report is obtained.

[0011] In one or some optional implementations of the embodiment of the present application, generating multiple test cases based on the interface model and the parameter model, and setting a parameter value for each of the test cases, includes:

[0012] Generate a plurality of test cases based on the interface model, the parameter model, the matching parameter rule, and the matching assertion rule; the plurality of test cases include normal cases, boundary cases, and exception cases;

[0013] Set the parameter values of each test case based on each test case, the matching parameter rule, and the matching assertion rule.

[0014] In one or some optional embodiments of the embodiments of the present application, the generating an interface model and a parameter model according to the obtained interface description document includes:

[0015] Read the interface description document, and parse to obtain the interface information and general parameters of each interface; the interface information includes the interface path, request method, interface parameters, request body, response body, and response information; the interface parameters include path parameters;

[0016] Parse the request body according to the request method of each interface to obtain the content type and defined structure model of each interface request body, and add the content type and defined structure model to the interface information of the corresponding interface;

[0017] Based on the interface path, request method, response body, response information, request body, and the content type and defined structure model of the request body of each interface, obtain an interface model;

[0018] Based on the general parameters and interface parameters of each interface, obtain a parameter model.

[0019] In one or some optional embodiments of the embodiments of the present application, after generating the interface model and the parameter model according to the obtained interface description document, it further includes:

[0020] Associate the interface model and the parameter model to obtain complete interface definition information.

[0021] In one or some optional embodiments of the embodiments of the present application, the obtaining a test report based on all the test cases and the use case library includes:

[0022] Read the use case library according to each test case to obtain the corresponding test case data;

[0023] Construct an interface request according to the test case data;

[0024] Send the interface request to the target interface environment to obtain an actual response result;

[0025] Obtain a test result according to the expected result and the actual response result;

[0026] Based on the test results of all test cases, a test report is obtained.

[0027] In one or some optional implementations of the embodiment of the present application, obtaining a test result according to the expected result and the actual response result includes:

[0028] According to the expected result and the actual response result, determine whether the actual response result is abnormal:

[0029] If yes, the test result is abnormal;

[0030] Otherwise, determine whether the expected result is consistent with the actual response result:

[0031] If yes, the test result is passed;

[0032] If not, the test result is failure.

[0033] In a second aspect, an embodiment of the present invention provides an interface testing method and device for generating test cases based on an interface description document, the device comprising:

[0034] The interface parsing module is used to input the acquired interface description document into the interface parser to generate an interface model and a parameter model;

[0035] A use case generation module, used to generate multiple test cases based on the interface model and the parameter model, and set the parameter value of each test case; the test cases include regular test cases, boundary test cases and abnormal test cases;

[0036] Generate test steps, set expected results and assertion rules for each test case according to the interface model and the parameter model;

[0037] Storing all the test cases and the corresponding interface models and parameter models in a test case library;

[0038] The use case execution module is used to input all the test cases and the use case library into the use case executor to obtain a test report.

[0039] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the interface testing method for generating test cases based on an interface description document as described above.

[0040] In a fourth aspect, an embodiment of the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the interface testing method for generating test cases based on an interface description document as described above is implemented.

[0041] In a fifth aspect, an embodiment of the present invention provides a computer program product comprising instructions, which, when executed on a computer device, enables the computer device to execute the interface testing method for generating test cases based on an interface description document as described above.

[0042] In a sixth aspect, an embodiment of the present invention provides a chip, the chip including a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a computer program or instructions to implement the interface testing method for generating test cases based on an interface description document as described above.

[0043] The beneficial effects of the above technical solution provided by the embodiment of the present invention include at least:

[0044] The interface testing method for generating test cases based on interface description documents provided by the embodiment of the present invention comprises the following steps: inputting the acquired interface description document into an interface parser to generate an interface model and a parameter model; inputting the interface model and the parameter model into a use case generator to generate multiple test cases, including regular use cases, boundary use cases and abnormal use cases; then generating test steps, setting expected results and assertion rules; storing all generated test cases into a use case library; inputting the test cases into a use case executor to obtain a test report; the present invention realizes the automatic collection and parsing of interface description documents, avoids manual retrieval of interface description documents, reduces the dependence on back-end developers and the communication cost, and effectively improves the test use case. It improves the timeliness and efficiency of case generation; conducts intelligent analysis on various types of interface input parameters, adopts algorithms to automatically generate relatively comprehensive and high-quality test cases, covers test scenarios with various parameter combinations to the maximum extent, and reduces a large amount of repetitive design work for testers; realizes batch automatic execution of test cases through task management and automated execution, reduces manual testing costs and error rates; automatically generates test reports, counts and analyzes test results, guides subsequent test optimization and debugging, reflects the coverage and quality of current tests, thereby achieving a high degree of automation of the entire interface testing process, greatly improving test frequency and quality, and providing guarantees for the quality and stability of software products.

[0045] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.

[0046] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0048] Figure 1 It is a flowchart of an interface testing method for generating test cases based on an interface description document provided in an embodiment of the present application;

[0049] Figure 2 This is the intention of the conventional interface test process provided by the embodiment of the present application;

[0050] Figure 3 is a schematic diagram of an interface parser provided in an embodiment of the present application;

[0051] Figure 4 is a schematic diagram of a use case generator provided in an embodiment of the present application;

[0052] Figure 5 is a schematic diagram of a use case executor provided in an embodiment of the present application;

[0053] Figure 6 It is a schematic diagram of the framework of an interface testing method for generating test cases based on an interface description document provided in an embodiment of the present application;

[0054] Figure 7 It is a schematic diagram of the user layer, implementation layer, and data layer framework provided in the embodiment of the present application;

[0055] Figure 8 A schematic diagram of the structure of an interface testing device for generating test cases based on an interface description document provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0057] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0058] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0059] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0060] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0061] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0062] It should be understood that the size of the serial numbers of the steps in the following embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0063] In order to illustrate the technical solution of the present application, a specific embodiment is provided below for illustration.

[0064] The inventors found that in the prior art, testers need to manually analyze interface description documents, understand interface-related information such as input parameters, output parameters and business logic, and then design test plans and a large number of test cases, and manually execute and verify the results. This manual testing method is inefficient and can easily lead to insufficient test coverage or missing test points due to human negligence, resulting in a small number of test cases, making it difficult to cover a wide range of parameter combinations, and unable to guarantee the quality of software product delivery.

[0065] In the specific implementation, the project testers need to use the interface test method to perform interface testing according to the test plan, and obtain the interface description document after communicating with the developers. The general interface test process diagram is as follows Figure 2 As shown in the figure, after obtaining the interface description document, the tester extracts the interface related information, that is, Figure 2 The interface information in the interface is obtained, and then the test cases are manually designed and written. After forming a set of test cases, they are executed one by one, and the test results are recorded to form a test report. The conventional interface testing process has the following shortcomings and deficiencies: testers need to spend a long time to understand and enter the relevant information in the interface definition specification or interface description document, such as input and output parameters, business logic, etc., which will undoubtedly greatly reduce the test efficiency and easily lead to information omission or misrecording; each interface needs to design a large number of test cases according to its interface parameters to achieve a high coverage rate, but manual design is difficult to achieve high coverage, and the number of test cases is often difficult to guarantee; due to the large number of interfaces, the assertions of each interface also need to be manually written, which also has the problems of low efficiency and omissions.

[0066] Based on this, in order to solve the problem that the existing interface testing process relies on manual design, analysis and execution of use cases, which is inefficient and has insufficient test coverage, the inventors have made the present invention after further research and development, providing an interface testing method and device for generating test cases based on interface description documents.

[0067] Embodiment 1

[0068] The embodiment of the present invention provides an interface testing method for generating test cases based on an interface description document, referring to Figure 1 As shown, the method includes:

[0069] S101: Generate an interface model and a parameter model according to the acquired interface description document.

[0070] In the embodiment of the present application, in the above step S101, generating an interface model and a parameter model according to the acquired interface description document includes:

[0071] Read the interface description document, parse and obtain the interface information and common parameters of each interface; the interface information includes the interface path, request method, interface parameters, request body, response body and response information; the interface parameters include path parameters;

[0072] Parse the request body according to the request method of each interface, obtain the content type and defined structure model of the request body of each interface, and add the content type and defined structure model to the interface information of the corresponding interface;

[0073] Based on the interface path, request method, response body, response information, request body and content type of the request body and the defined structural model of each interface, an interface model is obtained;

[0074] Based on the common parameters and interface parameters of each interface, a parameter model is obtained.

[0075] In the embodiment of the present application, after obtaining the interface model and the parameter model, the method may further include: associating the interface model and the parameter model to obtain complete interface definition information.

[0076] In the embodiment of the present application, the interface analysis diagram is as follows Figure 3 As shown, first, the staff writes the interface file containing n interfaces into an interface description document in accordance with a specific standard format, and requires the use of annotations in a specific format to describe the interface information. Then, the interface information is parsed based on the interface description document, and the specific steps include: the first step is to read the interface description document, use the parsing tool to obtain the interface information and common parameters of each interface, and store these data in the data structure of the memory, wherein the interface information includes the interface path, request method, interface parameters, request body, response body and response information, and the interface parameters include various parameters such as path parameters and query parameters; the second step is to parse the request body according to the request method of the interface, obtain the content type and the defined structure model of the request body corresponding to the interface, and add the content type and the defined structure model to the interface information of the corresponding interface for associated storage; the third step is to construct a data structure based on the interface path, request method, response body, response information, request body and the content type and the defined structure model of the request body of the interface to obtain the interface model; the fourth step is to construct a data structure based on the common parameters and interface parameters of the interface. At the same time, it is necessary to process the multi-layer nested structure existing in the interface description document, extract the key parameter information, and compress it to simplify the data structure to obtain the parameter model; the fifth step is to associate the interface model of the interface with the corresponding parameter model to obtain the complete interface definition information.

[0077] In a specific embodiment, the step of parsing interface information based on the interface description document includes: first, using a parsing tool to obtain the interface information and common parameters of each interface, and if the interface description document is in JSON format, the JSON tool can be used to parse the interface description document. Then, the request body is parsed according to the request method of the interface. If the interface supports requests such as POST and PUT, the request body will be parsed to obtain the content type and the defined structure model. For example, if the content type (Content-Type) is "application / json", it means that the data in the request body is in JSON format, and the defined structure model can be JSONSchema.

[0078] Next, to help understand, some structures and special terms in the interface description document are explained, such as Figure 3As shown, the interface description document includes meta information, server, path, parameter, request body and response body, which correspond to meta information description, server definition, path declaration, parameter description, request body definition and response body description respectively. The interface description document also includes rules and examples. Among them, the meta information includes basic information about the interface, such as the name, version, description, license and other information of the interface; the server information includes the url and description of the interface server; the path declaration includes the url path of the interface and the supported http methods, such as GET, POST, etc.; the parameter description includes interface parameters, such as name, location, whether required, type, format and other information; the request body definition includes the request body content type and the defined structural model; the response description includes the response status code and content type, such as the response status code 200OK indicates that the request is successful, and the content type "application / json" indicates that the response data will be returned in JSON format; the rules and examples are provided by developers when writing interface description documents, and they are rules and examples on how to correctly use the interface to help testers understand the interface. Step S101 is to parse the above data to obtain standardized interface parameters and common parameters.

[0079] S102: Generate multiple test cases based on the interface model and the parameter model, and set parameter values ​​for each test case.

[0080] In the embodiment of the present application, in the above step S102, multiple test cases are generated based on the interface model and the parameter model, and the parameter value of each test case is set, including:

[0081] Generate multiple test cases based on interface model and parameter model, matching parameter rules and matching assertion rules; multiple test cases include regular test cases, boundary test cases and abnormal test cases;

[0082] Based on each test case, matching parameter rules and matching assertion rules, set the parameter values ​​for each test case.

[0083] In the present application, refer to Figure 4As shown, the steps of generating test cases based on the interface model and the parameter model and setting the parameter values ​​of each test case include: the first step is to obtain the interface model and the parameter model generated in S101, which contain all the interface related information required to generate the test case; the second step is to obtain the matching parameter rules and the matching assertion rules from the interface related information, the matching parameter rules include the parameter type rules, the parameter range rules, the reverse parameter rules, and the special regular rules, the matching assertion rules include the framework response code, the custom response code, the manually defined assertion, and the reverse assertion, wherein the parameter type rule describes the data type of the parameter, the parameter range rule describes the valid value range of the parameter, the reverse parameter rule describes the illegal value of the parameter, the special regular rule describes the parameter setting feature regular verification, such as the parameter must conform to the special format of the email address, mobile phone number, etc., the framework response code describes the standard based on HTTP Quasi-response codes, such as 200OK, 404NotFound, etc., custom response codes describe custom response codes specific to the current interface, manually defined assertions indicate that developers have set specific status codes, and reverse assertions indicate testing unexpected status codes, which are used to verify unexpected response results; the third step is to generate multiple test cases based on all interface-related information, matching parameter rules, and matching assertion rules. The test cases include regular test cases, boundary test cases, and exception test cases. Regular test cases verify the main usage scenarios of the interface and verify whether the response is normal during normal behavior. Boundary test cases verify whether the response is normal when testing the maximum value, minimum value, and other boundary conditions for the parameter values ​​of the digital class. The exception test case verifies whether the expected error response can be obtained when the required parameter is not set or an illegal value is set; the fourth step is to set parameter values ​​for the generated test cases, such as path parameters in the interface-related information.

[0084] S103: Generate test steps, set expected results and assertion rules for each test case according to the interface model and the parameter model.

[0085] S104: All test cases and corresponding interface models and parameter models are stored in a test case library.

[0086] In an embodiment of the present application, after obtaining the generated test cases, test steps are set for each generated test case, and the test steps include request method, URl, request header, request parameter value, request body, etc. According to the matching parameter rules and matching assertion rules corresponding to the specific scenario of the test case, appropriate parameter values ​​are set for each test case, and expected results and corresponding assertions are set. The expected results include the expected status code, response header and response body, and the assertions include status code verification, response header verification, JSON schema verification, etc.

[0087] In a specific embodiment, taking a test case whose function is to obtain user information as an example, the test case name is Get User Information, and the specific test steps include: the request method is GET, the URL is the client's corresponding function URL, the request header includes the user login status token Authorization, and the content type application / json, there is no additional request parameter value and request body, and the expected results include: the expected status code: 200OK, the expected response header: content type application / json, the expected response body, that is, the user's information, and the assertion includes status code verification assert200, response header verification assert application / json, and JSON schema verification, which verifies whether the response body is a JSON structure.

[0088] In the embodiment of the present application, after all test cases are obtained through steps S102 and S103, first, other information needs to be associated with each test case, such as interface name, case type, project, creation time, etc., to facilitate management and maintenance. Then, all test cases and other related information contained in the interface model and parameter model are saved in the test case library to provide detailed information for subsequent test case executors.

[0089] S105: A test report is obtained based on all test cases and the test case library.

[0090] In the embodiment of the present application, in the above step S105, a test report is obtained based on all test cases and the test case library, including:

[0091] Read the test case library according to each test case to obtain the corresponding test case data;

[0092] Construct interface requests based on test case data;

[0093] Send the interface request to the target interface environment and obtain the actual response result;

[0094] Get the test results based on the expected results and actual response results;

[0095] Based on the test results of all test cases, a test report is obtained.

[0096] Among them, according to the expected results and the actual response results, the test results are obtained, including:

[0097] Based on the expected result and the actual response result, determine whether the actual response result is abnormal:

[0098] If yes, the test result is abnormal;

[0099] Otherwise, determine whether the expected result and the actual response result are consistent:

[0100] If yes, the test result is passed;

[0101] If not, the test result is failure.

[0102] In the present application, refer to Figure 5 As shown, the steps of obtaining a test report based on all test cases in the case library include: the first step is to read the test case set storing the test case definition information in the case library and obtain the data of all the test cases therein; the second step is to use the HTTP request library (such as requests) to assemble the interface request for each test case, including the request method, URL, request header, request parameters, request body and other data; the third step is to send the interface request to the target interface environment to obtain the actual response result; the fourth step is to parse the actual response result and extract the status code, response header, response body and other data; the fifth step is to check whether the status code, response header and response body are consistent according to the expected result and the data obtained by parsing the actual response result to determine whether the assertion is passed. If an unexpected exception occurs, the test result is "abnormal", if the actual response is consistent with the expected result, the test result is "passed", if not, the test result is "failed"; the sixth step is to generate the final test report according to the test results of all test cases. The test report contains the statistics of the number of passed, failed and abnormal assertions, as well as the details of failed and abnormal state assertions, to help testers quickly locate problems.

[0103] In order to facilitate those skilled in the art to understand the present solution, the specific implementation process of the interface testing method for generating test cases based on the interface description document provided in the embodiment of the present invention is described more clearly and completely below:

[0104] The framework diagram of the interface test method based on the interface description document to generate test cases and the framework diagram of the user layer, implementation layer, and data layer are as follows Figure 6 , Figure 7 In the present invention, the operation module of step S101 is called an interface parser, the operation modules of steps S102 to S104 are called a use case generator, and the operation module of step S105 is called a use case executor. Figure 6 It can be seen that the interface description document in the upper left corner is input into the interface parser for parsing to obtain the parsing results, build the interface model and parameter model, and then input the parameter model of the interface model into the use case generator to generate test cases and store them in the use case library. The use case executor obtains the test results of all test cases based on the test cases in the use case library and obtains the final test report.

[0105] Reference Figure 7 As shown, Figure 6The framework diagram of the interface testing method for generating test cases based on interface description documents is standardized in the form of user layer, implementation layer, and data layer. Among them, the user layer of the interface parser is mainly responsible for running and configuring the interface parser, providing interface description documents, and setting parsing rules and other configurations; the user layer of the use case generator is mainly responsible for proposing the demand goals that need to be achieved in use case generation, providing business scenarios, and designing the expected results of use cases, providing guidance on how to generate use cases for the use case generator, corresponding to the functional positioning of the use case generator; the user layer of the use case executor refers to all users involved in the project, such as development and testing, and mainly focuses on the test reports generated by the use case executor to evaluate the coverage and quality of use case execution, corresponding to the value of the output of the use case executor.

[0106] The purpose of the present invention is to solve the problem that the existing interface testing process relies on manual design, analysis and execution of use cases, which is inefficient and insufficient in test coverage, so as to achieve continuous high-quality testing to meet the requirements of rapid iteration and delivery. The interface testing method for generating test cases based on interface description documents proposed by the present invention avoids manual retrieval of interface description documents through automatic collection and parsing of interface description document definitions, reduces dependence on back-end developers and communication costs, and effectively improves the timeliness and efficiency of test case generation; realizes intelligent analysis of various types of interface input parameters, adopts algorithms to automatically generate more comprehensive and high-quality test cases, covers test scenarios of various parameter combinations to the maximum extent, and reduces a large amount of repetitive design work for testers; realizes batch automatic execution of test cases through task management and automated execution means, reduces manual testing costs and error rates; realizes automated generation of test reports, statistics and analysis of test results, guides subsequent test optimization and debugging, and reflects the coverage and quality of current tests; realizes high automation of the entire process of interface testing, greatly improves test frequency and quality, and provides guarantee for the quality and stability of software products.

[0107] Embodiment 2

[0108] Based on the same inventive concept, the embodiment of the present invention also provides an interface testing device for generating test cases based on an interface description document, referring to Figure 8 As shown, the device comprises:

[0109] The interface parsing module is used to input the acquired interface description document into the interface parser to generate an interface model and a parameter model;

[0110] A use case generation module, used to generate multiple test cases based on the interface model and the parameter model, and set the parameter value of each test case; the test cases include regular test cases, boundary test cases and abnormal test cases;

[0111] Generate test steps, set expected results and assertion rules for each test case according to the interface model and the parameter model;

[0112] Storing all the test cases and the corresponding interface models and parameter models in a test case library;

[0113] The use case execution module is used to input all the test cases and the use case library into the use case executor to obtain a test report.

[0114] Embodiment 3

[0115] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the interface testing method for generating test cases based on an interface description document as described in the above embodiment 1 is implemented.

[0116] Embodiment 4

[0117] Based on the same inventive concept, an embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the interface testing method for generating test cases based on an interface description document as described in the above-mentioned embodiment 1.

[0118] Embodiment 5

[0119] Based on the same inventive concept, an embodiment of the present invention also provides a computer program product comprising instructions. When the computer program product runs on a computer device, the computer device executes the interface testing method for generating test cases based on an interface description document as described in the first embodiment above.

[0120] Embodiment 6

[0121] Based on the same inventive concept, an embodiment of the present invention also provides a chip, the chip includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a computer program or instructions to implement an interface testing method for generating test cases based on an interface description document as described in the above embodiment one.

[0122] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.

[0123] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0124] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0125] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0126] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. Interface testing method that generates test cases based on interface description documents, It is characterized in that include: Generate interface model and parameter model according to the obtained interface description document; Generate multiple test cases based on the interface model and the parameter model, and set the parameter value of each test case; Generate test steps, set expected results and assertion rules for each test case according to the interface model and parameter model; Storing all the test cases and the corresponding interface models and parameter models in a test case library; Based on all the test cases and the test case library, a test report is obtained.

2. The method according to claim 1, It is characterized in that The generating a plurality of test cases based on the interface model and the parameter model, and setting a parameter value of each of the test cases, comprises: Based on the interface model and the parameter model, the matching parameter rule and the matching assertion rule, a plurality of test cases are generated; the plurality of test cases include regular test cases, boundary test cases and abnormal test cases; Based on each of the test cases, the matching parameter rules and the matching assertion rules, a parameter value of each of the test cases is set.

3. The method according to claim 1, It is characterized in that The generating of the interface model and the parameter model according to the acquired interface description document includes: Read the interface description document, parse and obtain interface information and common parameters of each interface; the interface information includes interface path, request method, interface parameters, request body, response body and response information; the interface parameters include path parameters; Parsing the request body according to the request method of each interface, obtaining the content type and defined structure model of the request body of each interface, and adding the content type and defined structure model to the interface information of the corresponding interface; Based on the interface path, request method, response body, response information, request body and content type of the request body of each interface and the defined structural model, an interface model is obtained; Based on the common parameters and interface parameters of each interface, a parameter model is obtained.

4. The method according to claim 1, It is characterized in that After generating the interface model and the parameter model according to the acquired interface description document, the method further includes: The interface model and the parameter model are associated to obtain complete interface definition information.

5. The method according to claim 1, It is characterized in that The test report is obtained based on all the test cases and the test case library, including: Read the test case library according to each test case to obtain corresponding test case data; Constructing an interface request according to the test case data; Sending the interface request to the target interface environment to obtain an actual response result; Obtaining a test result according to the expected result and the actual response result; Based on the test results of all test cases, a test report is obtained.

6. The method according to claim 5, It is characterized in that The test result is obtained according to the expected result and the actual response result, including: According to the expected result and the actual response result, determine whether the actual response result is abnormal: If yes, the test result is abnormal; Otherwise, determine whether the expected result is consistent with the actual response result: If yes, the test result is passed; If not, the test result is failure.

7. An interface testing method and device for generating test cases based on an interface description document, It is characterized in that include: The interface parsing module is used to input the acquired interface description document into the interface parser to generate an interface model and a parameter model; A use case generation module, used to generate multiple test cases based on the interface model and the parameter model, and set the parameter value of each test case; the test cases include regular test cases, boundary test cases and abnormal test cases; Generate test steps, set expected results and assertion rules for each test case according to the interface model and the parameter model; Storing all the test cases and the corresponding interface models and parameter models in a test case library; The use case execution module is used to input all the test cases and the use case library into the use case executor to obtain a test report.

8. A computer-readable storage medium storing instructions, which, when executed on a terminal, causes the terminal to execute the interface testing method for generating test cases based on an interface description document as described in any one of claims 1 to 6.

9. A computer device, It is characterized in that It includes a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the interface testing method for generating test cases based on an interface description document as described in any one of claims 1 to 6.

10. A computer program product comprising instructions, which, when executed on a computer device, enables the computer device to execute the interface testing method for generating test cases based on an interface description document as claimed in any one of claims 1 to 6.

11. A chip, comprising a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement the interface testing method for generating test cases based on an interface description document as described in any one of claims 1 to 6.

Citation Information

Cited By

  • Test case generation method and device, electronic equipment and storage medium

    CN121434102A