A test case generation method, device, equipment, storage medium and product

By having multiple intelligent agents work together, high-quality test cases of various types are generated based on current API request data and historical data, which solves the problem of low test case quality in existing technologies and achieves rich types and high stability of test case generation.

CN120849295BActive Publication Date: 2026-02-24CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511352126.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-22
Publication Date
2026-02-24
Estimated Expiration
2045-09-22

AI Technical Summary

Technical Problem

Existing methods for generating API test cases rely on a large amount of historical test case data, making it difficult to effectively mine the constraint rules of parameters. This results in low-quality test cases, especially as the complexity of the software system increases, with poor correlation between test cases and API request data and limited types.

Method used

By having multiple intelligent agents work together, high-quality test case sets of various types are generated based on current API request data, target historical API request data, and historical test case sets to be learned. These include a referee intelligent agent and multiple intelligent agents that generate test cases. Different types of test cases are generated through similarity filtering and type discrimination. A detection intelligent agent is introduced to filter out low-quality test cases.

Benefits of technology

It improves the variety and scenario coverage of test cases, simplifies the generation process, avoids the max_token limit when a single agent generates a large number of test cases, and ensures the stability and high quality of the generation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120849295B_ABST
    Figure CN120849295B_ABST
Patent Text Reader

Abstract

The application discloses a test case generation method and device, equipment, a storage medium and a product. The method comprises the following steps: obtaining M current application program interface request data, wherein M is an integer greater than or equal to 1; obtaining target historical application program interface request data related to each current application program interface request data and a to-be-learned historical test case set corresponding to each current application program interface request data; generating a plurality of test case sets corresponding to each current application program interface request data by a plurality of agents based on each current application program interface request data, the target historical application program interface request data related to each current application program interface request data and the to-be-learned historical test case set corresponding to each current application program interface request data, wherein the plurality of agents comprise a referee agent for type discrimination of historical test cases and a plurality of agents for generating test cases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a test case generation method, apparatus, device, storage medium, and product. Background Technology

[0002] Currently, the main method for generating test cases for Application Program Interfaces (APIs) is to use machine learning or deep learning methods to learn the value rules of interface parameters in the API, and then assign values ​​to the interface parameters in the API according to the learned value rules to generate test cases corresponding to the API in batches.

[0003] However, because current test case generation methods rely on a large amount of historical test case data, it is difficult to effectively mine the constraint rules of parameters. Furthermore, multiple parameters are tested simultaneously. As the complexity of software systems increases, the test cases generated by this method suffer from low overall quality. Summary of the Invention

[0004] This application provides a test case generation method, apparatus, device, storage medium, and product.

[0005] The technical solution of this application is implemented as follows:

[0006] A test case generation method, comprising:

[0007] Get M current application interface request data, where M is an integer greater than or equal to 1;

[0008] Obtain the target historical application interface request data related to each current application interface request data and the set of historical test cases to be learned corresponding to each current application interface request data;

[0009] Through multiple intelligent agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data, multiple test case sets corresponding to each current application interface request data are generated. The multiple intelligent agents include: a referee intelligent agent for judging the type of historical test cases and multiple intelligent agents for generating test cases.

[0010] A test case generation device, comprising:

[0011] The acquisition unit is set to acquire M current application interface request data, where M is an integer greater than or equal to 1;

[0012] The acquisition unit is configured to acquire the target historical application interface request data related to each current application interface request data and the set of historical test cases to be learned corresponding to each current application interface request data.

[0013] The generation unit is configured to generate multiple test case sets corresponding to each current application interface request data by using multiple intelligent agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data. The multiple intelligent agents include: a referee intelligent agent for judging the type of historical test cases and multiple intelligent agents for generating test cases.

[0014] An electronic device includes: a processor and a memory for storing a computer program capable of running on the processor, wherein, when the processor runs the computer program, it performs the steps of any of the methods described above.

[0015] A storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the above methods.

[0016] A computer program product includes a computer program that, when executed by a processor, implements the steps of any of the above methods.

[0017] This application provides a test case generation method that, through the collaborative work of multiple intelligent agents, generates multiple test case sets corresponding to each current application interface request data. These sets are based on the current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data. This enables the generation of high-quality, diverse test case sets and simplifies the process of generating multiple test cases. Attached Figure Description

[0018] Figure 1 This is a schematic diagram of a first process for a test case generation method provided in an embodiment of this application;

[0019] Figure 2 This is a second flowchart illustrating a test case generation method provided in an embodiment of this application;

[0020] Figure 3 A flowchart illustrating a test case generation scenario provided in an embodiment of this application;

[0021] Figure 4A flowchart illustrating a scenario for outputting standardized API request data, provided as an embodiment of this application;

[0022] Figure 5 A flowchart illustrating a similarity calculation scenario provided in an embodiment of this application;

[0023] Figure 6 A flowchart illustrating a test case generation scenario based on the collaboration of multiple intelligent agents, provided for an embodiment of this application;

[0024] Figure 7 A flowchart illustrating a scenario for automatically filtering test cases provided in an embodiment of this application;

[0025] Figure 8 This is a schematic diagram of the structure of a test case generation device provided in an embodiment of this application;

[0026] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0027] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0028] It should be understood that the phrases "embodiments of this application" or "foreign embodiments" throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "embodiments of this application" or "in the foreign embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential 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 this application. The sequence numbers of the above-described embodiments are merely descriptive and do not represent the superiority or inferiority of the embodiments.

[0029] It should be noted that the terms "first, second, and third" used in the embodiments of this application are merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0030] The technical terms used in this application are explained below.

[0031] An intelligent agent is a system possessing intelligence, capable of perceiving, reasoning, making decisions, and executing actions within a given environment. It consists of three parts: a brain, perception, and action. An intelligent agent can perceive its environment through various sensors and influence it by performing actions. The brain, acting as the controller, handles basic tasks such as memory, thinking, and decision-making. It can typically be an artificial intelligence model (such as a Large Language Model (LLM)) or a tool. The perception part enables the agent to perceive and process multimodal information from the external environment. The action part allows the agent to use tools to execute processing logic and output results (influencing the surrounding environment). In this specification, an intelligent agent generally refers to a software entity that possesses knowledge of the test case domain, encapsulates certain processing logic, and can invoke artificial intelligence models and tools to execute that logic.

[0032] Prompt templates: also known as prompt engineering or prompt word engineering, refer to a carefully designed questioning paradigm used in the design of instructions related to large models (such as LLM).

[0033] Currently, API test case generation primarily involves using machine learning or deep learning methods to learn the value rules of API interface parameters. Then, based on these learned rules, values ​​are assigned to the API parameters, generating test cases in batches. For example, some solutions generate corresponding API test chain groups by depth-first traversing dependency subtrees. Deep learning is used to extract the semantic and value features of the parameter descriptions of the target API. Test case generation models and parameter features are pre-trained using a large amount of historical data to generate test cases for the API test chains in batches, which are then used for program testing. Another approach involves parsing actual API service traffic data to obtain the actual parameter values. Then, based on these actual parameter values ​​and the API service's feature information, the value rules for all parameters are learned. Values ​​are assigned to the API parameters according to these rules, generating multiple test cases for the application service.

[0034] It is evident that current test case generation methods rely on undifferentiated training with a large amount of historical test case data, making it difficult to effectively uncover parameter constraint rules. Poor learning of parameter value rules leads to low accuracy in the generated test cases. Furthermore, as software systems become more complex, test cases generated in this way show poor relevance to API request data and exhibit a limited variety of test case types. Therefore, current test case generation methods suffer from overall low quality in the generated test cases.

[0035] Figure 1 This is a schematic diagram of the first process of a test case generation method provided in an embodiment of this application. The following will be combined with... Figure 1 Please provide an explanation. For example... Figure 1 As shown, the test case generation method may include the following steps S101 to S103:

[0036] Step S101: Obtain M current application interface request data, where M is an integer greater than or equal to 1;

[0037] Step S102: Obtain the target historical application interface request data related to each current application interface request data and the set of historical test cases to be learned corresponding to each current application interface request data;

[0038] Step S103: Using multiple intelligent agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data, multiple intelligent agents are generated for each current application interface request data. The multiple intelligent agents include: a referee intelligent agent for judging the type of historical test cases and multiple intelligent agents for generating test cases.

[0039] In some exemplary embodiments, step S102 may include the following steps:

[0040] Obtain N historical application interface request data, where N is an integer greater than or equal to 2;

[0041] Determine the similarity between each current application interface request data and N historical application interface request data respectively;

[0042] From N historical application interface request data, select historical application interface request data that meet the preset conditions for similarity, and use them as the target historical application interface request data related to each current application interface request data.

[0043] From the historical test case set, select the historical test case set corresponding to the target historical application interface request data related to each current application interface request data, and use it as the historical test case set to be learned for each current application interface request data.

[0044] Thus, the test case generation method provided in this application, through the collaborative work of multiple intelligent agents, generates multiple test case sets corresponding to each current API request data based on each current API request data, the target historical application interface request data related to each current API request data, and the historical test case set to be learned corresponding to each current API request data. Since the target historical application interface request data is related to the current API request data, and the historical test case set to be learned is strongly correlated with the current API request data, the collaborative work of multiple intelligent agents can generate high-quality multiple test cases, simplifying the process of generating multiple test cases. Furthermore, it avoids the truncation situation caused by the maximum token count (max_token) limit when a single agent generates a large number of test cases, thereby ensuring high stability in the test case generation process.

[0045] Figure 2 This is a schematic diagram of a second process for a test case generation method provided in an embodiment of this application. The following will be combined with... Figure 2 Please provide an explanation. For example... Figure 2 As shown, the method may include the following steps S201 to S205:

[0046] Step S201: Obtain M current application interface request data and N historical application interface request data, where M is an integer greater than or equal to 1 and N is an integer greater than or equal to 2.

[0047] Step S202: Determine the similarity between each current application interface request data and N historical application interface request data;

[0048] Step S203: Select historical application interface request data that meet the preset similarity conditions from N historical application interface request data, and use them as target historical application interface request data related to each current application interface request data.

[0049] Step S204: Select the historical test case set corresponding to the target historical application interface request data related to each current application interface request data from the historical test case set, and use it as the historical test case set to be learned for each current application interface request data.

[0050] Step S205: Using multiple agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data, multiple intelligent agents are generated to provide various test case sets for each current application interface request data. These multiple intelligent agents include: a referee intelligent agent for type discrimination of historical test cases and multiple intelligent agents for generating test cases. For example, depending on the type of the historical test cases, the types of the multiple intelligent agents used to generate test cases are different, and correspondingly, the types of the various test case sets are different.

[0051] Here, application programming interface (API) request data refers to the request data sent during the process of obtaining data by calling the API.

[0052] Thus, in the test case generation method of this application embodiment, by selecting historical API request data that meets preset similarity conditions from N historical API request data, and using these as target historical API request data related to each current API request data, it can be ensured that the target historical API request data is related to the current API request data. Furthermore, by selecting historical test case sets corresponding to the target historical API request data related to each current API request data from the historical test case set, and using these as the learning set of historical test cases for each current API request data, the targeting of the learning set of historical test cases can be enhanced, ensuring a strong correlation between the current API request data and the corresponding learning set of historical test cases. Therefore, through the collaborative work of multiple agents, high-quality test cases of different types can be generated, improving the richness of generated test case types, increasing the scenario coverage of generated test cases, and simplifying the process of generating various types of test cases. Moreover, it can avoid truncation due to the max_token limit when a single agent generates a large number of test cases, thus ensuring high stability in the test case generation process. In this way, high-quality test cases can be obtained.

[0053] In some exemplary embodiments, step S202 may include the following steps:

[0054] Based on the data requested by each current application interface, create a first dictionary corresponding to the data requested by each current application interface.

[0055] Based on N historical application interface request data, create N second dictionaries that correspond one-to-one with the N historical application interface request data;

[0056] Determine the similarity between the first dictionary and N second dictionaries corresponding to each current application interface request data, and use this as the similarity between each current application interface request data and N historical application interface request data.

[0057] In some exemplary embodiments, determining the similarity between a first dictionary and N second dictionaries corresponding to each current application interface request data may include the following steps:

[0058] Based on the m first key-value pairs of the first dictionary corresponding to the p-th current application interface request data and the n second key-value pairs of the q-th second dictionary among the N second dictionaries, perform a weight calculation operation to obtain the weights of all first key-value pairs in the first dictionary corresponding to the p-th current application interface request data;

[0059] The sum of the weights of all first key-value pairs in the first dictionary corresponding to the p-th current application interface request data is determined as the similarity between the first dictionary corresponding to the p-th current application interface request data and the q-th second dictionary, and is used as the similarity between the first dictionary corresponding to each current application interface request data and N second dictionaries; where m and n are integers greater than or equal to 2, p is an integer greater than or equal to 1 and less than or equal to M, and q is an integer greater than or equal to 1 and less than or equal to N.

[0060] In some exemplary embodiments, the weight calculation operation may include the following steps:

[0061] The i-th first key-value pair in the first dictionary corresponding to the p-th current application interface request data is matched with all the second key-value pairs in the q-th second dictionary to obtain the matching result of the i-th first key-value pair; where i is an integer greater than or equal to 1 and less than or equal to m.

[0062] Based on the correspondence between the matching results and the preset penalty coefficient, determine the target penalty coefficient corresponding to the matching result of the i-th first key-value pair;

[0063] The weight of the i-th first key-value pair is determined based at least on the target penalty coefficient and the preset initial weight.

[0064] In some exemplary embodiments, determining the target penalty coefficient corresponding to the matching result of the i-th first key-value pair based on the correspondence between the matching result and the preset penalty coefficient may include the following steps:

[0065] When the matching result of the i-th first key-value pair is that the key in the i-th first key-value pair does not match the key in any of the second key-value pairs in the q-th second dictionary, the difference between 1 and the preset first penalty value is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair.

[0066] or,

[0067] When the matching result of the i-th first key-value pair is that the key in the i-th first key-value pair matches the same key in the q-th second dictionary, the value corresponding to the same key in the q-th second dictionary is a single value type, and the value of the same key in the i-th first key-value pair is inconsistent with the value corresponding to the q-th second dictionary, the difference between 1 and the preset second penalty value is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair;

[0068] or,

[0069] When the matching result of the i-th first key-value pair is that the key in the i-th first key-value pair matches the same key in the q-th second dictionary, the value corresponding to the same key in the q-th second dictionary is an iterable value type, and the value of the same key in the i-th first key-value pair is inconsistent with all elements in the value corresponding to the q-th second dictionary, the difference between 1 and the preset third penalty value is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair.

[0070] In some exemplary embodiments, determining the weight of the i-th first key-value pair, at least based on the target penalty coefficient and a preset initial weight, may include the following steps:

[0071] Determine the key intersection between the first dictionary corresponding to the p-th current application interface request data and the q-th second dictionary among N second dictionaries;

[0072] When the key intersection is not empty, the remaining key penalty coefficient is determined based on the number of common keys in the key intersection and the length of the qth second dictionary among the N second dictionaries. The product of the target penalty coefficient, the preset initial weight, and the remaining key penalty coefficient is determined as the weight of the i-th first key-value pair. Alternatively, when the key intersection is empty, the product of the target penalty coefficient and the preset initial weight is determined as the weight of the i-th first key-value pair.

[0073] In some exemplary embodiments, selecting historical application interface request data that meets preset similarity conditions from N historical application interface request data and using it as target historical application interface request data related to each current application interface request data may include the following steps:

[0074] Sort the similarity between each current application interface request data and N historical application interface request data in descending order to obtain the similarity sequence corresponding to each current application interface request data.

[0075] The historical application interface request data corresponding to the first similarity (i.e. the maximum similarity) in the similarity sequence of each current application interface request data is used as the target historical application interface request data related to each current application interface request data.

[0076] In some exemplary embodiments, after generating multiple test case sets corresponding to each current application interface request data in step S205, the method may further include the following steps:

[0077] Determine whether the number of test cases in the test case set is less than a preset threshold;

[0078] When the number of test cases in the test case set is less than a preset threshold, the historical application interface request data corresponding to the next similarity of the similarity of the target historical application interface request data in the similarity sequence corresponding to the current application interface request data is taken as the new target historical application interface request data. Based on the new target historical application interface request data, multiple test case sets corresponding to each current application interface request data are regenerated.

[0079] The preset threshold can be set by those skilled in the art according to the actual scenario.

[0080] Thus, in this embodiment, when the number of test cases in the test case set generated based on the target historical application interface request data determined by the first similarity (i.e., the maximum similarity) in the similarity sequence is less than a preset threshold, new target historical application interface request data can be determined based on the next similarity (i.e., the second largest similarity) of the first similarity in the similarity sequence. Based on the new target historical application interface request data, steps S204 to S205 are re-executed to regenerate multiple test case sets of different types corresponding to each current application interface request data, until the number of test cases generated in the final test case set is greater than or equal to the preset threshold. This ensures the reliability of the generated test cases.

[0081] In some exemplary embodiments, the multiple agents used to generate test cases may include: first agents, second agents, and third agents of different types; step S205, through the multiple agents, generates multiple test case sets corresponding to each current application interface request data based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data, which may include the following steps:

[0082] By using the referee agent, based on the target historical application interface request data related to each current application interface request data, the type of the historical test cases to be learned in the historical test case set to be learned corresponding to each current application interface request data is determined, and the first type of historical test case set, the second type of historical test case set, and the third type of historical test case set corresponding to each current application interface request data are obtained.

[0083] The first intelligent agent generates a first type of test case set based on each current application interface request data and its corresponding first type of historical test case set;

[0084] The second intelligent agent generates a second type of test case set based on each current application interface request data and its corresponding second type of historical test case set;

[0085] A third-class test case set is generated by using a third intelligent agent based on the current application interface request data and its corresponding third-class historical test case set.

[0086] In some exemplary embodiments, the types of historical test cases may include: historical forward test cases, historical reverse test cases for required parameters, and historical reverse test cases for non-required parameters.

[0087] In some exemplary embodiments, depending on the test case category, the historical test cases in the first set of historical test cases can be historical forward test cases, the historical test cases in the second set of historical test cases can be historical reverse test cases for required parameters, and the historical test cases in the third set of historical test cases can be historical reverse test cases for non-required parameters.

[0088] In some exemplary embodiments, depending on the test case category, the first agent can be a positive agent for generating positive test cases, the second agent can be a negative-RT agent for generating test cases for required parameters, and the third agent can be a negative-FT agent for generating reverse test cases for non-required parameters.

[0089] In some exemplary embodiments, based on the test case category, the test cases in the first type of test case set can be forward test cases, the test cases in the second type of test case set can be reverse test cases for required parameters, and the test cases in the third type of test case set can be reverse test cases for non-required parameters.

[0090] In some exemplary embodiments, step S205, through multiple intelligent agents, generates multiple test case sets corresponding to each current application interface request data, based on each current application interface request data, target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data. This may include the following steps:

[0091] Through multiple intelligent agents, based on preset prompts, and using each current application interface request data, target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data, multiple test case sets are generated for each current application interface request data.

[0092] In some exemplary embodiments, a preset prompting process is used to indicate one or more of the following information to the agent: whether the parameter type in the current parameters is a required type or not, the meaning of the parameter name in the test case, the requirements and specifications for outputting test cases, and test cases generated by learning samples, etc.

[0093] Thus, in this embodiment, by having the referee agent collaborate with different types of first, second, and third agents, high-quality test cases of various types can be generated. This enhances the richness of generated test case types, improves the scenario coverage of generated test cases, and simplifies the process of generating multiple types of test cases. Furthermore, it avoids truncation due to the `max_token` limit when a single agent generates a large number of test cases, thereby ensuring high stability in the test case generation process. This results in high-quality test cases.

[0094] In some exemplary embodiments, each test case set may include: test cases and their corresponding expected response data; after generating multiple test case sets corresponding to each current application interface request data in step S205, the method may further include the following steps:

[0095] By detecting intelligent agents, based on the current application interface request data and its corresponding multiple test case sets, real response data corresponding to each test case in multiple test case sets is generated;

[0096] Compare the expected response data with the actual response data for each test case;

[0097] Remove test cases from multiple test case sets where the expected response data does not match the actual response data.

[0098] In some exemplary embodiments, the response data may include: response status and status code. The response status may include OK (success), ERROR (error), EXCEPTION (exception), ALARM (alarm), and FORBIDDEN (prohibition), etc.; the status code may include 200 (success), 400 (syntax or format error in the client request), 404 (server could not find the requested resource), etc.

[0099] Thus, in the test case generation method of this application embodiment, after generating the test case set, a test case self-examination mechanism can be introduced. The detection agent predicts the actual response output of the current API input and the generated test cases, and compares it with the expected response data, thereby filtering out low-quality test cases and avoiding ineffective work by testers.

[0100] In some exemplary embodiments, before obtaining M current application interface request data and N historical application interface request data in step S201, the method may further include the following steps:

[0101] Obtain M initial application interface request data;

[0102] Using an intelligent agent for data format standardization, based at least on a preset prompting process, M initial application interface request data are standardized to obtain M current application interface request data.

[0103] In some exemplary embodiments, the M initial API request data are standardized by an agent for data format standardization, based at least on a preset prompting process, to obtain M current API request data. This can be achieved through the following steps:

[0104] Using an intelligent agent (Unification-Agent) for data format standardization, key information is extracted from M initial API request data based on a preset prompting process; the key information may include: API parameter information;

[0105] The key information of M initial API request data is filled into a preset standardized API request data template to obtain M standardized API request data, and the M standardized API request data are used as the M current API request data.

[0106] In some exemplary embodiments, the initial API data can be obtained by user input based on the actual scenario. For example, depending on the data format, the initial application interface request data may include: API request data described in natural language, API request data in JavaScript Object Notation (JSON) format, API request data in Extensible Markup Language (XML) format, etc. Of course, other data formats are also possible for API request data; however, this embodiment of the application does not limit this.

[0107] In some exemplary embodiments, the data format of standardized API request data can be JSON format.

[0108] Thus, in the test case generation method of this application embodiment, the intelligent agent used for data format standardization processing can realize the conversion of API request data in multiple data formats, and can solve the API compatibility and consistency problems.

[0109] For example, in a feasible test case generation scenario based on multi-agent collaboration, such as Figure 3 As shown, the test case generation system may include: a unified agent (Unification-Agent), a judge agent (Judge-Agent) for type discrimination of the historical test cases to be learned in the set of historical test cases to be learned, a first agent (Positive-Agent) for generating positive test cases, a second agent (Negative-RT-Agent) for generating negative test cases for required parameters, a third agent (Negative-FT-Agent) for generating negative test cases for non-required parameters, and a check agent (Check-Agent). The scheme of this application can be divided into the following four stages:

[0110] The first stage is when the Unification-Agent outputs standardized API request data. This involves inputting initial API request data into the Unification-Agent, which then outputs standardized API request data.

[0111] The second stage is to calculate similarity and filter historical API request data associated with the current API request data, as well as historical test cases to be learned.

[0112] The third stage involves multiple agents—Judge-Agent, Positive-Agent, Negative-RT-Agent, and Negative-FT-Agent—collaboratively generating test cases. Specifically, the Judge-Agent identifies the types of historical test cases, the first agent (Positive-Agent) generates positive test cases, the second agent (Negative-RT-Agent) generates negative test cases for required parameters, and the third agent (Negative-FT-Agent) generates negative test case keys for non-required parameters.

[0113] The fourth stage involves filtering out low-quality test cases using a Check-Agent. This stage uses a Check-Agent to detect and process the generated test cases, resulting in a final set of multiple test cases of different types.

[0114] The first stage will be explained below. The first stage is the stage where the unified intelligent agent outputs standardized API request data, such as... Figure 4 As shown, in this stage, the unified agent is primarily responsible for standardizing the initial API request data input by the user and outputting standardized API request data. This enables the conversion of API request data in various formats, resolving API compatibility and consistency issues.

[0115] In some exemplary embodiments, the standardization process performed by the unified agent may include the following steps: After receiving the initial API request data input by the user, the unified agent parses the initial API request data according to a preset prompt, extracts key information from the initial API request data input by the user, and then fills the extracted key information into a preset standardized API request data template to obtain and output standardized API request data. The key information may include: parameter names and their corresponding parameter values.

[0116] In practical applications, the pre-defined standardized API request data template can be flexibly set by those skilled in the art according to the standardized API request data format required by the actual scenario. For example, the standardized API request data format can be JSON.

[0117] In some exemplary embodiments, when the initial API request data entered by the user is missing some key information, such as a Uniform Resource Locator (URL), the unified agent can intelligently add a temporary URL.

[0118] In other exemplary embodiments, the unified agent can intelligently correct erroneous input information in the API request data entered by the user through an automatic detection function, so as to ensure that more accurate standardized API request data can be output based on the standardized API request data template.

[0119] For example, depending on the data format, the initial API request data input by the user may include: API request data described in natural language, API request data in JSON format, API request data in XML format, etc. Of course, other data formats are also possible for API request data, but this embodiment of the application does not limit this.

[0120] The second stage, which involves calculating similarity and filtering API request data associated with the current API request data, as well as historical test cases to be learned, will be explained below using the example of how to calculate the similarity between a current API request and a historical API request. Figure 5 As shown, the similarity between a current API request and a historical API request can be obtained through the following steps:

[0121] Step 1: Obtain the standardized API request data output by the unified intelligent agent (i.e., the current API request data), and build the first dictionary A based on the standardized API request data, as shown in formula (1):

[0122] (1);

[0123] Where Dict_A represents the first dictionary A, {"A_k_i":A_v_i} represents the i-th first key-value pair (item_i) in the first dictionary A, and the i-th first key-value pair (item_i) can be any key-value pair in the first dictionary A, corresponding to {"parameter": parameter value} in the standardized API request data. A_k_i represents the key in the i-th first key-value pair in the first dictionary A (i.e., the parameter in the standardized API request data), and A_v_i represents the value in the i-th first key-value pair in the first dictionary A (the parameter value in the standardized API request data). , where i and m are both positive integers, and m is the length of the first dictionary A.

[0124] Step 2: Obtain historical API request data and build a second dictionary B based on the historical API request data, as shown in formula (2):

[0125] }(2;

[0126] Where Dict_B represents the second dictionary B, {" _k_j": _v_j} represents the j-th second key-value pair in the second dictionary B, corresponding to {"parameter": parameter value} in the historical API request data. _k_j represents the key in the j-th second key-value pair in the second dictionary B, i.e., the parameter in the historical API request data; B_v_j represents the value in the j-th second key-value pair in the second dictionary B, i.e., the parameter value in the historical API request data; 1 j and n are both positive integers, and n is the length of the second dictionary B.

[0127] In practical applications, the first dictionary A and the second dictionary B can be in dictionary format as in Python (a high-level programming language). Each key-value pair in the dictionary can include a key and its corresponding value, and the value can be of single-value type or iterable value type.

[0128] Step 3: Set the preset initial weight of each first key-value pair in the first dictionary A to init_score / m, where m is the length of the first dictionary A and init_score is the preset initial similarity value of the first dictionary A.

[0129] For example, if the initial similarity value init_score of the first dictionary A is set to a preset value a, for example, a can be 1.0, then the preset initial weight of each first key-value pair in the first dictionary A is 1 / m.

[0130] Step 4: Traverse the first key-value pairs in the first dictionary A, and match the i-th first key-value pair in the first dictionary with all the second key-value pairs in the second dictionary B to obtain the matching result of the i-th first key-value pair; where i is an integer greater than or equal to 1 and less than or equal to m.

[0131] Step 5: Based on the correspondence between the matching results and the preset penalty coefficients, determine the target penalty coefficient corresponding to the matching result of the i-th first key-value pair; and determine the weight of the i-th first key-value pair by multiplying the target penalty coefficient and the preset initial weight.

[0132] For example, depending on the matching results, at least the following situations may be included:

[0133] In the first case, when the key in the i-th first key-value pair in the first dictionary A does not match the key in any of the second key-value pairs in the second dictionary B (i.e., the first matching result), the difference between 1 and the preset first penalty value (i.e., the preset first penalty coefficient corresponding to the first matching result) is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair. At this time, based on the preset first penalty coefficient and the initial weight of the i-th first key-value pair in the first dictionary A, the weight of the i-th first key-value pair in the first dictionary A is determined according to the following formula (3).

[0134] (3);

[0135] in, represents the weight of the i-th first key-value pair in the first dictionary A, init_score / m represents the initial weight of the i-th first key-value pair in the first dictionary A, init_score represents the initial similarity value of the first dictionary A, m represents the length of the first dictionary A, miss_key_penalty represents the preset first penalty value, and 1-miss_key_penalty represents the preset first penalty coefficient.

[0136] Here, the first preset penalty coefficient is used to penalize a key-value pair when a key-value pair in the first dictionary A, used to represent standardized API request data, is missing in the second dictionary B, used to represent historical API request data. For example, the preset first penalty coefficient can be set to the difference between 1 and a preset first penalty value. For example, the preset first penalty value can be set to 0.9.

[0137] In the second case, when the key in the i-th first key-value pair in the first dictionary A matches the same key in the second dictionary B, it is determined whether the type of the value corresponding to the matched key in the second dictionary B is a single-value type; when the type of the value corresponding to the matched key in the second dictionary B is a single-value type, it is determined whether the value corresponding to the matched key in the second dictionary B matches the value in the first dictionary A (i.e., the value in the i-th first key-value pair in the first dictionary A); when it is determined that the value corresponding to the matched key in the second dictionary B does not match the value in the first dictionary A, the difference between 1 and the preset second penalty value (i.e., the preset second penalty coefficient corresponding to the first matching result) is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair. At this time, based on the preset second penalty coefficient and the initial weight of the i-th first key-value pair in the first dictionary A, the weight of the i-th first key-value pair in the first dictionary A is determined according to the following formula (4).

[0138] (4);

[0139] in, The value represents the weight of the i-th first key-value pair in the first dictionary A. init_score / m represents the initial weight of the i-th first key-value pair in the first dictionary A. init_score represents the initial similarity value of the first dictionary A. m represents the length of the first dictionary A. value_mismatch_penalty represents the preset second penalty value. 1-value_mismatch_penalty represents the preset second penalty coefficient.

[0140] Here, the preset second penalty coefficient is used to penalize key-value pairs that have the same key and a single value mismatch in the first dictionary A (used to represent standardized API request data) and the second dictionary B (used to represent historical API request data). For example, the preset second penalty coefficient can be set to the difference between 1 and a preset second penalty value. For example, the preset second penalty value can be set to 0.5.

[0141] For example, when the matched key-value pair is {"parameter name 1": parameter value 1}, it indicates that the type of the key-value pair corresponding to the matched key in the second dictionary B is a single-value type.

[0142] For example, if the type of the value of the matched key in the first dictionary A is a single-value type or an iterable value type, and the value corresponding to the matched key in the second dictionary B does not match the value in the first dictionary A, this can include the following two scenarios:

[0143] Scenario 1: The value of the matched key in the first dictionary A is the current single value, and the value of the matched key in the second dictionary B is the target single value. If the current single value and the target single value are inconsistent, it means that the value of the matched key in the second dictionary B does not match the value in the first dictionary A.

[0144] Scenario 2: The value of the matched key in the first dictionary A is the current iterable value, which includes multiple current elements. The value corresponding to the matched key in the second dictionary B is the target single value. If all elements among the multiple current elements are inconsistent with the target single value, it indicates that the value corresponding to the matched key in the second dictionary B does not match the value in the first dictionary A.

[0145] In the third case, when the key in the i-th first key-value pair in the first dictionary A matches the same key in the second dictionary B, it is determined whether the type of the value corresponding to the matched key in the second dictionary B is an iterable value type; when the type of the value corresponding to the matched key in the second dictionary B is an iterable value type, it is determined whether the value of the matched key in the first dictionary A (i.e., the value in the i-th first key-value pair in the first dictionary A) matches all elements of the value corresponding to the matched key in the second dictionary B; when the value of the matched key in the first dictionary A does not match any elements of the value corresponding to the matched key in the second dictionary B, a third penalty coefficient is preset and determined as the penalty coefficient of the i-th key-value pair in the first dictionary A. At this time, based on the preset third penalty coefficient and the initial weight of the i-th key-value pair in the first dictionary A, the weight of the i-th key-value pair in the first dictionary A is determined according to the following formula (5).

[0146] (5);

[0147] in, The initial weight of the i-th first key-value pair in the first dictionary A is represented by init_score / m, the initial weight of the i-th first key-value pair in the first dictionary A is represented by init_score, the initial similarity value of the first dictionary A is represented by m, the length of the first dictionary A is represented by iteration_mismatch_penalty, the preset third penalty value is represented by 1-iteration_mismatch_penalty, and the preset third penalty coefficient is represented by 1-iteration_mismatch_penalty.

[0148] Here, the preset third penalty coefficient is used to penalize key-value pairs when a key-value pair in the first dictionary A (used to represent standardized API request data) has the same key and an iteration value mismatch exists in the second dictionary B (used to represent historical API request data). For example, the preset first penalty coefficient can be set to the difference between 1 and the preset third penalty value. For example, the preset third penalty value can be set to 0.9.

[0149] For example, an iterable value type can refer to a list, set, container, dictionary, or other value type that can contain multiple elements.

[0150] For example, taking iterable value types in list form, when the key-value pair containing the same key matched in the second dictionary B is {"parameter name 2": [parameter value 21, parameter value 22, parameter value 23]}, [parameter value 21, parameter value 22, parameter value 23] is a list containing 3 elements, which indicates that the value corresponding to the matched key in the second dictionary B is of iterable value type.

[0151] For example, if the type of the matched key in the first dictionary A is a single-value type or an iterable value type, and all elements of the matched key in the first dictionary A do not match the corresponding values ​​in the second dictionary B, this can include the following two scenarios:

[0152] Scenario 3: Taking the case where the type of the matched key in the first dictionary A is a single value, the value of the matched key in the first dictionary A is the current single value, and the value corresponding to the matched key in the second dictionary B is the target iterable value. The target iterable value can include multiple target elements. If the current single value is inconsistent with multiple target elements, it means that the value of the matched key in the first dictionary A does not match any element in the value corresponding to the matched key in the second dictionary B.

[0153] Scenario 4: Taking the value of the matched key in the first dictionary A as an iterable value type as an example, the value of the matched key in the first dictionary A is the current iterable value, which includes multiple current elements. The value corresponding to the matched key in the second dictionary B is the target iterable value, which may include multiple target elements. If each of the multiple current elements is inconsistent with the multiple target elements, it indicates that the value of the matched key in the first dictionary A does not match any of the elements in the corresponding value in the second dictionary B.

[0154] In some exemplary embodiments, the preset third penalty coefficient, the preset second penalty coefficient, and the preset first penalty coefficient are all decimals greater than 0 and less than 1.

[0155] In some exemplary embodiments, the preset third penalty value, the preset second penalty value, and the preset first penalty value are all decimals greater than 0 and less than 1. For example, the preset third penalty value is greater than the preset second penalty value, and the preset third penalty value is the same as the preset first penalty value. For instance, the preset third penalty value and the preset first penalty value can be set to 0.9, and the preset second penalty value can be set to 0.5.

[0156] After step 5, the method may further include step 6, determining the key intersection between the second dictionary B and the first dictionary A, wherein the key intersection includes all common keys shared by the second dictionary B and the first dictionary A;

[0157] For example, determining the key intersection between the second dictionary B and the first dictionary A can be achieved by converting the dictionary keys into sets and using set operators, or by iterating through the keys and filtering for common keys. For instance, by sequentially matching the key of each key-value pair in the first dictionary A with the key of all key-value pairs in the second dictionary B, all common keys shared by the first dictionary A and the second dictionary B can be obtained, thus yielding the key intersection.

[0158] Step 7: When the key intersection is not empty, the difference between the length of the second dictionary B and the total number of common keys in the key intersection is determined as the total number of remaining keys, and the ratio between the total number of remaining keys and the length of the second dictionary B is determined as the remaining key penalty coefficient extra_keys_penalty, as shown in the following formula (6):

[0159] extra_keys_penalty=(n-num) / n(6);

[0160] Where extra_keys_penalty represents the penalty coefficient for remaining keys, n is the length of the second dictionary B, num is the total number of common keys in the key intersection between the second dictionary B and the first dictionary A, and n-num represents the total number of remaining keys.

[0161] Here, the residual key penalty coefficient is used to apply residual key penalty to the key-value pairs in the first dictionary A used to represent standardized API request data when there is a key intersection between the first dictionary A used to represent standardized API request data and the second dictionary B used to represent historical API request data, and when the second dictionary B used to represent historical API request data has residual keys.

[0162] Step 8: Based on the residual key penalty coefficient and the weight of the i-th first key-value pair in the first dictionary A, determine the final value of the weight of the i-th key-value pair in the first dictionary A according to the following formula (7).

[0163] (7);

[0164] in, Let represent the final weight of the i-th key-value pair in the first dictionary A. This represents the weight of the i-th first key-value pair in the first dictionary A, and extra_keys_penalty represents the penalty coefficient for the remaining keys.

[0165] Step 9: When the key intersection is empty, the product of the target penalty coefficient and the preset initial weight is determined as the weight of the i-th first key-value pair, that is, the weight of the i-th first key-value pair determined in the previous step 5 remains unchanged.

[0166] After determining the weights of all key-value pairs in the first dictionary A based on the initial similarity value init_score of the first dictionary A, the length m of the first dictionary A, the second dictionary B, and the preset penalty rules, step 10 is executed.

[0167] Step 10: The sum of the weights of all key-value pairs in the first dictionary A is used to determine the similarity between the first dictionary A and the second dictionary B, that is, to obtain the similarity between the standardized API request data and the historical API request data, as shown in the following formula (8).

[0168] (8);

[0169] Where final_score represents the similarity between the first dictionary A and the second dictionary B. This represents the weight of the i-th first key-value pair in the first dictionary A, 1 , where i and m are both positive integers, and m is the length of the first dictionary A.

[0170] Step 11: Sort the similarity scores of the first dictionary A of standardized API request data with the second dictionary B of N historical API request data in descending order to obtain a similarity sequence for each standardized API request data. The historical API request data with the highest similarity score (i.e., the largest similarity) in the similarity sequence is identified as the target historical API request data related to that standardized API request data. In this way, target historical API request data with high relevance to the standardized API request data can be selected from among the historical API request data.

[0171] Step 12: Obtain all historical test cases corresponding to the target historical API request data from the historical test case set as the historical test cases to be learned, thus obtaining the historical test case set, which serves as the historical test case set to be learned corresponding to the standardized API request data. In this way, by ensuring a high correlation between the target historical API request data and the standardized API request data, the relevance of the historical test cases in the historical test case set to be learned can be enhanced. Ensuring a strong correlation between the historical test cases to be learned and the standardized API request data allows for the acquisition of a highly reliable historical test case set to be learned, thereby improving the accuracy of test cases generated based on this standardized API request data and the historical test case set to be learned.

[0172] Below, we take a standardized API request data and its corresponding target historical API request data (e.g., historical API request data with the highest similarity value) as an example. Figure 6 As shown, the third stage is explained, which is the stage of multi-agent collaborative generation of test cases.

[0173] Using the Judge-Agent, based on the target's historical API request data, the judge-agent performs type discrimination on the historical test cases to be learned in the set of historical test cases to be learned, and obtains a set of historical positive test cases, a set of historical negative test cases for required parameters, and a set of historical negative test cases for non-required parameters.

[0174] Using the first intelligent agent (Positive-Agent), based on standardized API request data and a set of historical positive test cases, positive test cases and their corresponding expected response data (init-response) are generated according to pre-set prompts.

[0175] Using a second intelligent agent (Negative-RT-Agent), based on standardized API request data and a set of historical reverse test cases for required parameters, test cases for required parameters and their corresponding expected response data (init-response) are generated according to pre-set prompts.

[0176] Using a third-party intelligent agent (Negative-FT-Agent), based on standardized API request data and a set of historical reverse test cases for non-mandatory parameters, and according to pre-set prompts, reverse test cases for non-mandatory parameters and their corresponding expected response data (init-response) are generated.

[0177] For example, a pre-set prompting program is used to indicate one or more of the following information to the agent: whether the parameter type in the current parameters is required or not, the meaning of the parameter name in the test case, the requirements and specifications for outputting test cases, and test cases generated by learning samples, etc.

[0178] For example, the expected response data init-response may include: response status and status code. The response status may include OK, ERROR, EXCEPTION, ALARM, and FORBIDDEN, etc.; the status code may include 200, 400, 404, etc.

[0179] For example, the functionality of generating multiple Agents for test cases is described in detail below:

[0180] Positive-Agent: This is an intelligent agent specifically responsible for generating positive test cases. For example, it uses standardized API request data as input and historical positive test cases as learning examples. It is required to cover all required parameters during the generation process and ensure the correctness of all parameter values.

[0181] Negative-RT-Agent is an intelligent agent specifically designed to generate reverse test cases for required parameters. For example, it uses standardized API request data as input and historical reverse test cases for non-required parameters as learning examples. During the test case generation process, it generates test cases for individual parameters, thereby avoiding the generation of reverse test cases where multiple required parameters fail simultaneously.

[0182] Negative-FT-Agent is an intelligent agent specifically designed to generate reverse test cases for non-mandatory parameters. For example, it uses standardized API request data as input and historical reverse test cases for non-mandatory parameters as learning examples. During the test case generation process, it ensures the correctness of all mandatory parameters and generates test cases for individual non-mandatory parameters.

[0183] In some exemplary embodiments, the process of using a referee agent to determine the type of historical test cases to be learned from the set of historical test cases to be learned, based on the target historical API request data, may include the following steps:

[0184] When the historical test case to be learned covers all parameters and all parameter values ​​are completely correct, the historical test case to be learned is classified as a historical positive test case; where, covering all parameters and all parameter values ​​are completely correct can mean that: covering all required parameters and all required parameter values ​​are completely correct, and covering all non-required parameters and all non-required parameter values ​​are completely correct.

[0185] When a required parameter is missing or the value of the required parameter is incorrect in the historical test case to be learned, the historical test case to be learned is classified as a historical reverse test case for the required parameter.

[0186] When the test case to be learned covers all required parameters and the values ​​of the required parameters are completely correct, and there are errors in the values ​​of the non-required parameters, the test case to be learned is classified as a reverse test case for non-required parameters.

[0187] Taking Negative-RT-Agent as an example, by writing a prompt project, standardized API request data is passed into {Standardized API} as parameters, and negative test cases that Judge-Agent's historical test cases identify as required parameters are passed into {history_required_true_positive_test_cases} as parameters, thus forming the final completion prompt project. Negative-RT-Agent generates test cases based on the prompt words.

[0188] The default prompts for Negative-RT-Agent can be shown in Table 1 below:

[0189] Table 1 shows the project details.

[0190]

[0191] The test cases generated by Negative-RT-Agent cover all required parameters, and each parameter corresponds to multiple error types. In addition to the test cases themselves, the returned content includes expected response data. Furthermore, the test case return format can be defined as Markdown (a lightweight markup language) for easy extraction by testers.

[0192] The fourth stage will be explained below, such as Figure 6 and Figure 7 As shown, the fourth stage is the stage where the Check-Agent responds to self-censorship and filters out low-quality test cases.

[0193] After obtaining the generated test case set, for each generated test case in the test case set, a check-agent is used to generate a corresponding real response data (check-response) based on standardized API request data and each generated test case. The expected response data (init-response) corresponding to the generated test case is compared with the real response data (check-response). Test cases generated in the test case set whose expected response data (init-response) and real response data (check-response) are inconsistent are deleted, resulting in the final test case set. Thus, the test case generation method in this embodiment can introduce a test case self-checking mechanism after generating the test case set. It uses an agent to predict the API input and the real response output of the generated test cases, and compares it with the expected response data generated in the previous stage, thereby filtering out low-quality test cases and obtaining a high-quality test case set. Furthermore, when testers perform tests based on this high-quality test case set, they can avoid ineffective work and improve their efficiency.

[0194] In some exemplary embodiments, when the number of test cases generated in the final test case set is less than a preset threshold, it can be determined that the reliability of the selected historical test case set to be learned is low. The next historical API request data of the historical API request data with the second largest similarity value (i.e., the historical API request data with the second largest similarity value) can be determined as the new target historical API request data. Then, based on the new target historical API request data, the above steps S204 to S205 are executed again to re-obtain all historical test cases in the historical test case set that correspond to the new target historical API request data as new historical test cases to be learned, and a new set of historical test cases to be learned is obtained. Test cases are regenerated based on the new set of historical test cases to be learned until the number of test cases generated in the final test case set is greater than or equal to the preset threshold.

[0195] The test case generation method provided in this application has at least the following beneficial effects:

[0196] By selecting historical API request data that meets preset similarity criteria from N historical API request data sets, and then selecting historical test case sets corresponding to target historical API request data related to each current API request data from the historical test case set, the targeting of the historical test case set to be learned for each current API request data can be enhanced, ensuring a strong correlation between the current API request data and the corresponding historical test case set to be learned. Thus, through the collaborative work of multiple intelligent agents, high-quality test cases of different types can be generated, improving the richness of generated test case types, increasing the scenario coverage of generated test cases, and simplifying the process of generating various types of test cases. Furthermore, it avoids the truncation situation caused by the max_token limit when a single agent generates a large number of test cases, thereby ensuring high stability in the test case generation process. In this way, high-quality test cases can be obtained.

[0197] This application also provides a test case generation device, such as... Figure 8 As shown, the device includes:

[0198] Unit 801 is configured to obtain M current application interface request data, where M is an integer greater than or equal to 1;

[0199] The acquisition unit 802 is configured to acquire the target historical application interface request data related to each current application interface request data and the set of historical test cases to be learned corresponding to each current application interface request data;

[0200] The generation unit 803 is configured to generate multiple test case sets corresponding to each current application interface request data by using multiple intelligent agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data. The multiple intelligent agents include: a referee intelligent agent for judging the type of historical test cases and multiple intelligent agents for generating test cases.

[0201] In some exemplary embodiments, the acquisition unit 802 is configured to acquire N historical application interface request data, where N is an integer greater than or equal to 2; determine the similarity between each current application interface request data and the N historical application interface request data; select historical application interface request data whose similarity meets preset conditions from the N historical application interface request data, and use them as target historical application interface request data related to each current application interface request data; and select historical test case sets corresponding to the target historical application interface request data related to each current application interface request data from the historical test case set, and use them as the set of historical test cases to be learned for each current application interface request data.

[0202] In some exemplary embodiments, multiple agents for generating test cases include: a first agent, a second agent, and a third agent; a generation unit 803 is configured to, through a referee agent, perform type discrimination on the historical test cases in the set of historical test cases to be learned corresponding to each current application interface request data, based on the target historical application interface request data related to each current application interface request data, to obtain a first type of historical test case set, a second type of historical test case set, and a third type of historical test case set corresponding to each current application interface request data; through the first agent, generate a first type of test case set based on each current application interface request data and its corresponding first type of historical test case set; through the second agent, generate a second type of test case set based on each current application interface request data and its corresponding second type of historical test case set; and through the third agent, generate a third type of test case set based on each current application interface request data and its corresponding third type of historical test case set.

[0203] It should be noted that the descriptions of the same steps and contents in this embodiment as in other embodiments can be found in the descriptions in other embodiments, and will not be repeated here.

[0204] Embodiments of this application provide an electronic device that can be applied to... Figure 1 In a test case generation method provided in a corresponding embodiment, such as Figure 9 As shown, the electronic device 900 includes: a processor 901, a memory 902, and a communication bus 903, wherein:

[0205] The communication bus 903 is configured to enable communication between the processor 901 and the memory 902.

[0206] The memory 902 is configured to store computer programs that can run on the processor 901;

[0207] Processor 901, when running computer programs, performs the following steps:

[0208] Get M current application interface request data, where M is an integer greater than or equal to 1;

[0209] Obtain the target historical application interface request data related to each current application interface request data and the set of historical test cases to be learned corresponding to each current application interface request data;

[0210] Through multiple agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data, multiple test case sets corresponding to each current application interface request data are generated. The multiple agents include: a referee agent for judging the type of historical test cases and multiple agents for generating test cases.

[0211] In some exemplary embodiments, when the processor 901 runs a computer program, it performs the following steps: obtaining N historical application interface request data, where N is an integer greater than or equal to 2; determining the similarity between each current application interface request data and the N historical application interface request data; selecting historical application interface request data whose similarity meets preset conditions from the N historical application interface request data, as target historical application interface request data related to each current application interface request data; and selecting historical test case sets corresponding to the target historical application interface request data related to each current application interface request data from the historical test case set, as the set of historical test cases to be learned corresponding to each current application interface request data.

[0212] In some exemplary embodiments, the processor 901, when running a computer program, implements the steps of the test case generation method shown in one or more of the exemplary embodiments described above. Further details are omitted here; they can be understood by referring to the descriptions in the above embodiments of the test case generation method.

[0213] A processor can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, a general-purpose processor can be a microprocessor or any conventional processor.

[0214] It should be noted that the descriptions of the same steps and contents in this embodiment of the electronic device as in other embodiments can be found in the descriptions in other embodiments, and will not be repeated here.

[0215] Embodiments of this application provide a computer storage medium storing one or more programs, which can be executed by one or more processors to achieve, for example... Figure 1 The steps are shown. It should be noted that the descriptions of the same steps and contents as in other embodiments can be found in other embodiments and will not be repeated here.

[0216] It should be noted that the aforementioned computer storage media / memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic random access memory (FRAM), flash memory, magnetic surface memory, optical disc, or compact disc read-only memory (CD-ROM), etc.; it can also be various terminals that include one or any combination of the above-mentioned memory, such as mobile phones, computers, tablet devices, personal digital assistants, etc.

[0217] Embodiments of this application provide a computer program product, including a computer program that can be executed by a processor 901 of an electronic device 900 to perform tasks such as... Figure 1 The steps are shown. It should be noted that the descriptions of the same steps and contents as in other embodiments can be found in the descriptions of other embodiments, and will not be repeated here.

[0218] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0219] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.

[0220] Furthermore, in the various embodiments of this application, all functional units can be integrated into one processing module, or each unit can be a separate unit, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in a combination of hardware and software functional units. Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0221] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined to obtain new method embodiments without conflict. The features disclosed in the several product embodiments provided in this application can be arbitrarily combined to obtain new product embodiments without conflict. The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined to obtain new method embodiments or device embodiments without conflict.

[0222] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A test case generation method, characterized in that, include: Get M current application interface request data, where M is an integer greater than or equal to 1; The process involves obtaining target historical application interface request data related to each current application interface request data and a set of historical test cases to be learned corresponding to each current application interface request data. This includes: obtaining N historical application interface request data, where N is an integer greater than or equal to 2; determining the similarity between each current application interface request data and the N historical application interface request data; selecting historical application interface request data whose similarity meets preset conditions from the N historical application interface request data, and using these as target historical application interface request data related to each current application interface request data; and selecting historical test cases corresponding to the target historical application interface request data related to each current application interface request data from the historical test case set, and using these as the set of historical test cases to be learned corresponding to each current application interface request data. Through multiple intelligent agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data, multiple test case sets corresponding to each current application interface request data are generated. The multiple intelligent agents include: a referee intelligent agent for judging the type of historical test cases and multiple intelligent agents for generating test cases.

2. The method according to claim 1, characterized in that, The step of determining the similarity between each current application interface request data and the N historical application interface request data includes: Based on the data requested by each current application interface, create a first dictionary corresponding to the data requested by each current application interface. Based on the N historical application interface request data, establish N second dictionaries that correspond one-to-one with the N historical application interface request data; The similarity between the first dictionary and the N second dictionaries corresponding to each current application interface request data is determined, and used as the similarity between each current application interface request data and the N historical application interface request data.

3. The method according to claim 2, characterized in that, Determining the similarity between the first dictionary and the N second dictionaries corresponding to each current application interface request data includes: Based on the m first key-value pairs of the first dictionary corresponding to the p-th current application interface request data and the n second key-value pairs of the q-th second dictionary among the N second dictionaries, perform a weight calculation operation to obtain the weights of all first key-value pairs in the first dictionary corresponding to the p-th current application interface request data; The sum of the weights of all first key-value pairs in the first dictionary corresponding to the p-th current application interface request data is determined as the similarity between the first dictionary corresponding to the p-th current application interface request data and the q-th second dictionary, and is used as the similarity between the first dictionary corresponding to each current application interface request data and the N second dictionaries; Where m and n are integers greater than or equal to 2, p is an integer greater than or equal to 1 and less than or equal to M, and q is an integer greater than or equal to 1 and less than or equal to N.

4. The method according to claim 3, characterized in that, The weight calculation operation includes: The i-th first key-value pair in the first dictionary corresponding to the p-th current application interface request data is matched with all the second key-value pairs in the q-th second dictionary to obtain the matching result of the i-th first key-value pair; where i is an integer greater than or equal to 1 and less than or equal to m; Based on the correspondence between the matching results and the preset penalty coefficient, determine the target penalty coefficient corresponding to the matching result of the i-th first key-value pair; The weight of the i-th first key-value pair is determined based at least on the target penalty coefficient and the preset initial weight.

5. The method according to claim 4, characterized in that, The step of determining the target penalty coefficient corresponding to the matching result of the i-th first key-value pair based on the correspondence between the matching result and the preset penalty coefficient includes: When the matching result of the i-th first key-value pair is that the key in the i-th first key-value pair does not match the key in any of the second key-value pairs in the q-th second dictionary, the difference between 1 and the preset first penalty value is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair. or, When the matching result of the i-th first key-value pair is that the key in the i-th first key-value pair matches the same key in the q-th second dictionary, the value corresponding to the same key in the q-th second dictionary is a single value type, and the value of the same key in the i-th first key-value pair is inconsistent with the value corresponding to the q-th second dictionary, the difference between 1 and the preset second penalty value is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair; or, When the matching result of the i-th first key-value pair is that the key in the i-th first key-value pair matches the same key in the q-th second dictionary, the value corresponding to the same key in the q-th second dictionary is an iterable value type, and the value of the same key in the i-th first key-value pair is inconsistent with all elements in the value corresponding to the q-th second dictionary, the difference between 1 and the preset third penalty value is determined as the target penalty coefficient corresponding to the matching result of the i-th first key-value pair.

6. The method according to claim 4, characterized in that, The step of determining the weight of the i-th first key-value pair based at least on the target penalty coefficient and the preset initial weight includes: Determine the key intersection between the first dictionary corresponding to the p-th current application interface request data and the q-th second dictionary among the N second dictionaries; When the key intersection is not empty, the remaining key penalty coefficient is determined based on the number of common keys in the key intersection and the length of the q-th second dictionary among the N second dictionaries. The product of the target penalty coefficient, the preset initial weight, and the remaining key penalty coefficient is determined as the weight of the i-th first key-value pair. Alternatively, when the key intersection is empty, the product of the target penalty coefficient and the preset initial weight is determined as the weight of the i-th first key-value pair.

7. The method according to any one of claims 1 to 6, characterized in that, The step of selecting historical application interface request data that meets preset similarity conditions from the N historical application interface request data, and using them as target historical application interface request data related to each current application interface request data, includes: The similarity between each current application interface request data and the N historical application interface request data is sorted in descending order to obtain the similarity sequence corresponding to each current application interface request data. The historical application interface request data corresponding to the first similarity in the similarity sequence of each current application interface request data is used as the target historical application interface request data related to each current application interface request data.

8. The method according to claim 7, characterized in that, After generating multiple test case sets corresponding to each current application interface request data, the method further includes: Determine whether the number of test cases in the test case set is less than a preset threshold; When the number of test cases in the test case set is less than a preset threshold, the historical application interface request data corresponding to the next similarity of the similarity of the target historical application interface request data in the similarity sequence corresponding to each current application interface request data is taken as the new target historical application interface request data, so as to regenerate multiple test case sets corresponding to each current application interface request data based on the new target historical application interface request data.

9. The method according to any one of claims 1 to 6, characterized in that, The plurality of intelligent agents used to generate test cases include: a first intelligent agent, a second intelligent agent, and a third intelligent agent; The process involves generating multiple test case sets for each current application interface request data based on various intelligent agents, including: each current application interface request data, related target historical application interface request data, and a set of historical test cases to be learned corresponding to each current application interface request data. Through the referee agent, based on the target historical application interface request data related to each current application interface request data, the type of the historical test cases to be learned in the historical test case set to be learned corresponding to each current application interface request data is determined, and the first type of historical test case set, the second type of historical test case set and the third type of historical test case set corresponding to each current application interface request data are obtained. The first intelligent agent generates a first type of test case set based on each current application interface request data and its corresponding first type of historical test case set. The second intelligent agent generates a second type of test case set based on each current application interface request data and its corresponding second type of historical test case set. The third intelligent agent generates a third type of test case set based on each current application interface request data and its corresponding third type of historical test case set.

10. The method according to any one of claims 1 to 6, characterized in that, Each test case set includes: test cases and their corresponding expected response data; After generating multiple test case sets corresponding to each current application interface request data, the method further includes: By detecting the intelligent agent, based on the current application interface request data and its corresponding multiple test case sets, the real response data corresponding to each test case in the multiple test case sets is generated; Compare the expected response data with the actual response data for each test case; Delete test cases in the aforementioned test case sets where the expected response data does not match the actual response data.

11. A test case generation device, characterized in that, include: The acquisition unit is set to acquire M current application interface request data, where M is an integer greater than or equal to 1; The acquisition unit is configured to acquire target historical application interface request data related to each current application interface request data and a set of historical test cases to be learned corresponding to each current application interface request data. The acquisition of target historical application interface request data related to each current application interface request data and a set of historical test cases to be learned corresponding to each current application interface request data includes: acquiring N historical application interface request data, where N is an integer greater than or equal to 2; determining the similarity between each current application interface request data and the N historical application interface request data; selecting historical application interface request data whose similarity meets preset conditions from the N historical application interface request data, as target historical application interface request data related to each current application interface request data; and selecting historical test cases corresponding to the target historical application interface request data related to each current application interface request data from the historical test case set, as the set of historical test cases to be learned corresponding to each current application interface request data. The generation unit is configured to generate multiple test case sets corresponding to each current application interface request data by using multiple intelligent agents, based on each current application interface request data, the target historical application interface request data related to each current application interface request data, and the historical test case set to be learned corresponding to each current application interface request data. The multiple intelligent agents include: a referee intelligent agent for judging the type of historical test cases and multiple intelligent agents for generating test cases.

12. An electronic device, characterized in that, include: The processor and the memory used to store computer programs that can run on the processor. When the processor is used to run the computer program, it performs the steps of the method as described in any one of claims 1 to 10.

13. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 10.

14. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 10.

Citation Information

Patent Citations

  • Service interface test method and device, electronic equipment and storage medium

    CN116149978A

  • Test case generation method and device based on intelligent agent, equipment and medium

    CN120631781A