Method and device for generating interface test case
By analyzing interface documents and applying the principles of equivalence classes and boundary value division, interface test cases are automatically generated, which solves the problems of inefficient generation of interface test cases and incomplete coverage in the existing technology, and realizes efficient and accurate interface testing.
Patent Information
- Application Number
- CN202411328446.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2024-11-26
AI Technical Summary
In the prior art, the generation efficiency of interface test cases is inefficient, error-prone and incomplete coverage, resulting in missed tests and errors in the software system in function, security and stability verification.
By obtaining the interface document data of the system software to be tested, analyzing the interface document based on predetermined parsing rules, combining the equivalence class division principle and boundary value division principle, test case data is automatically generated, including forward and opposite test cases, covering the various interfaces input and boundary situations.
It significantly improves the generation efficiency of interface test cases, reduces the time and workload of manually writing use cases, reduces the risk of missed tests and incorrect tests caused by human factors, can quickly adapt to different types of interface documents, improves test coverage and accuracy.
Smart Images

Figure CN119025432A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of software testing technology, specifically to the field of interface testing technology, and more specifically to a method and device for generating interface test cases. Background Art
[0002] In today's Internet computer industry, the quality issues of software systems are becoming increasingly prominent, and bugs frequently appear, not limited to functions, security, and performance. The reasons behind this can be summarized as follows: no software testing, incomplete functional test cases, difficulty in ensuring the depth of testing (only testing page functions), and insufficient time and human resources to complete testing.
[0003] In view of this, in order to create stable and mature products or software, it is urgently necessary for the testing team to cover more functions as widely as possible in the short term without increasing labor costs, while significantly improving the test coverage, accuracy and test depth.
[0004] Therefore, there is an urgent need for effective methods or practical tools that can quickly and comprehensively verify the functionality, security and stability of the system interfaces of the products being tested, so as to completely solve this serious problem that has long plagued the development of the industry. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method and device for generating interface test cases, aiming to solve the technical problems in the prior art that interface test cases are inefficient, error-prone and have incomplete coverage.
[0006] To achieve the above object, according to a first aspect of the present application, a method for generating an interface test case is provided, the method comprising:
[0007] Acquire interface document data of the system software to be tested, wherein the interface document data at least includes: address information of the interface document;
[0008] Parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to each of all interfaces contained in the interface document, wherein the predetermined parsing rule is formulated according to the document type of the interface document;
[0009] Based on the predetermined use case generation rules, corresponding test case data is generated according to the basic data of each of the interfaces, wherein at least an equivalence class partitioning principle and a boundary value partitioning principle are introduced into the predetermined use case generation rules.
[0010] Optionally, in a possible implementation manner of the first aspect, the generating corresponding test case data according to the basic data of each of the interfaces based on a predetermined use case generation rule includes:
[0011] According to the equivalence class division principle and the boundary value division principle, a plurality of valid equivalence class rules and a plurality of invalid equivalence class rules are divided;
[0012] According to the input parameter field information and field restriction conditions in the basic data of each of the interfaces, combined with the valid equivalence class rules and the invalid equivalence class rules, positive test case data and heterogeneous test case data are generated.
[0013] Optionally, in a possible implementation manner of the first aspect, each of the valid equivalence class rules and the invalid equivalence class rules respectively corresponds to a rule default value, and the generating of the positive test case data and the outward test case data according to the input parameter field information and the field restriction condition in the basic data of each of the interfaces, in combination with the valid equivalence class rules and the invalid equivalence class rules, includes:
[0014] If the field type of the input parameter field information is an integer type, then according to the boundary value of the input parameter field indicated in the field restriction condition, the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the integer input parameter field are determined; and / or
[0015] If the field type of the input parameter field information is a string type, then according to the limit length of the input parameter field indicated in the field restriction condition, the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the string type input parameter field are determined; and / or
[0016] If the field type of the input parameter field information is non-mandatory, then determining the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the non-mandatory input parameter field;
[0017] Forward test case data is generated according to the rule default values corresponding to the valid equivalence class rules, and outward test case data is generated according to the rule default values corresponding to the invalid equivalence class rules.
[0018] Optionally, in a possible implementation manner of the first aspect, after generating the positive test case data and the negative test case data, the method further includes:
[0019] If there are multiple positive test case data, retain one positive test case data with the same equivalence class among the multiple positive test case data;
[0020] If there are multiple heterogeneous test case data, multiple heterogeneous test case data are retained.
[0021] Optionally, in a possible implementation manner of the first aspect, after generating corresponding test case data according to the basic data of each of the interfaces based on a predetermined use case generation rule, the method further includes:
[0022] Determine the title line of each form page in the pre-generated test case template, wherein the title line of each form page in the test case template is named using at least one of the following data: interface name, request method, interface route, input parameter field, whether forward or reverse, and expected response result;
[0023] The test case data is written into the test case template according to the title row of each form page.
[0024] Optionally, in a possible implementation manner of the first aspect, parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to each of all interfaces included in the interface document includes:
[0025] According to the address information of the interface document, requesting access to the interface module of the system software to be tested corresponding to the address information;
[0026] According to the document type of the interface document, the corresponding predetermined parsing rule is called to traverse the interface module to obtain the basic data corresponding to all the interfaces, wherein the basic data includes at least one of the following: interface name, interface routing, request method, input parameter field, and expected response result.
[0027] Optionally, in a possible implementation manner of the first aspect, calling the corresponding predetermined parsing rule to traverse the interface module according to the document type of the interface document to obtain basic data corresponding to each of all the interfaces includes:
[0028] Obtaining a module name of the system software to be tested, wherein the module name is a name of an interface module obtained by dividing the system software to be tested according to code annotations;
[0029] According to the document type of the interface document, the corresponding predetermined parsing rule is called to traverse the interface module according to the module name to obtain the basic data corresponding to all the interfaces, wherein each interface module corresponds to an interface category, and each interface category contains multiple interfaces.
[0030] Optionally, in a possible implementation manner of the first aspect, after parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, the method further includes:
[0031] Obtaining field information of an input parameter field of each of the interfaces, wherein the field information is a type and / or length of the input parameter field;
[0032] In the case where the input parameter fields include a required associated foreign key field, the interface is labeled, wherein the label is used to indicate that no additional processing is required on the required associated foreign key field when generating corresponding test case data for the interface.
[0033] Optionally, in a possible implementation manner of the first aspect, after parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, the method further includes:
[0034] In the case that the basic data of any of the interfaces do not meet the data result requirements, the basic data of the interface are subjected to data format conversion processing to obtain converted basic data of the interface, wherein the type of the converted basic data includes: a string type;
[0035] The interface and the converted basic data of the interface are stored in a message queue.
[0036] According to a second aspect of the present application, a device for generating an interface test case is provided, comprising:
[0037] An acquisition unit, used to acquire interface document data of the system software to be tested, wherein the interface document data at least includes: address information of the interface document;
[0038] A parsing unit, configured to parse the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to each of all interfaces contained in the interface document, wherein the predetermined parsing rule is formulated according to the document type of the interface document;
[0039] A generating unit is used to generate corresponding test case data according to the basic data of each of the interfaces based on predetermined use case generation rules, wherein at least an equivalence class partitioning principle and a boundary value partitioning principle are introduced into the predetermined use case generation rules.
[0040] The second aspect and any implementation of the second aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the second aspect and any implementation of the second aspect can refer to the technical effects corresponding to the first aspect and any implementation of the first aspect, which will not be repeated here.
[0041] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the methods described above when executing the computer program.
[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements any of the methods described above.
[0043] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes any one of the methods described in the first aspect.
[0044] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.
[0045] The present application provides a method and device for generating interface test cases. The method for generating interface test cases obtains interface document data of system software to be tested, wherein the interface document data at least includes: address information of the interface document; the address information of the interface document is parsed based on predetermined parsing rules to obtain basic data corresponding to all interfaces contained in the interface document, wherein the predetermined parsing rules are formulated according to the document type of the interface document; based on predetermined case generation rules, corresponding test case data is generated according to the basic data of each interface, wherein the predetermined case generation rules at least introduce an equivalence class division principle and a boundary value division principle.
[0046] Through the above-mentioned embodiments of the present application, the difficulties in parsing and processing caused by the diversity of interface document types can be overcome, and the problems of inefficiency, error-proneness and incomplete coverage of manually written interface test cases can be solved. The automated generation and execution process reduces the risk of missed tests and erroneous tests caused by human factors, can quickly adapt to different types of interface documents, can significantly improve the generation efficiency of interface test cases, and reduce the time and workload of manually writing cases. In addition, with the help of the equivalence class division principle and the boundary value division principle, potential problems of the interface under boundary and abnormal conditions can be effectively discovered. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0048] Figure 1 It is a schematic flow chart of a method for generating an interface test case provided in an embodiment of the present application;
[0049] Figure 2 It is a schematic flow chart of an optional method for generating interface test cases provided in an embodiment of the present application;
[0050] Figure 3 It is a schematic flow chart of an optional method for generating interface test cases provided in an embodiment of the present application;
[0051] Figure 4 It is a schematic flow chart of an optional method for generating interface test cases provided in an embodiment of the present application;
[0052] Figure 5 It is a schematic flow chart of an optional method for generating interface test cases provided in an embodiment of the present application;
[0053] Figure 6 It is a structural schematic diagram of a device for generating interface test cases provided in an embodiment of the present application;
[0054] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] 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.
[0056] 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.
[0057] 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.
[0058] 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.
[0059] 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.
[0060] 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.
[0061] First, some terms in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0062] The online interface document address is a specific URL that can be accessed through the Internet. The URL contains a detailed description and explanation information about the interface in the software system. The page pointed to by the address will present the relevant content of the interface in a specific format and structure.
[0063] JSON (JavaScript Object Notation) is a lightweight data exchange format.
[0064] Swagger is a specification and framework for describing and defining APIs. Swagger-type interface documents usually have detailed API descriptions, including API endpoints (paths), request methods (such as GET, POST, PUT, DELETE, etc.), input parameters, output parameters, response examples, error codes, and other information. It is usually presented in YAML or JSON format and has a visual interface to facilitate developers to view and understand the structure and functions of the API.
[0065] Yapi is an API management platform that provides richer functions, such as permission management, data mock, testing, team collaboration, etc. The Yapi type interface document contains the basic information of the API, such as path, request method, parameters, response, etc.
[0066] A ll ure is a flexible, lightweight, multi-language test reporting framework that is used to generate test reports containing rich information, display the pass, fail, skip and other status of the test in an intuitive way, and provide detailed error information and stack traces.
[0067] The above is a brief introduction to the terms involved in the embodiments of the present application, which will not be repeated below.
[0068] In today's Internet computer industry, the quality issues of software systems are becoming increasingly prominent, and bugs frequently appear, covering multiple aspects such as functionality, security, and performance. The root causes of this situation are mainly the following key factors:
[0069] First, some software completely lacks the testing process during the development process, resulting in the software being put into use without sufficient verification, which poses many hidden dangers.
[0070] Second, there is a serious problem of incompleteness in functional test cases. Many test cases only focus on the surface page functions, but do not consider the underlying interface logic and complex interaction scenarios enough, resulting in a large number of potential problems being ignored.
[0071] Third, it is difficult to ensure the depth of testing. Due to time constraints and shortage of human resources, testing can only be done superficially, and it is impossible to deeply explore the performance of the software system under various extreme and complex conditions, making it difficult to discover hidden defects.
[0072] Fourth, limited time and tight human resources make comprehensive testing a luxury, and a large number of functions cannot be fully tested.
[0073] In view of this, in order to create stable and mature products or software, the testing team is urgently required to cover as many functions as possible in a short period of time without increasing labor costs, while significantly improving the coverage, accuracy and depth of the test. At present, the industry is in urgent need of an effective method and practical tool that can quickly and comprehensively verify the function, security and stability of the system interface of the tested product, so as to completely solve this serious problem that has long plagued the development of the industry.
[0074] Based on market research and problems with existing products, the interface documents provided in this application example include but are not limited to: RESTful (Representational State Transfer) style online interface documents generated using tools such as swagger. The inventors have found through research that they propose to parse interface documents to obtain basic data, and automatically generate and execute interface test cases for system software based on specific rules and open source frameworks. The following content describes in detail the specific implementation steps of the above method and the implementation of the system, including the framework, components, database, and system architecture used.
[0075] This application example provides an example of a method for generating an interface test case. Please refer to Figure 1 As shown, Figure 1 A schematic flowchart of a method for generating an interface test case provided by the present application is shown. As an example but not a limitation, the method can be applied to electronic devices.
[0076] S101, obtaining interface document data of the system software to be tested, wherein the interface document data at least includes: address information of the interface document.
[0077] In the above step S101, for example, it is possible but not limited to obtaining the address information of the interface document entered in the page of the test client by the tester. In addition, the interface document data may also include other information such as document type.
[0078] S102, parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, wherein the predetermined parsing rule is formulated according to the document type of the interface document.
[0079] In the above step S102, in response to the tester clicking the parsing operation after entering the interface document data, the address information of the interface document is parsed based on the predetermined parsing rules corresponding to the document type of the interface document, that is, the address of the interface document is requested to be accessed, and the basic data corresponding to each of the interfaces contained in the interface document is obtained. It can also be that the server program automatically requests to access the address of the interface document after receiving the address information of the interface document, and obtains the basic data in the returned Json format (lightweight data exchange format).
[0080] As an example and not a limitation, the address information of the online interface document refers to a specific URL that can be accessed through the Internet, which contains detailed descriptions and instructions about the interface in the software system. Generally speaking, the page pointed to by this address information will present the relevant content of the interface in a specific format and structure, so that testers and developers can clearly understand the specific requirements of each interface.
[0081] It should be understood that the predetermined parsing rules are code logic programs written in advance according to the document type of the interface document. Different types of interface documents have different rules, but the general steps are the same. For example, the acquired data can be processed and extracted through a series of code logic and algorithms, such as traversal, matching, regular expressions, etc., to obtain basic data such as the route, request method, and input parameters of each interface.
[0082] S103, based on the predetermined use case generation rules, corresponding test case data is generated according to the basic data of each interface, wherein the predetermined use case generation rules at least introduce an equivalence class division principle and a boundary value division principle.
[0083] In the above step S103, the predetermined use case generation rule is first determined, wherein the equivalence class division principle and the boundary value division principle are introduced.
[0084] In one example, for the basic data of each interface, the input values are divided into valid and invalid equivalence classes according to the equivalence class division principle. For example, for an interface that requires age input, the valid equivalence class may be an integer between 1 and 150 years old, and the invalid equivalence class may be a negative number, a decimal, or a value greater than 150 years old. According to the boundary value division principle, pay attention to the boundary conditions of the input domain. For example, the boundary values of the above age input may be 0 years old, 1 year old, 149 years old, and 150 years old.
[0085] Taking these principles and the basic data of the interface into consideration, various permutations and combinations and logical judgments are performed to generate corresponding test case data. For example, for an interface with required fields and length restrictions, test cases containing various valid and invalid input conditions are generated based on the rules of equivalence classes and boundary values.
[0086] The test cases or test case data in the example of this application can be understood as a code underlying interface test case, which is a collection of a series of test steps and expected results designed to verify the functionality, performance, stability, and security of the underlying interface in the software system.
[0087] The low-level interface usually refers to the more basic and core part of the software system, which may interact with hardware, operating system, other modules or external systems. By writing detailed test cases, the input and output, parameter transfer, exception handling, boundary conditions, etc. of these interfaces can be fully tested.
[0088] In a specific embodiment, suppose an interface requires input of a user's ID card number, and the rule is 18 digits. When generating test cases, based on the equivalence class division method or principle: the valid equivalence class is the 18-digit ID card number, and the invalid equivalence class is a string of non-18-digit numbers, a string containing letters or special characters, etc. Based on the boundary value division method or principle: the boundary value may be the smallest 18-digit number and the largest 18-digit number, as well as numbers near the boundary value, such as numbers with one less or one more digit. Then, various test cases are generated based on the above divisions and rules, such as valid standard numbers, numbers with one less digit, numbers with one more digit, numbers containing letters, etc.
[0089] Through the above-mentioned embodiments of the present application, it is possible to quickly adapt to different types of interface documents, significantly improve the efficiency of generating interface test cases, and reduce the time and workload of manually writing cases. The automated generation and execution process reduces the risk of missed tests and erroneous tests caused by human factors. Moreover, with the help of the equivalence class division principle and the boundary value division principle, potential problems of interfaces under boundary and abnormal conditions are effectively discovered. Furthermore, the difficulties in parsing and processing caused by the diversity of interface document types are overcome, and the problems of inefficiency, error-proneness, and incomplete coverage of manually written interface test cases are solved.
[0090] As an example but not a limitation, the interface test case generation scheme provided in the example of this application specifically relates to a method for generating interface test cases based on the underlying code, which has a wide range of applications in the fields of software system interfaces and automated testing. The following are some optional application areas:
[0091] Self-test of development software: After the developer completes the code development, he can use the generation scheme of the interface test case or run the test tool with the generation scheme of the interface test case to perform preliminary self-test on the interface module developed by the developer himself to ensure that the tested function will not cause a large number of system bugs.
[0092] Test case library update: During the product iteration process, due to the addition of new interfaces or changes to the original interfaces, some of the interface test cases of the previous version cannot be run. Using this tool can avoid most of the manual adjustments and automatically update and generate the latest version of the interface test case data.
[0093] Regression test verification: Before the product test is completed and the version is closed, the interface use cases generated by this tool can be fully executed to quickly regress all functional interfaces of the system to ensure the normal use of new and old functions, and to avoid bugs in the original functions due to changes in new functions.
[0094] Test data preparation: In daily functional testing, some test data preparation is sometimes needed. It is time-consuming to enter it manually. You can use this tool to quickly repeat one or more test cases to create data to meet the needs of functional testing.
[0095] These application areas are only part of the generation and execution method of test cases based on the underlying code interface. Due to the wide application of interface testing in software testing in various industries, the example method of this application can achieve fast, comprehensive and accurate testing software, help reduce manpower and time costs, improve production efficiency, and ensure that the system software always maintains high quality in continuous version iterations.
[0096] Please refer to Figure 2 As shown, Figure 2 A schematic flow chart of a method for generating an interface test case provided by the present application is shown. In a possible implementation, based on a predetermined case generation rule, corresponding test case data is generated according to basic data of each interface, including:
[0097] S201, dividing a plurality of valid equivalence class rules and a plurality of invalid equivalence class rules according to an equivalence class division principle and a boundary value division principle.
[0098] S202, generating positive test case data and heterogeneous test case data according to the input parameter field information and field restriction conditions in the basic data of each interface, combined with the valid equivalence class rules and the invalid equivalence class rules.
[0099] In a possible implementation, each valid equivalence class rule and invalid equivalence class rule respectively corresponds to a rule default value, and according to the input parameter field information and field restriction conditions in the basic data of each interface, combined with the valid equivalence class rule and the invalid equivalence class rule, positive test case data and outward test case data are generated, including:
[0100] S301, if the field type of the input parameter field information is an integer type, determine the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the integer type input parameter field according to the boundary value of the input parameter field indicated in the field restriction condition; and / or
[0101] S302, if the field type of the input parameter field information is a string type, then according to the limit length of the input parameter field indicated in the field limit condition, determine the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the string type input parameter field respectively; and / or
[0102] S303: If the field type of the input parameter field information is non-mandatory, determine the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the non-mandatory input parameter field;
[0103] S304, generating forward test case data according to the rule default values corresponding to the valid equivalence class rules, and generating reverse test case data according to the rule default values corresponding to the invalid equivalence class rules.
[0104] It should be noted that the above steps S301, S302 and S303 are not required to be executed in full, and when all are executed, the execution order and execution steps of steps S301, S302 and S303 are not limited. For example, S301 and S302 can be executed first, and then S303, or S302 and S303 can be executed first and then S301.
[0105] In the present application example, each valid equivalence class rule and invalid equivalence class rule has a corresponding default value, which is determined based on the input parameter field information and field restriction conditions in the interface basic data.
[0106] If the field type of the input parameter field information is integer, the default value of the rule corresponding to the valid equivalence class rule and the invalid equivalence class rule is determined according to the boundary value of the input parameter field indicated in the field restriction condition. When the field type of the input parameter field information is string, the default value of the rule corresponding to the valid equivalence class rule and the invalid equivalence class rule is determined according to the limit length of the input parameter field indicated in the field restriction condition.
[0107] If the field type of the input parameter field information is non-mandatory, the default values of the valid equivalence class rules and invalid equivalence class rules corresponding to the non-mandatory input parameter field are directly determined. For example, for a non-mandatory note field, the default value of the valid equivalence class rule may be a reasonable short string (such as "note"), and the default value of the invalid equivalence class rule may be null (empty value).
[0108] For example, if an interface has 3 fields, field a is a required int type and its maximum value is 0-100, the maximum boundary value, minimum boundary value, minimum boundary value plus 1, maximum boundary value minus 1 (i.e. 0, 1, 99, 100) are set as positive default parameters, and those exceeding the maximum boundary value, minimum boundary value, negative numbers and other types are set as reverse default parameters (e.g., -1, 101, null, 'test'), and a total of 8 possible situations can be obtained; field b is a required str type and its maximum length is 32 bits, and its maximum and minimum boundary values ('test', 'test'*16) are set as positive default parameters, and those exceeding the boundary value length limit and empty strings ('test'*18, null) are set as reverse default parameters, and a total of 4 possible situations. Field c is a non-required str type, and the forward default parameter is set to 'test', and the reverse default parameter is set to null, and a total of 2 possible situations. Therefore, the interface can automatically generate 8*4*2=64 types of positive and reverse test data.
[0109] In this application example, positive test case data is generated according to the default value of the rule corresponding to the valid equivalence class rule to characterize the input that the interface should be able to handle correctly under normal circumstances. At the same time, the out-of-phase test case data is generated according to the default value of the rule corresponding to the invalid equivalence class rule to test the performance of the interface under abnormal circumstances.
[0110] Through the above method, comprehensive positive and negative test case data can be generated for different types of input parameter fields according to their specific restrictions and equivalence class rules, so as to test the interface more effectively and improve the coverage and quality of the test.
[0111] In an optional example, after generating the positive test case data and the negative test case data, the method further includes:
[0112] If there are multiple positive test case data, then one positive test case data with the same equivalence class among the multiple positive test case data is retained;
[0113] If there are multiple heterogeneous test case data, then multiple heterogeneous test case data are retained.
[0114] Optionally, in the example of this application, only one piece of forward test case data with the same equivalence class among multiple forward test case data is retained, and all the heterogeneous test case data are retained. Finally, several pieces of interface test case data with relatively comprehensive forward and reverse coverage will be generated according to each interface under each module. The data format is a list, which nests several dictionary test case data, and the test case data also includes the request header, request method, request body, expected response and other contents collected previously.
[0115] In addition, after generating the test case input data, the program will write and save the data that should be in each test case according to the horizontal and vertical coordinates of all the titles in the first row according to the sheet name of the Excel template.
[0116] As an optional example, after generating corresponding test case data according to basic data of each interface based on a predetermined test case generation rule, the method further includes:
[0117] Determine the title row of each form page in the pre-generated test case template, wherein the title row of each form page in the test case template is named using at least one of the following data: interface name, request method, interface routing, input parameter field, whether forward or reverse, and expected response result.
[0118] Write the test case data to the test case template according to the header row of each form page.
[0119] In this application example, a test case execution and report generation solution is also provided. With the help of an open source framework, the generated test case data is read and scheduled for execution in a data-driven manner, and the expected result assertion is performed. The test case to be executed can be freely selected, and then the test data results are converted into a test report in HTML format through a third-party tool and the relevant person in charge is notified by email. This module can assist developers and testers to simply and quickly execute test cases for regression verification.
[0120] Specifically, the use case execution and report generation module in the test tool can read and execute the test case data in the Excel file in a data-driven manner. After the execution is completed, it can generate a test report with the help of a third-party tool and notify the relevant person in charge.
[0121] For a possible implementation, please refer to Figure 3 As shown, Figure 3 A schematic flow chart of an optional method for generating an interface test case provided by the present application is shown, wherein the address information of the interface document is parsed based on a predetermined parsing rule to obtain basic data corresponding to each of all interfaces contained in the interface document, including:
[0122] S401 : Requesting access to an interface module of the system software to be tested corresponding to the address information of the interface document.
[0123] S402, according to the document type of the interface document, calls the corresponding predetermined parsing rules to traverse the interface module to obtain the basic data corresponding to all interfaces, wherein the basic data includes at least one of the following: interface name, interface routing, request method, input parameter fields, and expected response results.
[0124] In the embodiment of the present application, when obtaining the interface document data of the system software to be tested, it is necessary not only to obtain the address information of the interface document, but also to clarify its document type. This is because the document type is very critical, because different types of interface documents may have different data structures and formats, and corresponding specific parsing rules are required to accurately extract and process the information therein.
[0125] For example, if the interface document is of Swagger type (Swagger is a specification and framework for describing and defining APIs. Swagger-type interface documents usually have detailed API descriptions, including API endpoints (paths), request methods (such as GET, POST, PUT, DELETE, etc.), input parameters, output parameters, response examples, error codes, and other information), there may be a specific set of parsing rules to handle its unique format and data structure; if it is of Yapi type (Yapi-type interface documents can also contain basic API information, such as paths, request methods, parameters, responses, etc.), another set of different rules is required. By simultaneously obtaining address information and document types, the system can determine which set of predetermined parsing rules should be called for subsequent processing, thereby ensuring accurate and effective acquisition and parsing of data in the interface document.
[0126] First, according to the address information of the interface document input by the tester on the client page, a request is sent to this address, so that the interface module of the system software to be tested corresponding to the address can be accessed.
[0127] Then, since the interface documents may have different types, such as swagger type or Yapi type, etc. According to the specific type of the current interface document, the corresponding pre-defined parsing rules are called. According to the specific type of the interface document, the corresponding predetermined parsing rules are called to traverse the interface module. During the traversal process, the information in the interface module is extracted and processed according to the rules, and the key information of each interface is extracted as the basic data. These basic data are very critical, including the interface name: clear interface identification; interface routing: indicates the path to access the interface; request method: such as GET, POST, etc., which determines the data interaction method; interface input parameters: that is, the parameters required to send a request to the interface; and the expected response result: the result that the interface should return after processing the request normally.
[0128] In an optional example, assuming that the interface document is of Swagger type, the test tool will call the parsing rules for the Swagger format to perform detailed parsing and data extraction on the interface module. If it is of Yapi type, the rules adapted to the Yapi format will be called to perform the same operation.
[0129] Through the above examples of this application, the basic data of the interface can be accurately and comprehensively obtained, providing the necessary basis and preparation for the subsequent generation of test cases and testing.
[0130] For a possible implementation, please refer to Figure 4 As shown, Figure 4A schematic flow chart of an optional method for generating interface test cases provided by the present application is shown. According to the document type of the interface document, the corresponding predetermined parsing rules are called to traverse the interface module to obtain the basic data corresponding to all interfaces, including:
[0131] S501, obtaining a module name of the system software to be tested, wherein the module name is a name of an interface module obtained by dividing the system software to be tested according to code annotations;
[0132] S502, according to the document type of the interface document, call the corresponding predetermined parsing rule to traverse the interface module according to the module name to obtain the basic data corresponding to all interfaces, wherein each interface module corresponds to an interface category, and each interface category contains multiple interfaces.
[0133] In the entire interface test case generation process, first, the interface modules of the system software to be tested are divided into several categories, and the module names of the system software to be tested are obtained. These module names are the names of the interface modules determined by dividing them according to code annotations during the development of the system to be tested. For example, in an e-commerce system, "user module", "order module", "payment module" and so on may be divided.
[0134] Then, according to the specific document type of the interface document (such as swagger type or Yapi type), the corresponding predetermined parsing rules are called. According to the module name that has been obtained, the corresponding interface module is traversed. Since each interface module corresponds to a specific interface category, the category of "user module" may include multiple interfaces such as "user registration interface", "user login interface", "user information modification interface", etc.
[0135] The specific traversal method can be to loop and match dictionary data according to the module name (dictionary data refers to the basic data in Json format. When it reaches the code, the basic data in Json format is converted into basic data in dictionary format. The basic data in dictionary format is a key-value pair. The key is the module name, and the value is a list. The content in the list is each interface information data under the module). Get the lower-level list data. The data format is a list nested dictionary. The dictionary content is each interface information under the module (interface input parameter dictionary). Loop through and read each interface information data again, match the interface route through regular expressions, obtain the interface request method, the interface input parameter dictionary, and the value of the correct response code.
[0136] Through the above traversal according to the module name and interface category, the basic data corresponding to each interface can be accurately extracted according to the predetermined parsing rules, such as interface name, interface route, request method, interface input parameter, expected response result, etc. For example, in the "order module", through traversal and parsing, the relevant basic data of the "create order interface" is obtained, including its specific route is " / order / create", the request method is "POST", the required input parameters are "product ID", "purchase quantity", etc., and the expected response result is the relevant information of the successful creation of the order.
[0137] Through the above examples, targeted and systematic traversal and analysis can be achieved, providing a solid data foundation for the subsequent generation of accurate and comprehensive test cases.
[0138] In a possible implementation, after parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, the method further includes:
[0139] Get the field information of the input parameter field of each interface, where the field information is the type and / or length of the input parameter field.
[0140] After successfully parsing the address information of the interface document according to the predetermined parsing rules and obtaining the basic data corresponding to all interfaces, the next step is to further dig into the field information of the interface input parameters of each interface. The field information here at least covers each input parameter field itself, as well as its corresponding type (such as integer, string, etc.) and length (for example, the input string length is specified to be between 10 and 20 characters).
[0141] When the input parameter fields include a required associated foreign key field, the interface is labeled, wherein the label is used to indicate that no additional processing is required for the required associated foreign key field when generating corresponding test case data for the interface.
[0142] Take the "add product" interface of an online shopping system as an example. The input fields may include "product name" (string type, length 20 to 50 characters), "product price" (floating point type), etc. Then, if a required foreign key field is found in these field information, such as "product category ID", this interface will be labeled.
[0143] This is because when generating the corresponding test case data, there may be some specific rules or situations that do not require additional processing for this required foreign key field. For example, in a test environment, this required foreign key field may already have a default setting or a specific processing method, so special operations on it can be ignored when generating test cases.
[0144] For example, in the above-mentioned "Add Product" interface, after labeling it, when generating test cases later, various changes and combinations of the required associated foreign key field "Product Category ID" will not be tested. Instead, the focus will be on other input parameter fields that need to be tested, thereby generating comprehensive and effective test cases more efficiently and specifically.
[0145] In a possible implementation, after parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, the method further includes:
[0146] S601, when basic data of any interface does not meet the data result requirements, the basic data of the interface is converted into a data format to obtain converted basic data of the interface, wherein the type of the converted basic data includes: a string type.
[0147] S602: Store the interface and the converted basic data of the interface in a message queue.
[0148] In this application example, after parsing the address information of the interface document according to the predetermined parsing rules and obtaining the basic data corresponding to all interfaces, these basic data will be checked. After that, the parsed data will be sorted and classified and stored in the message queue of the database.
[0149] For example, if it is found that the basic data of any interface does not meet the expected data result requirements, such as the data format is not uniform or does not meet the needs of subsequent processing, the data format conversion will be performed on it. For example, the basic data of a certain interface is originally a complex data structure, but in order to facilitate subsequent storage and processing in the message queue, it is converted into a string type, for example, converted into a dictionary format of basic data, and the converted basic data exists in the form of key-value pairs, such as the key is the module name, the value value is a list, and the content in the list is each interface information data under the interface module. After the conversion process, the interface and its converted basic data are stored in the message queue together.
[0150] For example, in a user information interface, the basic data obtained may contain multiple different types of data, such as numbers, arrays, etc. If it does not meet the subsequent processing requirements, it will be converted into a string type and then stored in the message queue together with the interface, waiting for subsequent test case generation and other modules to consume and use this data.
[0151] In this application example, the message queue component is deployed in advance, and the message queue component is asynchronously created according to the module name after the preliminary parsing of the data is completed. Each interface name under each interface module is used as the key of a piece of data, and other contents such as request mode, input parameters, etc. are written into a created dictionary, and the dictionary after the content is written is converted into a string. Finally, the code program pushes the string (the content format written into the message queue is a string, which is converted from the dictionary) to the corresponding message queue pipeline waiting to be consumed by the consumer program.
[0152] Through the above examples of the present application, comprehensive positive test case data and negative test case data are generated for each interface to test the interface more comprehensively.
[0153] Please refer to Figure 5 As shown, Figure 5 A schematic flow chart of an optional method for generating an interface test case provided by the present application is shown. The present application example may also include the following method steps:
[0154] S104, in response to the user's selection operation, determining the test case data corresponding to the selection operation;
[0155] S105, running the test case data, and generating execution record data according to the running result obtained by running the test case data.
[0156] For example, the tester selects the product name and execution content (including execution module and number of lines) to be executed in the client page of the test tool. After clicking execute, the server program starts to execute the corresponding interface use case, and the page generates an execution record data.
[0157] 1. Read test case data: Read by receiving the execution content parameter from the client. If there is no content, all test cases of all modules are read by default. If a specific execution module is given without a line number, all test cases under the module are read. If a specific execution module is given and a line number is given, the test cases with a specified number of lines under the specified module are read.
[0158] 2. Run test cases: Fill the test cases to be executed taken out in the above steps into the data-driven test suite that comes with the framework. The order of test case execution is fixed as adding interface, querying interface, modifying interface, and deleting interface. The program automatically judges and switches according to the test case request method field. During the specific operation process, it will automatically judge whether each test case execution result passes according to the expected response code, and store the test data in the Json file under the specified path.
[0159] 3. Query the running results: During the execution process, testers and other users can query the current execution record status in real time on the client page, which is divided into executing, completed and failed.
[0160] After all test cases are run, the program will automatically call the flexible lightweight multi-language test report framework all ure plug-in to obtain the Json file data, generate a report link in HTML format through commands and store it in the database table. Users can view the test report content according to the date on the client page and click the link to jump.
[0161] 4. Notification of execution results: After the test report is generated, the program will automatically query the latest generated data in the test report table, and send the report results to the responsible person's mailbox through a fixed e-mail template. The email recipient supports configuration modifications on the client page.
[0162] The generation and execution method of test cases based on the underlying interface of the code can greatly improve the test efficiency and test coverage, reduce personnel and time costs, and avoid missed tests and erroneous tests that may be caused by manual testing. It can even discover some problems that cannot be discovered by manual testing, thereby improving product quality.
[0163] It should be understood that the size of the serial numbers of the steps in the above 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.
[0164] Corresponding to the method for generating interface test cases in the above embodiment, Figure 6 is a schematic diagram of the structure of a device for generating interface test cases provided in an embodiment of the present application. The device can be implemented as part or all of a computer device by software, hardware, or a combination of both. The computer device can be Figure 7 Electronic equipment shown.
[0165] Reference Figure 6 , the interface test case generation device includes:
[0166] The acquisition unit 601 is used to acquire the interface document data of the system software to be tested, wherein the interface document data at least includes: address information of the interface document.
[0167] The parsing unit 602 is used to parse the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, wherein the predetermined parsing rule is formulated according to the document type of the interface document.
[0168] The generating unit 603 is used to generate corresponding test case data according to the basic data of each interface based on the predetermined test case generation rules, wherein at least the equivalence class division principle and the boundary value division principle are introduced into the predetermined test case generation rules.
[0169] Further, based on any of the above embodiments, as an example of the present application, the generating unit includes:
[0170] The partitioning subunit is used to partition a plurality of valid equivalence class rules and a plurality of invalid equivalence class rules according to an equivalence class partitioning principle and a boundary value partitioning principle.
[0171] The generation subunit is used to generate positive test case data and heterogeneous test case data according to the input parameter field information and field restriction conditions in the basic data of each interface, combined with the valid equivalence class rules and the invalid equivalence class rules.
[0172] Further, based on any of the above embodiments, as an example of the present application, each valid equivalence class rule and each invalid equivalence class rule respectively corresponds to a rule default value, generating a subunit, which is specifically used for:
[0173] If the field type of the input parameter field information is an integer type, then according to the boundary value of the input parameter field indicated in the field restriction condition, the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the integer input parameter field are determined; and / or
[0174] If the field type of the input parameter field information is a string type, then according to the limit length of the input parameter field indicated in the field restriction condition, the default value of the rule corresponding to the valid equivalence class rule and the invalid equivalence class rule of the string type input parameter field is determined; and / or
[0175] If the field type of the input parameter field information is non-mandatory, then the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the non-mandatory input parameter field are determined.
[0176] Positive test case data is generated according to the rule default values corresponding to the valid equivalence class rules, and negative test case data is generated according to the rule default values corresponding to the invalid equivalence class rules.
[0177] Further, based on any of the above embodiments, as an example of the present application, the device further includes:
[0178] The retaining unit is used to retain one positive test case data with the same equivalence class among the multiple positive test case data if the number of the positive test case data is multiple; and to retain multiple heterogeneous test case data if the number of the heterogeneous test case data is multiple.
[0179] Further, based on any of the above embodiments, as an example of the present application, the device further includes:
[0180] A determination unit is used to determine the title line of each form page in a pre-generated test case template, wherein the title line of each form page in the test case template is named using at least one of the following data: interface name, request method, interface routing, input parameter field, whether forward or reverse direction, and expected response result; according to the title line of each form page, the test case data is written into the test case template.
[0181] Optionally, in a possible implementation manner of the first aspect, the parsing unit includes:
[0182] The access subunit is used to request access to the interface module of the system software to be tested corresponding to the address information according to the address information of the interface document.
[0183] The calling sub-unit is used to call the corresponding predetermined parsing rules to traverse the interface module according to the document type of the interface document to obtain the basic data corresponding to all interfaces, wherein the basic data includes at least one of the following: interface name, interface routing, request method, input parameter field, and expected response result.
[0184] It should be noted that the interface test case generation device provided in the above embodiment is only illustrated by the division of the above-mentioned functional modules. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0185] The functional units and modules in the above embodiments 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, and the above integrated units may be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present application.
[0186] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0187] An embodiment of the present application further provides an electronic device, the electronic device comprising one or more processors and a memory;
[0188] The memory is coupled to one or more processors, and the memory is used to store computer program codes, the computer program codes include computer instructions, and the one or more processors call the computer instructions to enable the electronic device to execute the interface test case generation method shown above.
[0189] An embodiment of the present application also provides a computer-readable storage medium, in which computer instructions are stored; when the computer-readable storage medium is run on an electronic device, the electronic device executes the method for generating interface test cases shown above.
[0190] Computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. Computer-readable storage media may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes one or more available media integrated therein. Available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media, or semiconductor media (e.g., solid-state drives (SSDs)), etc.
[0191] An embodiment of the present application also provides a computer program product including computer instructions, which, when executed on an electronic device, enables the electronic device to execute the method for generating interface test cases shown above.
[0192] The computer storage medium and computer program product provided in the above-mentioned embodiments of the present application are used to execute the method provided above. Therefore, the beneficial effects that can be achieved can refer to the corresponding beneficial effects of the method provided above, and will not be repeated here.
[0193] In the above embodiments, it can also be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loading and executing computer instructions on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transmitted from a website site, computer, server or data center by wired (such as: coaxial cable, optical fiber, data subscriber line (Digital Subscriber Line, DSL)) or wireless (such as: infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access, or a data storage device such as a server or data center that includes one or more available media integrations. The available media may be magnetic media (such as floppy disks, hard disks, magnetic tapes), optical media (such as digital versatile discs (DVD)), or semiconductor media (such as solid-state drives (SSD)).
[0194] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the electronic device 700 may be a mobile phone, a computer, a digital broadcast terminal, a message transceiver device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0195] The memory 701 can be used to store computer software programs 702 and modules, and the processor 703 executes various functional applications and data processing of the electronic device by running the software programs and modules stored in the memory 701. The memory 701 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the electronic device (such as audio data, a phone book, etc.), etc. In addition, the memory 701 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0196] Among them, the processor 703 may include one or more processors such as a central processing unit, an application processor (AP), a baseband processor, etc. The processor may be the nerve center and command center of the wireless router. The processor 703 may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching instructions and executing instructions. The memory 701 may be used to store computer executable program codes, and the executable program codes include instructions. The processor 703 executes various functional applications and data processing of the network device by running the instructions stored in the memory. The memory 701 may include a program storage area and a data storage area, such as storing data of a sound signal to be played. For example, the memory may be a double rate synchronous dynamic random access memory DDR or a flash memory Flash, etc.
[0197] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0198] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments applied for herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0199] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are 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 multiple 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, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0200] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0201] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for generating an interface test case, characterized in that: include: Acquire interface document data of the system software to be tested, wherein the interface document data at least includes: address information of the interface document; Parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to each of all interfaces contained in the interface document, wherein the predetermined parsing rule is formulated according to the document type of the interface document; Based on the predetermined use case generation rules, corresponding test case data is generated according to the basic data of each of the interfaces, wherein at least an equivalence class partitioning principle and a boundary value partitioning principle are introduced into the predetermined use case generation rules.
2. The method according to claim 1, characterized in that The generating of corresponding test case data based on the predetermined test case generation rule and according to the basic data of each of the interfaces comprises: According to the equivalence class division principle and the boundary value division principle, a plurality of valid equivalence class rules and a plurality of invalid equivalence class rules are divided; According to the input parameter field information and field restriction conditions in the basic data of each of the interfaces, combined with the valid equivalence class rules and the invalid equivalence class rules, positive test case data and heterogeneous test case data are generated.
3. The method according to claim 2, characterized in that Each of the valid equivalence class rules and the invalid equivalence class rules respectively corresponds to a rule default value, and the positive test case data and the out-of-phase test case data are generated according to the input parameter field information and field restriction conditions in the basic data of each of the interfaces, in combination with the valid equivalence class rules and the invalid equivalence class rules, including: If the field type of the input parameter field information is an integer type, then according to the boundary value of the input parameter field indicated in the field restriction condition, the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the integer input parameter field are determined; and / or If the field type of the input parameter field information is a string type, then according to the limit length of the input parameter field indicated in the field restriction condition, the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the string type input parameter field are determined; and / or If the field type of the input parameter field information is non-mandatory, then determining the rule default values corresponding to the valid equivalence class rules and the invalid equivalence class rules of the non-mandatory input parameter field; Forward test case data is generated according to the rule default values corresponding to the valid equivalence class rules, and outward test case data is generated according to the rule default values corresponding to the invalid equivalence class rules.
4. The method according to claim 2, characterized in that: After generating the positive test case data and the negative test case data, the method further includes: If there are multiple positive test case data, retain one positive test case data with the same equivalence class among the multiple positive test case data; If there are multiple heterogeneous test case data, multiple heterogeneous test case data are retained.
5. The method according to claim 1, characterized in that After generating corresponding test case data according to the basic data of each of the interfaces based on a predetermined test case generation rule, the method further includes: Determine the title line of each form page in the pre-generated test case template, wherein the title line of each form page in the test case template is named using at least one of the following data: interface name, request method, interface route, input parameter field, whether forward or reverse, and expected response result; According to the title row of each form page, the test case data is written into the test case template.
6. The method according to any one of claims 1 to 5, characterized in that The step of parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document includes: According to the address information of the interface document, requesting access to the interface module of the system software to be tested corresponding to the address information; According to the document type of the interface document, the corresponding predetermined parsing rule is called to traverse the interface module to obtain the basic data corresponding to all the interfaces, wherein the basic data includes at least one of the following: interface name, interface routing, request method, input parameter field, and expected response result.
7. The method according to claim 6, characterized in that The step of calling the corresponding predetermined parsing rule according to the document type of the interface document and traversing the interface module to obtain basic data corresponding to all the interfaces includes: Obtaining a module name of the system software to be tested, wherein the module name is a name of an interface module obtained by dividing the system software to be tested according to code annotations; According to the document type of the interface document, the corresponding predetermined parsing rule is called to traverse the interface module according to the module name to obtain the basic data corresponding to all the interfaces, wherein each interface module corresponds to an interface category, and each interface category contains multiple interfaces.
8. The method according to any one of claims 1 to 5, characterized in that After parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, the method further includes: Obtaining field information of an input parameter field of each of the interfaces, wherein the field information is a type and / or length of the input parameter field; In the case where the input parameter fields include a required associated foreign key field, the interface is labeled, wherein the label is used to indicate that no additional processing is required on the required associated foreign key field when generating corresponding test case data for the interface.
9. The method according to any one of claims 1 to 5, characterized in that After parsing the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to all interfaces contained in the interface document, the method further includes: In the case that the basic data of any of the interfaces do not meet the data result requirements, the basic data of the interface are subjected to data format conversion processing to obtain converted basic data of the interface, wherein the type of the converted basic data includes: a string type; The interface and the converted basic data of the interface are stored in a message queue.
10. A device for generating interface test cases, characterized in that: include: An acquisition unit, used to acquire interface document data of the system software to be tested, wherein the interface document data at least includes: address information of the interface document; A parsing unit, configured to parse the address information of the interface document based on a predetermined parsing rule to obtain basic data corresponding to each of all interfaces contained in the interface document, wherein the predetermined parsing rule is formulated according to the document type of the interface document; A generating unit is used to generate corresponding test case data according to the basic data of each of the interfaces based on predetermined use case generation rules, wherein at least an equivalence class partitioning principle and a boundary value partitioning principle are introduced into the predetermined use case generation rules.
Citation Information
Cited By
Method and device for generating train number validity test case of vehicle-mounted system
CN119705543A
