Test case generation method and device and medium
By analyzing interface documents and using the pairwise algorithm to generate test cases, the inefficiency problem caused by manually modifying interface fields in traditional tests is solved, and efficient and automated test case generation is achieved, which improves the testing efficiency and code applicability.
Patent Information
- Application Number
- CN202411675095.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-12-29
- Filing Date
- 2024-11-21
- Publication Date
- 2025-07-08
AI Technical Summary
During traditional automated testing, the interface fields need to be frequently modified manually when generating test cases, resulting in inefficiency, especially when there are many scenario combinations.
By parsing the remark fields and other fields in the interface document, the pairwise algorithm is used to generate test cases, and combined with the random data generation library and the template engine library, the test case set is automatically generated and optimized.
It improves the efficiency of test case generation, reduces manual operations, ensures test quality, reduces the number of use cases, shortens test execution time, and enhances the universality of the code.
Smart Images

Figure CN120276971A_ABST
Abstract
Description
[0001] This application claims priority based on the invention patent application filed with the China National Patent Office on December 29, 2023, with the application number 202311872308.0 and the invention title "A Test Case Generation Method, Device, and Medium". This application incorporates the entire text of the above-mentioned Chinese patent application by reference. Technical Field
[0002] This application relates to the field of computers, and specifically to a test case generation method, device, and medium. Background Art
[0003] For an application program, various functions need to be tested.
[0004] In the traditional automated testing process, the interface needs to be frequently called. And in the process of creating automated interface test cases, if there are many scenario combinations involved, often only the fields of the relevant interface can be manually modified and saved as a new test case, which makes the test case generation process cumbersome and inefficient. Summary of the Invention
[0005] To solve the above problems, this application proposes a test case generation method, including:
[0006] Determine the interface document corresponding to the current interface, and based on the interface details returned in the interface document, determine the included remark field and other fields;
[0007] Parse the remark field, extract multiple first values included therein, and based on the interface document, traverse the other fields to determine the second values corresponding to the other fields;
[0008] Based on the pairwise algorithm, combine the second values with the first values to generate multiple test cases, optimize the multiple test cases, filter to obtain core test case data, and based on the core test case data, generate and return a test case set.
[0009] This application also proposes a test case generation method, including:
[0010] Determine the interface document corresponding to the current interface, and based on the interface details returned in the interface document, determine the included remark field and other fields;
[0011] Based on the parsing result of the interface details, extract the first value corresponding to the remark field, and traverse the other fields to extract the corresponding second values;
[0012] Based on the pairwise algorithm, combine the second value with the first value to generate multiple test cases, and generate and return a test case set based on the multiple test cases.
[0013] In one example, based on the interface details returned in the interface document, determine the included remark field and other fields, specifically including:
[0014] Obtain the corresponding module ID based on the interface document, obtain the corresponding interface details from the database according to the module ID, and store the interface details in the corresponding dictionary;
[0015] Among them, the interface details include a remark field and other fields, and the other fields include: name field, request method, variable type, request header, request parameters, variables;
[0016] Determine that the corresponding conditions are met, call the corresponding function and pass in the interface details, and store the returned test case list in the corresponding variable. Among them, the corresponding conditions include: the request method of the interface is POST, and the variable type is JSON;
[0017] Print and return the content of the corresponding variable through the log.
[0018] In one example, based on the interface details returned in the interface document, determine the included remark field and other fields, specifically including:
[0019] Obtain the corresponding module ID based on the interface document, obtain the corresponding interface details from the database according to the module ID, and store the interface details in the corresponding dictionary; among them, the interface details include a remark field and other fields;
[0020] Determine that the corresponding conditions are met, call the corresponding function and pass in the interface details, and store the returned test case list in the corresponding field; print and return the content of the corresponding field through the log to obtain the remark field and other fields after field assignment;
[0021] Preferably, the other fields include but are not limited to at least one of the following: name field, request method, variable type, request header, request parameters, variables; the corresponding conditions include: the request method of the interface is POST, and the variable type is JSON, and the method further includes:
[0022] When the request method in other fields is POST and the variable type in other fields is JSON, call the corresponding function and pass in the interface details, and store the returned list of test cases in the corresponding variable in other fields;
[0023] Print the content of the corresponding variable through the log and return it to obtain other fields after variable assignment and the remark field.
[0024] In one example, parse the remark field, extract multiple first values contained therein, and based on the interface document, traverse other fields to determine the corresponding second values of other fields, specifically including:
[0025] Parse the interface details to generate a template, and perform data filling based on the template;
[0026] Among them, for the fixed fields in the use case details, generate random data through a random data generation library to fill the fixed fields;
[0027] For the remark field that meets the use case generation standard in the use case details, perform preprocessing through a preset method and then fill the remark field.
[0028] In one example, based on the parsing result of the interface details, extract the first value corresponding to the remark field, and traverse other fields to extract the corresponding second values, including:
[0029] Parse the interface details to generate a data template, and fill the fields in the data template;
[0030] Based on the filled data template, extract the first value corresponding to the remark field, and traverse other fields to extract the corresponding second values.
[0031] In one example, filling the fields in the data template specifically includes:
[0032] For other fields in the data template, generate a data model through a random data generation library in advance, and generate random data through the data model to fill other fields with the generated random data;
[0033] For the remark field in the data template, perform preprocessing on the data in the data template through a preset method and then fill the remark field.
[0034] In one example, the interface details are parsed to generate a template, and data filling is performed based on the template, which specifically includes:
[0035] Check whether the incoming data is empty. If it is empty, throw a custom exception to indicate that the data is empty.
[0036] If it is not empty, determine whether the data is of dictionary type. If it is of dictionary type, traverse each key-value pair in the dictionary.
[0037] For each key-value pair, determine whether there is a type field.
[0038] If it exists, determine that the key-value pair belongs to a field, and continue to determine whether there is a remark field for this field.
[0039] If there is no remark field, or there is a remark field but no multiple candidate values are provided, or there is a remark field and multiple candidate values are provided but the pairwise algorithm is not used for optimization, generate test data of the corresponding type for this field.
[0040] Among them, for integer-type fields, random data is generated through a random data generation library.
[0041] For string-type fields, further determine whether there is a format field for this field.
[0042] If it exists and the value is date-time, generate a future date and time through a random data generation library. Otherwise, use the default string as the value of this field.
[0043] In one example, after preprocessing the data in the data template through a preset method, the remark field is filled, which specifically includes:
[0044] Check whether the incoming data is empty. If it is not empty, determine whether the data is of dictionary type. If it is of dictionary type, traverse each key-value pair in the dictionary.
[0045] For each key-value pair, determine whether there is a type field. If it exists, determine whether the type of the field in the key-value pair is a remark field, as well as the value information and value optimization information of the field in the key-value pair.
[0046] If there is no remark field, or there is a remark field but no multiple candidate values are provided, or there is a remark field and multiple candidate values are provided but it is not planned to use the pairwise algorithm for optimization, generate test data of the corresponding field type for the field in the key-value pair.
[0047] If there is a remark field, and multiple candidate values are provided, and the pairwise algorithm is planned to be used for optimization, then set the value of the remark field to a template expression, increment the value of the counter, and store the value of the remark field in the said dictionary.
[0048] In one example, based on the pairwise algorithm, combine the second value with the first value to generate multiple test cases, optimize the multiple test cases, filter out the core use case data, and based on the core use case data, generate and return a test case set, specifically including:
[0049] Generate the required materials based on the pairwise algorithm, and fill the materials into a pre-set expected value list, so as to combine the fields included in the interface details through the pairwise algorithm, and filter out the core use case data;
[0050] Based on the template engine library, convert the core use case data into the required dictionary format, add the dictionary format to the final list, and after encapsulation, return it to the upper layer.
[0051] In one example, based on the pairwise algorithm, combine the second value with the first value to generate multiple test cases, and generate and return a test case set based on the multiple test cases, specifically including:
[0052] Based on the pairwise algorithm, combine the second value with the first value to generate multiple test cases, optimize the multiple test cases, filter out the core use case data, and based on the core use case data, generate and return a test case set;
[0053] Preferably, the combining the second value with the first value based on the pairwise algorithm to generate multiple test cases, optimizing the multiple test cases, filtering out the core use case data, and generating and returning a test case set based on the core use case data includes:
[0054] Generate the required materials based on the pairwise algorithm, and fill the materials into a pre-set expected value list, so as to combine the second value with the first value through the pairwise algorithm to generate multiple test cases;
[0055] Optimize the multiple test cases and filter out the core use case data; based on the template engine library, convert the core use case data into the required dictionary format, add the dictionary format to the final list after encapsulation, and return the finally generated test case set to the upper layer.
[0056] In one example, the required materials are generated based on the pairwise algorithm, and the materials are filled into a preset expected value list to combine the fields included in the interface details through the pairwise algorithm and filter out the core use case data, specifically including:
[0057] Save the input data in the corresponding variable in the form of an ordered dictionary;
[0058] Determine the maximum threshold according to the number of parameters. Wherein, if the number of parameters is greater than 1, the maximum threshold is 2; otherwise, the maximum threshold is 1;
[0059] Create an empty remark list to save the generated test cases;
[0060] Traverse the test cases generated by using the AllPairs function, add each test case to the remark list, and during the traversal, filter the test cases through the filter_func parameter to only retain the core use case data.
[0061] In one example, based on the pairwise algorithm, the required materials are generated, and the materials are filled into a preset expected value list to combine the second value and the first value through the pairwise algorithm to generate multiple test cases, specifically including:
[0062] Save the input data in the corresponding variable in the form of an ordered dictionary; Determine the maximum threshold according to the number of parameters. Wherein, if the number of parameters is greater than 1, the maximum threshold is 2; otherwise, the maximum threshold is 1;
[0063] Create an empty remark list to save the generated test cases; Traverse the test cases generated by using the AllPairs function, add each test case to the remark list, and during the traversal, filter the test cases through the filter_func parameter to only retain the core use case data.
[0064] In one example, based on the template engine library, convert the core use case data into the required dictionary format and add the dictionary format to the final list, specifically including:
[0065] Convert the template into a string form based on the corresponding function and retain non-ASCII characters;
[0066] Loop through each expected value in the expected value list;
[0067] Wherein, during each loop, use the Template class to use the template string as the template and render the template through the expected value;
[0068] Convert the rendered template string into a Python object form based on the corresponding function and add it to the final list.
[0069] In one example, after encapsulation, return to the upper layer, specifically including:
[0070] Determine that the corresponding conditions are met, where the corresponding conditions include: the request method of the interface is POST, and the variable type is JSON;
[0071] Call the corresponding method to generate the data of the test case, save the data to the return list, and print the return list to the log.
[0072] In one example, based on the template engine library, convert the core test case data into the required dictionary format, add the dictionary format to the final list for encapsulation, and then return the finally generated test case set to the upper layer, specifically including:
[0073] Convert the data model into a string form in JSON format based on the corresponding function;
[0074] Loop through each expected value in the list of expected values;
[0075] Among them, in each loop, through the Template class, render the string form in JSON format with the expected value to replace the template tags in the string form in JSON format;
[0076] Use the rendered string form in JSON format as a set of specific test case data, deserialize it into test data in JSON format, and add the test data to the final list;
[0077] Determine that the corresponding conditions are met, where the corresponding conditions include: the request method of the interface is POST, and the variable type is JSON;
[0078] Call the corresponding method to generate the data of the test case, save the data to the return list, and print the return list to the log.
[0079] On the other hand, the present application also proposes a test case generation device, including:
[0080] At least one processor; and,
[0081] A memory communicatively connected to the at least one processor; wherein,
[0082] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the test case generation method as described in any of the above examples.
[0083] On the other hand, the present application also proposes a non-volatile computer storage medium storing computer-executable instructions, and the computer-executable instructions are configured as: the test case generation method described in any of the above examples.
[0084] The test case generation method proposed by the present application can bring the following beneficial effects:
[0085] Testers do not need to manually copy and paste, and can easily generate multiple test cases for a certain interface with one key. For the generated test cases, the number of test cases can be reduced as much as possible on the premise of ensuring the test quality, which also reduces the execution time and troubleshooting time of the test, and overall improves the iteration efficiency. And the specific code solution can be used independently of the platform, and only a small amount of modification is required based on the code, increasing the versatility. BRIEF DESCRIPTION OF THE DRAWINGS
[0086] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0087] Figure 1 is a schematic flowchart of the test case generation method in an embodiment of the present application;
[0088] Figure 2 is a schematic diagram of the code in the first case in an embodiment of the present application;
[0089] Figure 3 is a schematic diagram of the code in the second case in an embodiment of the present application;
[0090] Figure 4 is a schematic diagram of the code in the third case in an embodiment of the present application;
[0091] Figure 5 is a schematic diagram of the code in the fourth case in an embodiment of the present application;
[0092] Figure 6 is a schematic diagram of the code in the fifth case in an embodiment of the present application;
[0093] Figure 7 is a schematic diagram of test case generation in the traditional solution in an embodiment of the present application;
[0094] Figure 8 is a schematic diagram of test case generation in the present solution in an embodiment of the present application;
[0095] Figure 9 is a schematic diagram of the test case generation device in an embodiment of the present application;
[0096] Figure 10 This is a schematic flowchart of a test case generation method in another scenario in the embodiments of the present application. Detailed implementation manners
[0097] To make the objectives, technical solutions, and advantages of the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only a part rather than all of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.
[0098] The following will describe in detail the technical solutions provided in each embodiment of the present application with reference to the drawings.
[0099] As Figure 1 shown, the embodiments of the present application provide a test case generation method, including:
[0100] S101: Determine the interface document corresponding to the current interface, and based on the interface detailed information returned in the interface document, determine the included remark field and other fields.
[0101] Similarly, as Figure 10 shown, a test case generation method is provided, including step S1001: Determine the interface document corresponding to the current interface, and based on the interface detailed information returned in the interface document, determine the included remark field and other fields (i.e., fixed fields).
[0102] Among them, the interface document is a document obtained from the swagger interface platform, which can be called a swagger document. Of course, it can also be applied to other platforms based on requirements.
[0103] As Figure 2 shown, obtain the corresponding module ID based on the interface document, obtain the corresponding interface detailed information from the database according to the module ID, and store the interface detailed information in the corresponding dictionary (for example, _simple).
[0104] Among them, the interface detailed information includes the remark field and other fields. The other fields include at least one of the following: name field name, request method method, variable type variableType, request header header, request parameter param, variable variable. Among them, the request header, request parameter, and variable are stored in JSON format, so the json.loads() function needs to be used to convert them into Python objects.
[0105] Determine whether the corresponding conditions are met (including: the request method of the interface is POST, and the variable type is JSON). If so, call the corresponding function (for example, gener.gen_cases()) by passing in the interface details, and store the returned test case list in the corresponding variable (for example, end_data_list). Among them, the corresponding conditions include: the request method of the interface is POST, and the variable type is JSON. Then, print the content of the corresponding variable through the log and return it to obtain the remark field and other fields after field assignment.
[0106] S102: Parse the remark field, extract multiple first values contained therein, and based on the interface document, traverse the other fields to determine the second values corresponding to the other fields.
[0107] Similarly, as Figure 10 shown, step S1002: Based on the parsing result of the interface details, extract the first value corresponding to the remark field, and traverse the other fields to extract the corresponding second values.
[0108] Specifically, parse the interface details to generate a template (for example, api_data_model, also called the data template), and perform data filling based on the template (that is, fill the fields in the data template, so as to facilitate extracting the first value corresponding to the remark field based on the filled data template, and traversing the other fields to extract the corresponding second values). Among them, for the fixed fields (that is, the other fields) in the use case details (that is, the interface details), random data is generated through a random data generation library (for example, the faker library) for filling the fixed fields (for example, generate a data model in advance through the random data generation library and generate random data through the data model to fill the other fields with the generated random data); for the remark fields in the use case details that meet the use case generation standard (or for the remark fields in the data template), after preprocessing through a preset method, the remark fields are filled.
[0109] The interface details are obtained by analyzing and understanding the interface in detail. The template is the basis for interface calls. By filling in specific data, the interface is actually called. The data filling process is to fill specific parameter values into the template, then send a request to the interface, and obtain the returned data.
[0110] Furthermore, as Figure 3 shown, check whether the incoming data is empty. If it is empty, throw a custom exception SwaggepPapseEppop to indicate that the data is empty.
[0111] If it is not empty, then determine whether the data is of dictionary type. If it is of dictionary type, then traverse each key-value pair in the dictionary. For each key-value pair, determine whether there is a type field.
[0112] If it exists, then determine that the key-value pair belongs to a field, and continue to determine whether there is a remark field for this field. Or, when it exists, it is also possible to determine whether the type of the field in the key-value pair is a remark field, as well as the value information and value optimization information of the field in the key-value pair.
[0113] If the remark field does not exist, or the remark field exists but does not provide multiple candidate values, or the remark field exists, provides multiple candidate values, but does not use (or does not plan to use) the pairwise algorithm for optimization, then generate test data of the corresponding type for the field in the key-value pair.
[0114] If the remark field exists, provides multiple candidate values, and plans to use the pairwise algorithm for optimization, then set the value of the remark field to the template expression {{key}}, increment the value of the counter (multi_nums), and store the value of the remark field in the (pairwise_stuff) dictionary.
[0115] Among them, for fields of integer type, generate random data through a random data generation library (such as the faker library). For fields of string type, further determine whether there is a format field for this field.
[0116] If it exists and the value is date-time, then generate a future date and time through a random data generation library as the date-time. Otherwise, use the default string as the value of this field.
[0117] S103: Combine the second value with the first value based on the pairwise algorithm to generate multiple test cases, optimize the multiple test cases, screen out the core use case data, and generate and return a test case set based on the core use case data.
[0118] Similarly, as Figure 10 shown, step S1003: Combine the second value with the first value based on the pairwise algorithm to generate multiple test cases, and generate and return a test case set based on the multiple test cases.
[0119] Specifically, generate the required materials (e.g., pairwise_stuff) based on the pairwise algorithm, and fill the materials into a pre-set expected value list (e.g., expect_value_list) to combine the fields included in the interface details through the pairwise algorithm (it can also be said to combine the second value with the first value), thereby generating multiple test cases, optimizing the multiple test cases, and screening to obtain the core test case data.
[0120] Based on the template engine library, convert the core test case data into the required dictionary format, add the dictionary format to the final list, and encapsulate the finally generated test case set and return it to the upper layer.
[0121] Furthermore, as Figure 4 shown, save the input data in the corresponding variable (e.g., parameters) in the form of an ordered dictionary, and determine the maximum threshold (e.g., max_threshold) according to the number of parameters. Among them, if the number of parameters is greater than 1, the maximum threshold is 2; otherwise, the maximum threshold is 1.
[0122] Create an empty remark list (e.g., remark_list) to save the generated test cases, traverse the test cases generated by using the AllPairs function, add each test case to the remark list, and during the traversal process, screen the test cases through the filter_func parameter to only retain the core test case data.
[0123] As Figure 5 shown, based on the corresponding function (e.g., json.dumps()), convert the template (i.e., the data model, e.g., api_data_model) into a string form (e.g., JSON format string form), and set ensure_ascii = False to retain non-ASCII characters.
[0124] Loop through each expected value (e.g., expect_value) in the expected value list (e.g., expect_value_list). Among them, during each loop process, use the Template class to use the template string (e.g., api_data_model_str) as the template and render the template through the expected value (e.g., expect_value).
[0125] Based on the corresponding function (e.g., json.loads()), convert the rendered template string into a Python object form and add it to the final list (api_data_final_list).
[0126] Further, in each loop, through the Template class, render the JSON-formatted string in the form of an expected value to replace the template tags in the JSON-formatted string, use the rendered JSON-formatted string as a set of specific test case data, deserialize it into JSON-formatted test data, and add the test data to the final list.
[0127] As Figure 6 shown, determine that the corresponding conditions are met. The corresponding conditions include: the request method of the interface is POST, and the variable type is JSON.
[0128] Call the corresponding method (for example, gener.gen_cases(_simple[0])) to generate the data of the test case, save the data to the return list (for example, end_data_list), and call current_app.logger.info(end_data_list) to print the return list to the log.
[0129] For the interface specification format used by Swagger is relatively old, it is difficult to directly obtain and locate the fields required by the interface and modify them when the dictionary arrays are loop-nested, and there is no ready-made and mature library in the entire Python ecosystem. This solution can accurately identify and locate the final fields by extracting the feature values in the specification, and provide different implementation solutions that can be flexibly switched in the code.
[0130] The data generated using the Pairwise algorithm is not concise enough and there is redundant data. The current solution combines Jinja2, a relatively mature third-party library in Python, and through the special characters injected into the interface data in the early stage. It can intelligently locate the fields to be generated and inject the data into the dictionary in batches and return.
[0131] Testers do not need to manually copy and paste, and can easily generate multiple test cases for a certain interface with one click. For the generated test cases, on the premise of ensuring the test quality, the number of test cases can be reduced as much as possible, which also reduces the execution time and troubleshooting time of the test, and overall improves the iteration efficiency. And the specific code solution can be used independently of the platform, and only a small amount of modification is required based on the code, which increases the versatility.
[0132] In one embodiment, different numerical values are represented by letters for the following test scenarios:
[0133] Status: M, O, P;
[0134] Platform: W, L, I;
[0135] Type: C, E;
[0136] In the traditional solution, 18 test cases as shown in Figure 7 can be generated. However, when using the solution in the embodiments of the present application, only 9 test cases as shown in Figure 8 are generated. The number of test cases is reduced by 50%. Moreover, the more dimensions there are, the more obvious this becomes. When there are 10 dimensions, the number of test cases in the traditional solution can be: 4 * 4 * 4 * 4 * 3 * 3 * 3 * 2 * 2 * 2 = 55296, while only 24 are generated through the present solution, which is 0.04% of the original scale of test cases.
[0137] As shown in Figure 9 , the embodiments of the present application also propose a test case generation device, including:
[0138] At least one processor; and,
[0139] A memory communicatively connected to the at least one processor; wherein,
[0140] The memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is enabled to execute the test case generation method as described in any of the above embodiments.
[0141] The embodiments of the present application also propose a non - volatile computer storage medium storing computer - executable instructions, and the computer - executable instructions are set to: the test case generation method as described in any of the above embodiments.
[0142] The various embodiments in the present application are all described in a progressive manner. For the parts that are the same or similar among the various embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for the relevant parts, reference can be made to the partial description of the method embodiments.
[0143] The device and medium provided by the embodiments of the present application correspond one - to - one with the method. Therefore, the device and medium also have beneficial technical effects similar to those of the corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the device and medium are not elaborated here.
[0144] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0145] The present application is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, as well as the combination of flows 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 the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0146] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that implement the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0147] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are performed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0148] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0149] Memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
[0150] A computer-readable medium includes both permanent and non-permanent, removable and non-removable media and can implement information storage by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer-readable medium does not include transitory computer-readable media such as modulated data signals and carrier waves.
[0151] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or apparatus comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or apparatus. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising the element.
[0152] The above description is only for the embodiments of the present application and is not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A test case generation method, characterized in that, Including: Determine the interface document corresponding to the current interface, and based on the interface details returned in the interface document, determine the included remark field and other fields; Based on the parsing result of the interface details, extract the first value corresponding to the remark field, and traverse the other fields to extract the corresponding second values; Based on the pairwise algorithm, combine the second values with the first values to generate multiple test cases, and generate and return a test case set based on the multiple test cases.
2. The method according to claim 1, wherein Based on the interface details returned in the interface document, determine the included remark field and other fields, specifically including: Obtain the corresponding module ID based on the interface document, obtain the corresponding interface details from the database according to the module ID, and store the interface details in the corresponding dictionary; wherein, the interface details include the remark field and other fields; Determine to meet the corresponding conditions, call the corresponding function and pass in the interface details, and store the returned test case list in the corresponding field; print and return the content of the corresponding field through the log to obtain the remark field and other fields after field assignment; Preferably, the other fields include but are not limited to at least one of the following: name field, request method, variable type, request header, request parameter, variable; the corresponding conditions include: the request method of the interface is POST, and the variable type is JSON, and the method further includes: When the request method in the other fields is POST and the variable type in the other fields is JSON, call the corresponding function and pass in the interface details, and store the returned test case list in the corresponding variable in the other fields; Print and return the content of the corresponding variable through the log to obtain the other fields and the remark field after variable assignment.
3. The method according to claim 1, wherein Based on the parsing result of the interface details, extract the first value corresponding to the remark field, and traverse the other fields to extract the corresponding second values, including: Parse the interface details to generate a data template, and fill in the fields in the data template; Based on the filled data template, extract the first value corresponding to the remark field, and traverse the other fields to extract the corresponding second values.
4. The method according to claim 1, wherein Filling in the fields in the data template specifically includes: For the other fields in the data template, pre-generate a data model through a random data generation library, and generate random data through the data model to fill in the other fields with the generated random data; For the remark field in the data template, after preprocessing the data in the data template through a preset method, fill in the remark field.
5. The method according to claim 4, wherein After preprocessing the data in the data template through a preset method, filling in the remark field specifically includes: Check whether the incoming data is empty. If it is not empty, determine whether the data is of dictionary type. If it is of dictionary type, traverse each key-value pair in the dictionary; For each key-value pair, determine whether there is a type field; if there is, determine whether the type of the field in the key-value pair is a remark field, as well as the value information and value optimization information of the field in the key-value pair; If there is no remark field, or there is a remark field but no multiple candidate values are provided, or there is a remark field and multiple candidate values are provided but the pairwise algorithm is not planned to be used for optimization, generate test data of the corresponding field type for the field in the key-value pair; If there is a remark field, and multiple candidate values are provided, and the pairwise algorithm is planned to be used for optimization, set the value of the remark field as a template expression, increment the value of the counter, and store the value of the remark field in the dictionary.
6. The method according to claim 1, characterized in that Based on the pairwise algorithm, combine the second value with the first value to generate multiple test cases, and generate and return a test case set based on the multiple test cases, specifically including: Based on the pairwise algorithm, combine the second value with the first value to generate multiple test cases, optimize the multiple test cases, filter out the core use case data, and generate and return a test case set based on the core use case data; Preferably, the step of combining the second value with the first value based on the pairwise algorithm to generate multiple test cases, optimizing the multiple test cases, filtering out the core use case data, and generating and returning a test case set based on the core use case data includes: Generate the required materials based on the pairwise algorithm and fill the materials into a pre-set expected value list to combine the second value with the first value through the pairwise algorithm to generate multiple test cases; Optimize the multiple test cases and filter out the core use case data; based on the template engine library, convert the core use case data into the required dictionary format, add the dictionary format to the final list for encapsulation, and then return the finally generated test case set to the upper layer.
7. The method according to claim 6, characterized in that, Generate the required materials based on the pairwise algorithm and fill the materials into a pre-set expected value list to combine the second value with the first value through the pairwise algorithm to generate multiple test cases, specifically including: Save the input data in the corresponding variable in the form of an ordered dictionary; determine the maximum threshold according to the number of parameters, where if the number of parameters is greater than 1, the maximum threshold is 2, otherwise, the maximum threshold is 1; Create an empty remark list to save the generated test cases; traverse the test cases generated by the AllPairs function, add each test case to the remark list, and during the traversal, filter the test cases through the filter_func parameter to only retain the core test case data.
8. The method according to claim 6, characterized in that, Based on the template engine library, convert the core test case data into the required dictionary format, add the dictionary format to the final list for encapsulation, and then return the finally generated test case set to the upper layer, specifically including: Convert the data model into a JSON format string based on the corresponding function; Loop through each expected value in the expected value list; Among them, during each loop, through the Template class, render the JSON format string with the expected value to replace the template tags in the JSON format string; Use the rendered JSON format string as a set of specific test case data, deserialize it into JSON format test data, and add the test data to the final list; Determine that the corresponding conditions are met, and the corresponding conditions include: the request method of the interface is POST, and the variable type is JSON; Call the corresponding method to generate the data of the test case, save the data to the return list, and print the return list to the log.
9. A test case generation device, characterized in that, Include: At least one processor; And, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the test case generation method described in any one of claims 1 to 8.
10. A non-volatile computer storage medium stores computer-executable instructions, characterized in that, The computer-executable instructions are set to: the test case generation method described in any one of claims 1 to 8.