Test case generation method and device, terminal equipment and storage medium

By automatically generating test cases through machine learning models and force-directed algorithms, this technology overcomes the shortcomings of existing technologies that rely on human experience and fixed templates, and achieves efficient and flexible test case generation.

CN120929374APending Publication Date: 2025-11-11AIJI MICRO CONSULTING (XIAMEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511032494.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-25
Publication Date
2025-11-11

AI Technical Summary

Technical Problem

Existing technologies rely heavily on human experience, making it difficult to meet the testing efficiency requirements of rapid iteration in agile development models. Automated generation technologies lack intelligent reasoning capabilities, resulting in low test case effectiveness.

Method used

通过机器学习模型自动分析目标文档中的业务逻辑和页面元素,利用力导向算法生成流程图,基于机器学习模型生成覆盖所有路径的测试用例,结合图遍历和强化学习算法优化生成规则。

Benefits of technology

It can automatically analyze business logic and page elements without relying on human experience, dynamically adjust testing strategies, and significantly improve the efficiency and effectiveness of test case generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120929374A_ABST
    Figure CN120929374A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a test case generation method and device, terminal equipment and a storage medium. According to the scheme, the target operation can be carried out on the target document according to the operation instruction to obtain the corresponding service module, the service logic and the page element of each service module are extracted, the page circulation relation is determined according to the service logic and the page element, and the flow chart is generated according to the page circulation relation through the force steering algorithm. And generating a test case covering all paths in the flow chart based on the machine learning model, and outputting the test case in a preset code form. According to the scheme provided by the embodiment of the invention, the business logic and the page elements in the target document can be automatically analyzed without depending on artificial experience, the test case is automatically generated through the machine learning model, and the test strategy can be dynamically adjusted according to the change of the business logic, so that the test efficiency is improved. The defect that the test case can only be generated by adopting a fixed template in the prior art is overcome, so that the generation efficiency and effectiveness of the test case are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software testing technology, specifically to a test case generation method, apparatus, terminal device, and storage medium. Background Technology

[0002] With the continuous increase in the complexity of software systems, software testing has become an indispensable and crucial link in ensuring software quality. Test cases, as the core carrier of testing activities, directly impact the effectiveness of testing and the control of the development cycle through their generation efficiency and quality. Traditional test case generation methods mainly rely on manual design, with test engineers manually writing test cases covering various scenarios by interpreting requirements documents and drawing business process diagrams.

[0003] In practical use, the applicant found that existing technologies rely too heavily on human experience, especially in agile development models, where traditional methods struggle to meet the efficiency requirements of rapid iteration. Furthermore, existing automated test case generation technologies generally lack intelligent reasoning capabilities; most commercial testing tools (such as Selenium and QTP) use fixed templates to generate test cases, failing to dynamically adjust testing strategies based on changes in business logic, resulting in low effectiveness of the generated test cases. Summary of the Invention

[0004] This application provides a test case generation method, apparatus, terminal device, and storage medium, which can automatically analyze the business logic and page elements in the target document and automatically generate test cases through a machine learning model, effectively improving the efficiency and effectiveness of test case generation.

[0005] This application provides a test case generation method, including:

[0006] Perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and extract the business logic and page elements of each business module;

[0007] The page flow relationship is determined based on the business logic and page elements;

[0008] A flowchart is generated based on the page flow relationship using a force-guided algorithm;

[0009] Test cases covering all paths in the flowchart are generated based on a machine learning model, and the test cases are output in the form of preset code.

[0010] In one embodiment, performing target operations on the target document to obtain the corresponding business module includes:

[0011] Convert the document format of the target document;

[0012] The target document after format conversion is processed, including text cleaning, word segmentation, and part-of-speech tagging;

[0013] Semantic analysis is performed on the processed target document to extract business modules.

[0014] In one embodiment, determining the page flow relationship based on the business logic and page elements includes:

[0015] Construct a graph structure and define the nodes and edges in the graph structure;

[0016] Based on the operation response information corresponding to the page elements and the business logic, the association relationship between nodes and edges in the graph structure is established.

[0017] In one embodiment, generating a dynamic flowchart based on the page flow relationship using a force-directed algorithm includes:

[0018] Assign weight values ​​to each node and edge in the graph structure based on the multidimensional feature information of the business module;

[0019] Based on the graph structure and weight values, a force-directed algorithm is used to generate a flowchart, which is then output in Mermaid code form.

[0020] In one embodiment, generating test cases based on a machine learning model that cover all paths in the flowchart includes:

[0021] All paths in the flowchart are extracted using a graph traversal algorithm, and the paths are expanded using a reinforcement learning algorithm.

[0022] The machine learning model is trained using historical test case data to optimize the generation rules;

[0023] Based on the optimized generation rules and expanded paths, the machine learning model automatically generates test cases that cover all paths in the flowchart.

[0024] In one embodiment, training the machine learning model using historical test case data includes:

[0025] Collect historical test case data and extract key features from the historical test case data;

[0026] The key features are input into the machine learning model to calculate the prediction result, and the loss function is calculated based on the prediction result and the pre-labeled actual result;

[0027] The parameters in the machine learning model are adjusted through backpropagation to minimize the loss function, thereby completing the training.

[0028] In one embodiment, the method further includes:

[0029] Receive feedback information for the test cases and adjust the test cases based on the feedback information.

[0030] This application also provides a test case generation device, including:

[0031] The receiving unit is used to perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and to extract the business logic and page elements of each business module;

[0032] The determining unit is used to determine the page flow relationship based on the business logic and page elements;

[0033] The generation unit is used to generate a flowchart based on the page flow relationship using a force-guided algorithm;

[0034] The output unit is used to generate test cases covering all paths in the flowchart based on the machine learning model, and output the test cases in the form of preset code.

[0035] This application also provides a terminal device, which includes a memory and a processor. The memory stores an application program, and when the application program is executed by the processor, it implements the steps of the test case generation method provided in any of the embodiments of this application.

[0036] This application also provides a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute any of the test case generation methods provided in this application.

[0037] The test case generation method provided in this application can perform target operations on a target document according to operation instructions to obtain the corresponding business modules, extract the business logic and page elements of each business module, determine the page flow relationship based on the business logic and page elements, generate a flowchart based on the page flow relationship using a force-directed algorithm, generate test cases covering all paths in the flowchart based on a machine learning model, and output the test cases in the form of preset code. The solution provided in this application does not rely on human experience and can automatically analyze the business logic and page elements in the target document, and automatically generate test cases through a machine learning model. Moreover, it can dynamically adjust the test strategy according to changes in business logic, overcoming the shortcomings of existing technologies that can only use fixed templates to generate test cases, thereby effectively improving the efficiency and effectiveness of test case generation. Attached Figure Description

[0038] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0039] Figure 1 This is a schematic diagram of the first type of test case generation method provided in the embodiments of this application;

[0040] Figure 2 This is a schematic diagram of the second process of the test case generation method provided in the embodiments of this application;

[0041] Figure 3 This is a schematic diagram of a test case generation device provided in an embodiment of this application;

[0042] Figure 4 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation

[0043] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0044] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, components, features, and elements with the same names in different embodiments of this application may have the same meaning or different meanings, the specific meaning of which must be determined by its interpretation in that specific embodiment or further in conjunction with the context of that specific embodiment.

[0045] It should be understood that although the steps in the flowcharts of this application's embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.

[0046] It should be noted that step designations such as 101 and 102 are used in this document for the purpose of more clearly and concisely describing the corresponding content, and do not constitute a substantial limitation on the order. In specific implementation, those skilled in the art may execute 102 first and then 101, etc., but these should all be within the protection scope of this application.

[0047] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0048] This application provides a test case generation method. The execution subject of this test case generation method can be the test case generation device provided in this application, or a terminal device (smart terminal, server, etc.) that integrates the test case generation device. The test case generation device can be implemented in hardware or software.

[0049] For details, please refer to Figure 1 , Figure 1 This is a schematic diagram of the first flowchart of the test case generation method provided in this application embodiment. The specific flow of the test case generation method can be as follows:

[0050] 101. Perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and extract the business logic and page elements of each business module.

[0051] In one embodiment, after receiving target documents of various formats, the system performs target operations on the target documents according to operation instructions. These operation instructions can be user-issued instructions or pre-stored instructions. For user-issued instructions, the system temporarily caches the target documents upon receiving them and executes the target operation upon receiving the user's instruction. For pre-stored instructions, the system immediately reads the pre-stored instructions upon receiving target documents of various formats and simultaneously triggers the target operation on the target documents, thus meeting the agile development model's requirements for high efficiency and rapid testing.

[0052] It is understood that the target document can be a requirements document, business document, test document, functional verification document, etc., and this application embodiment does not limit its type. The following uses the requirements document as an example for illustration.

[0053] For the target operation, the requirements document is first preprocessed to prepare for subsequent semantic analysis. Preprocessing includes text cleaning (removing redundant formatting and special characters), word segmentation, and part-of-speech tagging. Then, natural language processing (NLP) techniques are used to perform semantic analysis on the preprocessed requirements document. Keyword matching (e.g., "login module," "payment function") and semantic clustering are used to identify the main business modules. For example, "user login," "product browsing," and "shopping cart management" modules are extracted from e-commerce requirements documents. Each business module is then analyzed in depth to extract its business logic (business rules). For example, the business logic of the "login module" includes "enter username and password → system verification → successful verification redirects to the homepage, failure displays an error message." Page elements of the business modules are identified and extracted, such as interactive elements (buttons, input boxes, dropdown menus) and their attributes (name, function, location). For example, elements such as the "username input box" and "login button" on the login page are extracted and their functions are recorded, such as "the login button is used to trigger the verification process."

[0054] 102. Determine the page flow relationship based on business logic and page elements.

[0055] In one embodiment, a graph structure is constructed, and nodes and edges within the graph structure are defined. Based on the operation response information corresponding to page elements and business logic, the relationships between nodes and edges in the graph structure are established. Specifically, each page can be considered a node in the graph structure, and the navigation relationships between pages can be considered edges. For example, the login page node is connected to the homepage node via an edge indicating successful login. By analyzing the system responses triggered by user actions, page flow relationships (page flow paths) are determined. For example, clicking the "Add to Cart" button on the product details page triggers a system response that navigates to the shopping cart page, forming an edge from "Product Details Page → Shopping Cart Page".

[0056] In one embodiment, conditional attributes can be added to the edges in the graph structure to distinguish between normal and abnormal flows. For example, the edge for "Login Page → Homepage" must satisfy "Username and password are correct," while the edge for "Login Page → Error Message Page" corresponds to "Incorrect password entered." This covers all possible operational scenarios, including normal flows (such as placing an order normally) and abnormal flows (such as insufficient inventory when placing an order), ensuring the integrity of page flow relationships.

[0057] 103. Generate a flowchart based on the page flow relationship using a force-directed algorithm.

[0058] In one embodiment, the "attraction" and "repulsion" forces between nodes in a physical system are simulated to bring related page nodes closer together and unrelated nodes further apart, generating a well-structured flowchart. Nodes are weighted according to business complexity (e.g., the payment module is more complex than the homepage) and user traffic (high-frequency access pages have higher weight), and these weights affect the node's position in the graph structure (higher-weight nodes are more prominent). Edge weights are adjusted based on page transition frequency (e.g., the transition from "homepage → product details page" is more frequent), with high-frequency edges bringing nodes closer together to improve flowchart readability. A force-directed algorithm iteratively calculates node positions to avoid overlap, ultimately generating a flowchart output in Mermaid code format, allowing users to view and edit it visually.

[0059] 104. Generate test cases that cover all paths in the flowchart based on the machine learning model, and output the test cases in the form of preset code.

[0060] In one embodiment, a graph traversal algorithm (such as depth-first search) is used to extract all path branches in the flowchart, including normal paths and abnormal paths. A normal path might be "Login → Homepage → Place Order," and an abnormal path might be "Login Failed → Retry." Then, a machine learning model (such as a decision tree or neural network) is trained using historical test case data (input data, operation steps, and expected results) to learn the test patterns corresponding to different paths in the flowchart. For example, the machine learning model learns the pattern of "an error message should be displayed when an empty password is entered" by learning from historical test case data. The path branches of the new flowchart are input into the machine learning model, which automatically generates test cases, including test steps, input data, and expected results. Finally, the test cases are output in Markdown code format, containing standardized fields such as test case number, test steps, and expected results, making it easy for users to use directly or import into testing tools.

[0061] This embodiment significantly reduces the time and workload required for manually writing test cases by integrating artificial intelligence technology into the test case generation process. It can also accept target documents in various formats to meet diverse user needs, allowing for flexible processing of target documents with different content. Specifically, the testing strategy can be flexibly adjusted for different target documents. Furthermore, the technical solution of this embodiment supports outputting test cases in user-friendly formats such as Markdown code, and outputting flowcharts in Mermaid code format with editing support, enabling the system to adapt to the needs of different projects and scenarios, and possessing strong versatility. In addition, compared to existing technologies that generate test cases using fixed templates, the technical solution of this embodiment constructs dynamic flowcharts through a force-directed algorithm and optimizes the layout by adjusting node weights and edge weights. This dynamically reflects changes in business logic, improves the readability of the flowchart, facilitates subsequent test case generation, and significantly enhances the effectiveness of the generated test cases.

[0062] As described above, the test case generation method proposed in this application can perform target operations on a target document according to operation instructions to obtain the corresponding business modules, extract the business logic and page elements of each business module, determine the page flow relationship based on the business logic and page elements, generate a flowchart based on the page flow relationship using a force-directed algorithm, generate test cases covering all paths in the flowchart based on a machine learning model, and output the test cases in the form of preset code. The solution provided by this application does not rely on human experience and can automatically analyze the business logic and page elements in the target document, automatically generate test cases through a machine learning model, and dynamically adjust the test strategy according to changes in business logic, thereby overcoming the shortcomings of existing technologies that can only use fixed templates to generate test cases, thus effectively improving the efficiency and effectiveness of test case generation.

[0063] The method described in the preceding embodiments will be further described in detail below.

[0064] Please see Figure 2 , Figure 2 This is a schematic diagram of a second flowchart of the test case generation method provided in this application embodiment. The method includes:

[0065] 201. Perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and extract the business logic and page elements of each business module.

[0066] In one embodiment, the step of performing target operations on a target document according to operation instructions to obtain the corresponding business module may include: converting the document format of the target document; processing the converted target document, including text cleaning, word segmentation, and part-of-speech tagging; and performing semantic analysis on the processed target document to extract the business module. Specifically, this embodiment can receive target documents in various formats such as Word, PDF, and TXT, and convert them into plain text format, such as a TXT document encoded in UTF-8, through a format conversion tool, thereby eliminating the layout differences between different document formats.

[0067] Text cleaning includes removing headers, footers, comments, blank lines, special symbols, and irrelevant descriptions from documents, retaining only core business descriptions. For example, removing non-business content such as "This document is copyrighted by XXX" from requirements documents. Additionally, it standardizes capitalization, full-width / half-width characters, date formats, and reduces data noise. Word segmentation involves using word segmentation tools to break continuous text into individual words and handling out-of-vocabulary words. Alternatively, for English requirements documents, words are split by spaces, verbs are restored to their base forms, and nouns are standardized to singular forms for easier semantic analysis. Part-of-speech tagging uses tools to assign part-of-speech tags to each segmented word, such as noun, verb, or adjective.

[0068] In one embodiment, text can be divided into independent sentences based on punctuation marks or preset words. Then, a semantic similarity algorithm is used to cluster sentences describing the same topic into semantic blocks. Based on a preset business domain dictionary, high-frequency keywords are extracted from these semantic blocks. For example, when words such as "username," "password," and "verification" are detected in a semantic block, it is initially determined that it is related to the "user login" module. A word vector model is then used to calculate the semantic similarity between keywords and candidate business modules, and semantic blocks with high similarity are grouped into the same business module. For example, semantic blocks such as "enter payment password" and "confirm payment" have a higher similarity to the "payment module" than other modules, and therefore belong to that payment module. Finally, all semantic blocks are traversed to confirm whether the business logic contained in each business module is complete, avoiding content overlap between business modules. Furthermore, the dependencies between business modules can be recorded; for example, the "payment module" depends on the login status of the "user module," providing a basis for subsequent analysis of page flow relationships.

[0069] 202. Construct a graph structure and define the nodes and edges in the graph structure.

[0070] In one embodiment, each page can be viewed as a node in a graph structure, with each node representing an independent page, such as a login page, homepage, or product details page. The flow between pages can be viewed as edges in the graph structure, where an "edge" represents an operation or jump path from one page to another. For example, clicking the "Login" button on the login page to jump to the homepage constitutes an edge.

[0071] 203. Based on the operation response information and business logic corresponding to the page elements, establish the relationship between nodes and edges in the graph structure.

[0072] In one embodiment, various user actions on a page can be analyzed, such as clicking buttons, entering information, selecting drop-down menus, and submitting forms. For example, clicking the "Checkout" button on a shopping cart page triggers a page transition / redirect. Furthermore, for each user action, the system's corresponding action response information (response action) and the resulting page transition can be determined. For instance, after entering the correct username and password on the login page and clicking the "Login" button, the system verifies the information, and the action response is a redirect to the user's homepage; the page transition is a transition edge from the login page to the homepage.

[0073] Then, each user action and its corresponding response information are transformed into edges between nodes in a graph structure. The starting point (source page node) and ending point (target page node) of each edge are clearly defined, as well as the type of action that triggers the edge. For example, the action of "clicking the login button" corresponds to an edge from the login page node to the homepage node, and the edge's attribute records the action type as "click". In addition, relevant attribute information can be added to each edge, which, besides the action type, may also include flow conditions (such as different flow paths when the action succeeds / fails) and data transmission information (such as the username and password data transmitted during login). For example, after entering keywords on the search page and clicking the "search" button, the user is redirected to the search results page. The edge's attributes will record the data transmission information of the search keywords, and the flow condition that is only triggered when the entered keywords are not empty.

[0074] In one embodiment, combining all identified nodes and edges forms a complete directed graph structure that represents the network of possible flow relationships between all pages in the system. In this graph structure, a user can start from any node (page) and travel along edges (flow relationships) to other nodes, thus simulating various user operation paths within the system.

[0075] 204. Assign weight values ​​to each node and edge in the graph structure based on the multidimensional feature information of the business module.

[0076] The node weight values ​​are determined based on multiple dimensions, including the complexity of the business module, user traffic, and importance. The more complex the business logic, the higher the user traffic, or the more critical the business module, the greater the weight value of its corresponding node. Edge weight values ​​are assigned based on factors such as the frequency of flow between business modules and the importance of the business process. The more frequent the flow between business modules or the more critical the flow is in the business process, the greater the weight value of the corresponding edge.

[0077] 205. Based on the graph structure and weight values, a force-directed algorithm is used to generate a flowchart, which is then output in the form of Mermaid code.

[0078] By utilizing a force-directed algorithm to simulate the attractive and repulsive forces between nodes, and combining this with the weights of nodes and edges, the layout of nodes in the graph structure is optimized. This brings closely related nodes closer together, generating a logically laid-out and easily understandable flowchart. The optimized flowchart is output in Mermaid code format, allowing users to visualize and edit it using relevant tools.

[0079] 206. Use a graph traversal algorithm to extract all paths in the flowchart, and expand the paths using a reinforcement learning algorithm.

[0080] In one embodiment, a graph traversal algorithm, such as depth-first search or breadth-first search, is used to traverse the flowchart and extract all possible paths contained therein. Then, a reinforcement learning algorithm is used to expand the extracted paths with objectives such as path coverage, searching for more uncovered path branches to improve the comprehensiveness of path coverage.

[0081] 207. Train the machine learning model using historical test case data to optimize the generation rules.

[0082] In one embodiment, the step of training a machine learning model using historical test case data may include: collecting historical test case data and extracting key features from the historical test case data; inputting the key features into the machine learning model to calculate the prediction result; calculating the loss function based on the prediction result and the pre-labeled actual result; and adjusting the parameters in the machine learning model through backpropagation to minimize the loss function, thereby completing the training. Specifically, test case data that is manually written or automatically generated in past development projects can be collected, including test cases for different functional modules (such as login, payment, search, etc.) and different test scenarios (normal process, abnormal input, boundary conditions, etc.). Then, the test cases are labeled according to multiple dimensions such as the corresponding functional module, test type, and path branch, which facilitates the machine learning model's subsequent learning to distinguish different scenarios.

[0083] Next, valuable features for test case generation can be extracted from the structured data, such as the type and format of the input data, the order and combination of operation steps, the type of expected result, and associated page elements. Historical data is then divided into training, testing, and validation sets. Based on the task requirements for test case generation, an appropriate model is selected. For example, decision tree / random forest models are suitable for handling structured features and can learn the mapping relationship between different input conditions and expected results. Another option is reinforcement learning models, suitable for optimizing test path coverage, which learn how to expand paths to cover more branching paths through a "reward mechanism." Finally, the input, hidden, and output layers of the machine learning model are designed according to the feature dimensions.

[0084] The input to the aforementioned machine learning model can include path branch information from the flowchart, input data from historical test cases, and operational step features. The output consists of predicted test case input data, a sequence of operational steps, and the expected result. During training, the training set data can be input into the machine learning model. The prediction result is calculated through forward propagation and then compared with the results of the actual labeled test cases to calculate the loss function. Backpropagation is then used to adjust model parameters, such as weights and biases, to minimize the loss function. This process is iterated multiple times until the performance of the machine learning model on the validation set no longer shows significant improvement.

[0085] Finally, this embodiment can also use a test set to evaluate the accuracy and effectiveness of the test cases generated by the machine learning model. Common metrics include the proportion of generated test cases covering path branches in the flowchart, the degree of matching between predicted and actual results, and whether the generated test steps conform to business logic. The machine learning model is then iterated based on these metrics. The trained machine learning model is integrated into the automated testing system, and when a new flowchart path branch is input, the machine learning model can automatically generate test cases based on the learned patterns.

[0086] Furthermore, by adding new test cases to the historical dataset and periodically retraining the machine learning model, the model can adapt to changes in business logic and continuously optimize the generated results. For example, when the system adds a "fingerprint login" function, the new test case data will be included in the training samples, and the machine learning model will learn the test pattern of this function, thereby automatically covering the relevant paths in subsequent generation.

[0087] 208. Based on the optimized generation rules and expanded paths, automatically generate test cases covering all paths using a machine learning model, and output the test cases in Markdown code format.

[0088] In one embodiment, generation rules trained based on a machine learning model are combined with business logic constraints to form standardized test case generation rules. For example, a generation rule might define "when the path includes a payment node, the input data must include a valid payment method and the expected result must verify the consistency of the amount." All path branches extended by reinforcement learning are associated with the generation rules to clarify the testing focus for each path. Then, based on the page elements and business rules involved in the path, valid and invalid input data can be generated and input into the machine learning model, which then outputs the expected results. For example, when an invalid email address is entered, the expected result is "Incorrect email format"; after a normal payment, the expected result is "Order status updated to paid." Finally, the verified test cases can be batch-converted into Markdown code, and information such as the test case generation time, associated flowchart version, and model version can be recorded to ensure traceability. When the target document or flowchart is updated, test cases that need to be regenerated are automatically marked to avoid version conflicts.

[0089] In one embodiment, the method may further include: receiving feedback information regarding test cases and adjusting the test cases based on the feedback information. Specifically, user feedback information regarding test cases can be received through system interfaces, file uploads, API interfaces, etc. Then, natural language processing technology is used to extract key elements from the feedback information, such as problem type, associated module, specific location, and modification suggestions. Based on the test case number, module name, or step description in the feedback information, the corresponding Markdown code block is quickly located, and the feedback information is associated with elements such as the input data, steps, and expected results of the test cases. For feedback information with clearly defined rules, the system can automatically correct it. For feedback information involving business logic, adjustment suggestions can be generated based on historical business rules, which are then executed after user confirmation. For example, if inconsistent column numbers are detected in a Markdown table, the column structure is automatically adjusted; if disordered test step numbers are detected, they are reordered. For another example, if a user reports that "the payment process needs to add SMS verification," the system automatically inserts a "Enter SMS verification code" step into the test steps and generates the corresponding expected result "Verification code verification passed," waiting for user confirmation to save.

[0090] In one embodiment, if the above adjustments involve adding new path coverage, the path coverage of the flowchart can be recalculated to ensure that the adjusted coverage does not decrease. If necessary, a reinforcement learning algorithm can be triggered to re-expand the paths. If the test cases are associated with multiple versions of the flowchart or target document, the affected versions are automatically marked, and the user is prompted whether to adjust the test cases of other versions simultaneously to avoid information conflicts between different versions.

[0091] As described above, the test case generation method proposed in this application can perform target operations on a target document according to operation instructions to obtain the corresponding business module, extract the business logic and page elements of each business module, construct a graph structure and define the nodes and edges in the graph structure, establish the association relationship between the nodes and edges in the graph structure based on the operation response information and business logic corresponding to the page elements, assign weight values ​​to each node and edge in the graph structure according to the multi-dimensional feature information of the business module, generate a flowchart using a force-directed algorithm based on the graph structure and weight values, and output the flowchart in Markdown code form, extract all paths in the flowchart using a graph traversal algorithm, expand the paths using a reinforcement learning algorithm, train the machine learning model using historical test case data to optimize the generation rules, automatically generate test cases covering all paths using the machine learning model based on the optimized generation rules and expanded paths, and output the test cases in Markdown code form. The solution provided in this application embodiment does not rely on human experience and can automatically analyze the business logic and page elements in the target document. It can also automatically generate test cases through machine learning models and dynamically adjust the test strategy according to changes in business logic. This overcomes the shortcomings of existing technologies that can only use fixed templates to generate test cases, thereby effectively improving the efficiency and effectiveness of test case generation.

[0092] For example, such as Figure 3 The diagram shown is a structural schematic of a test case generation device provided in an embodiment of this application. The test case generation device may include:

[0093] The receiving unit 301 is used to perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and to extract the business logic and page elements of each business module;

[0094] The determining unit 302 is used to determine the page flow relationship based on the business logic and page elements;

[0095] Generation unit 303 is used to generate a flowchart based on the page flow relationship using a force-guided algorithm;

[0096] Output unit 304 is used to generate test cases covering all paths in the flowchart based on a machine learning model, and output the test cases in the form of preset code.

[0097] The test case generation device proposed in this application can perform target operations on a target document according to operation instructions to obtain the corresponding business modules, extract the business logic and page elements of each business module, determine the page flow relationship based on the business logic and page elements, generate a flowchart based on the page flow relationship using a force-directed algorithm, generate test cases covering all paths in the flowchart based on a machine learning model, and output the test cases in the form of preset code. The solution provided in this application does not rely on human experience and can automatically analyze the business logic and page elements in the target document, and automatically generate test cases through a machine learning model. Moreover, it can dynamically adjust the test strategy according to changes in business logic, overcoming the shortcomings of existing technologies that can only use fixed templates to generate test cases, thereby effectively improving the efficiency and effectiveness of test case generation.

[0098] This application also provides a terminal device, such as... Figure 4 As shown, the terminal device 400 may include a memory 401 and a processor 402. The memory 401 stores an application processing program, which, when executed by the processor 402, implements the steps of the test case generation method described above in this embodiment.

[0099] Specifically, in this embodiment, the processor 402 in the terminal device 400 loads the executable files corresponding to the processes of one or more applications into the memory 401 according to the following instructions, and the processor 402 runs the applications stored in the memory 401 to achieve various functions:

[0100] Perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and extract the business logic and page elements of each business module;

[0101] The page flow relationship is determined based on the business logic and page elements;

[0102] A flowchart is generated based on the page flow relationship using a force-guided algorithm;

[0103] Test cases covering all paths in the flowchart are generated based on a machine learning model, and the test cases are output in the form of preset code.

[0104] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed description of the test case generation method above, which will not be repeated here.

[0105] As can be seen from the above, the terminal device in this embodiment can perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, extract the business logic and page elements of each business module, determine the page flow relationship based on the business logic and page elements, generate a flowchart based on the page flow relationship using a force-directed algorithm, generate test cases covering all paths in the flowchart based on a machine learning model, and output the test cases in the form of preset code. The solution provided by this embodiment does not rely on human experience and can automatically analyze the business logic and page elements in the target document, automatically generate test cases through a machine learning model, and dynamically adjust the test strategy according to changes in business logic, thereby overcoming the shortcomings of existing technologies that can only use fixed templates to generate test cases, thus effectively improving the generation efficiency and effectiveness of test cases.

[0106] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0107] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of instructions that can be loaded by a processor to execute steps in any of the test case generation methods provided in embodiments of this application.

[0108] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0109] Since the instructions stored in the storage medium can execute the steps in any of the test case generation methods provided in the embodiments of this application, the beneficial effects that any of the test case generation methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.

[0110] The above provides a detailed description of a test case generation method, apparatus, terminal device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A test case generation method, characterized in that, include: Perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and extract the business logic and page elements of each business module; The page flow relationship is determined based on the business logic and page elements; A flowchart is generated based on the page flow relationship using a force-guided algorithm; Test cases covering all paths in the flowchart are generated based on a machine learning model, and the test cases are output in the form of preset code.

2. The test case generation method as described in claim 1, characterized in that, The process of performing target operations on the target document to obtain the corresponding business module includes: Convert the document format of the target document; The target document after format conversion is processed, including text cleaning, word segmentation, and part-of-speech tagging; Semantic analysis is performed on the processed target document to extract business modules.

3. The test case generation method as described in claim 1, characterized in that, The step of determining the page flow relationship based on the business logic and page elements includes: Construct a graph structure and define the nodes and edges in the graph structure; Based on the operation response information corresponding to the page elements and the business logic, the association relationship between nodes and edges in the graph structure is established.

4. The test case generation method as described in claim 3, characterized in that, The process of generating a flowchart based on the page flow relationship using a force-guided algorithm includes: Assign weight values ​​to each node and edge in the graph structure based on the multidimensional feature information of the business module; Based on the graph structure and weight values, a force-directed algorithm is used to generate a flowchart, which is then output in Mermaid code form.

5. The test case generation method as described in claim 1, characterized in that, The generation of test cases based on the machine learning model, covering all paths in the flowchart, includes: All paths in the flowchart are extracted using a graph traversal algorithm, and the paths are expanded using a reinforcement learning algorithm. The machine learning model is trained using historical test case data to optimize the generation rules; Based on the optimized generation rules and expanded paths, the machine learning model automatically generates test cases that cover all paths in the flowchart.

6. The test case generation method as described in claim 5, characterized in that, The step of training the machine learning model using historical test case data includes: Collect historical test case data and extract key features from the historical test case data; The key features are input into the machine learning model to calculate the prediction result, and the loss function is calculated based on the prediction result and the pre-labeled actual result; The parameters in the machine learning model are adjusted through backpropagation to minimize the loss function, thereby completing the training.

7. The test case generation method according to any one of claims 1-6, characterized in that, The method further includes: Receive feedback information for the test cases and adjust the test cases based on the feedback information.

8. A test case generation device, characterized in that, include: The receiving unit is used to perform target operations on the target document according to the operation instructions to obtain the corresponding business modules, and to extract the business logic and page elements of each business module; The determining unit is used to determine the page flow relationship based on the business logic and page elements; The generation unit is used to generate a flowchart based on the page flow relationship using a force-guided algorithm; The output unit is used to generate test cases covering all paths in the flowchart based on the machine learning model, and output the test cases in the form of preset code.

9. A terminal device, characterized in that, The terminal device includes: a memory and a processor, wherein the memory stores an application processing program, and when the application processing program is executed by the processor, it implements the steps of the test case generation method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The storage medium stores multiple instructions adapted for loading by a processor to execute the test case generation method according to any one of claims 1 to 7.