Test case generation method and device, equipment and medium
By extracting and clustering step information in test cases and using large language models for step adjustment, the problem of inefficient current test case generation methods is solved, more efficient and comprehensive test case generation is achieved, and software testing efficiency and quality is improved.
Patent Information
- Application Number
- CN202510180961.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-19
- Publication Date
- 2025-03-21
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing test case generation methods are inefficient, making it difficult for testers to quickly generate comprehensive test cases, insufficient test coverage, and potential defects are not discovered, affecting the quality of software and user experience.
By extracting the test script functions and description information in the test cases, clustering to obtain similar step information, using the preset large language model to adjust the test cases step by step to generate new test cases.
It improves the generation efficiency and coverage of test cases, makes full use of existing test resources, avoid resource waste, effectively covers potential defects of the software, and improves software testing efficiency and product quality.
Smart Images

Figure CN119669027A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software testing, and in particular to a test case generation method, device, equipment and medium. Background Art
[0002] As the complexity and scale of software systems continue to grow, the writing and maintenance of test cases in software testing becomes increasingly arduous.
[0003] The traditional way of writing test cases mainly relies on manual writing. Testers need to manually design test cases based on requirement documents and design documents. However, this method has many shortcomings, which seriously restricts test efficiency and test quality: First, manual writing of test cases is time-consuming and labor-intensive, and inefficient. In a fast-iterative development environment, testers often find it difficult to keep up with the project progress and write comprehensive test cases in a timely manner. This not only increases the work pressure of testers, but also limits the timeliness and effectiveness of testing work. At the same time, due to time and manpower constraints, testers may not be able to fully consider all test scenarios, resulting in insufficient test coverage. The risk of potential defects not being discovered increases, which in turn affects the overall quality of the software and user experience. In addition, the quality of manual test cases also depends on the personal experience of testers. The step description of the test case lacks standardization, and the expected results are usually not clear enough. These problems may affect the execution of the test and the accuracy of the results.
[0004] In recent years, with the rapid development of artificial intelligence technology, test case generation methods based on large language models (LLM) have begun to be applied in the field of software testing. For example, using advanced large language models such as GPT (Generative Pre-trained Transformer, generative pre-training based on transformer) models, test cases can be directly and automatically generated based on the requirements description. However, these methods also have problems such as insufficient accuracy, lack of path analysis and combination, and insufficient utilization of existing resources. The model may generate content that does not meet the actual requirements, and there is a "hallucination" phenomenon, which affects the accuracy of the test cases. At the same time, these methods often fail to perform path analysis and combination of test steps, and cannot effectively generate new test cases. In addition, traditional large language models are also unable to fully utilize existing resources such as manual test cases, defect reproduction paths, and automated script functions, resulting in a waste of resources. Summary of the invention
[0005] The main purpose of the present invention is to provide a test case generation method, device, equipment and medium, aiming to solve the technical problem of low efficiency of existing test case generation methods.
[0006] A first aspect of the present invention provides a test case generation method, which includes: extracting a test script function and description information of each test step in a first test case; clustering the test steps based on the test script function and the description information to obtain similar step information; and adjusting the steps of the first test case based on a preset first large language model and the similar step information to obtain a second test case.
[0007] Optionally, in a first implementation method of the first aspect of the present invention, the test steps are clustered based on the test script function and the description information to obtain similar step information, including: when the test script functions are the same, the corresponding test steps are classified into the same category to obtain first similar information; the semantic similarity between each descriptive information is calculated, and the test steps whose semantic similarity is greater than a preset similarity threshold are classified into the same category to obtain second similar information; and the first similar information and the second similar information are merged to obtain the similar step information.
[0008] Optionally, in a second implementation of the first aspect of the present invention, the step adjustment of the first test case based on the preset first large language model and the similar step information includes: Based on the similar step information, the test steps in the first test case are replaced with corresponding similar steps; and / or based on the preset first large language model, the insertable position and the corresponding insertion condition in the first test case are determined, and the test case that meets the insertion condition is inserted into the insertable position; and / or based on the preset first large language model, the deletable steps in the first test case are determined, and the corresponding test steps are deleted from the first test case; and / or based on the similar step information, the common step positions of different first test cases are determined, the corresponding first test cases are intercepted at the common step positions, and the intercepted different first test cases are reorganized at the common step positions.
[0009] Optionally, in a third implementation method of the first aspect of the present invention, after extracting the test script function and description information of each test step in the first test case, it also includes: based on each of the test steps, generating a corresponding test node, the test node corresponding one-to-one to the test step; based on the order of the test steps, adding directed edges between each of the test nodes to generate a test case graph structure.
[0010] Optionally, in the fourth implementation method of the first aspect of the present invention, after adding directed edges between each of the test nodes based on the order of the test steps to generate a test case graph structure, it also includes: traversing the test case graph structure to obtain the second test case.
[0011] Optionally, in a fifth implementation manner of the first aspect of the present invention, after adjusting the steps of the first test case based on the preset first largest language model and the similar step information to obtain the second test case, it also includes: verifying the business logic of the second test case based on the preset second largest language model to determine a feasible test case; performing step analysis on the feasible test case based on a preset third largest language model, and generating optimization instructions when it is determined that there is a defect in the corresponding test step; and optimizing the second test case based on the optimization instructions.
[0012] Optionally, in the sixth implementation method of the first aspect of the present invention, after adjusting the steps of the first test case based on the preset first large language model and the similar step information to obtain the second test case, it also includes: associating the test script function corresponding to the second test case to generate an automated test script.
[0013] The second aspect of the present invention also provides a test case generation device, which includes: an extraction module, used to extract the test script function and description information of each test step in a first test case; a clustering model, based on the test script function and the description information, clustering the test steps to obtain similar step information; an adjustment module, based on a preset first large language model and the similar step information, performing step adjustment on the first test case to obtain a second test case.
[0014] The third aspect of the present invention also provides a computer device, which includes: a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the computer device executes the test case generation method as described above.
[0015] A fourth aspect of the present invention further provides a computer-readable storage medium, on which instructions are stored, and when the instructions are executed by a processor, the test case generation method as described above is implemented.
[0016] The embodiment of the present invention provides a test case generation method, device, equipment and storage medium, which first extracts the test script function and description information of each test step in the first test case, and then clusters the test steps based on the test script function and the description information to obtain similar step information; based on the preset first large language model and the similar step information, the first test case is adjusted to obtain a second test case. The present invention can automatically generate test cases, reduce the time and cost of manually writing test cases, effectively improve the generation efficiency and coverage of test cases, make full use of existing test resources, avoid resource waste, effectively cover potential defects in the software, thereby improving software testing efficiency and ensuring software product quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of a flow chart of an embodiment of a method for generating a test case in an embodiment of the present invention; Figure 2 for Figure 1 A schematic diagram of a flow chart of an embodiment after step 101 in the embodiment; Figure 3 for Figure 2 A schematic diagram of the structure of an example of a test case diagram structure 1 in the embodiment; Figure 4 for Figure 1 A flow chart of an embodiment of step 102 in the embodiment; Figure 5 for Figure 1 A schematic flow chart of an embodiment of step 103 in the embodiment; Figure 6 for Figure 1 A schematic diagram of a flow chart of an embodiment after step 103 in the embodiment; Figure 7 This is a functional module diagram of an embodiment of a test case generation device according to an embodiment of the present invention; Figure 8 The figure is a functional module diagram of an embodiment of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION
[0018] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0019] For ease of understanding, the specific process of the test case generation method in the embodiment of the present invention is described below. The test case generation method of this embodiment is applied to electronic devices, which can be terminals, such as smart phones, laptops, tablet computers, desktop computers, etc., or development boards, chip systems, etc. Please refer to Figure 1 , Figure 1 The first embodiment of the test case generation method in the embodiment of the present invention is a flow chart of the first embodiment. In this embodiment, the test case generation method includes: 101. Extracting the test script function and description information of each test step in the first test case; In this embodiment, the first test case is an existing test case, which can specifically be a manually written test case, a defect reproduction path, and a test script, etc., wherein a manual test case refers to a test case manually designed by a tester according to a requirement document and a design document, a defect reproduction path refers to a sequence of operation steps that can cause software defects to be reproduced, and a test script is a code implementation for automated testing. The first test case includes one or more of the corresponding test steps, description information, operation type, target object, and associated automated script function information. Therefore, the test script function and description information of each test step can usually be specifically extracted from the first test case, wherein the test script function refers to the code function used to execute the test step, and the description information refers to the explanatory text of the test step. The purpose of extracting this information is to perform cluster analysis and step adjustment on the test steps later.
[0020] In this embodiment, an example of a first test case is specifically provided to illustrate the form of the first test case. The example of the first test case provided is also used to illustrate the corresponding steps in the description of the subsequent steps. In each example, the test script function corresponding to each test step is in brackets, and the description outside the brackets is the corresponding description information. Specifically, the four first test cases provided in this application specifically include: Manual test case 1, which is used to represent the steps of purchasing product P1 through the product details page. The manual test case 1 includes an identifier TC001 for unique identification, and the corresponding test steps specifically include: step A, user login (login(username, password)); step B, browse product P1 details (browse_product(product_id_p1)); step C, add product P1 to the shopping cart (add_to_cart(product_id_p1)); step D, view the shopping cart (view_cart()); step E, submit the order (submit_order()); step F, pay the order (pay_for_order()), and the corresponding expected results are successful order submission and successful payment.
[0021] Manual test case 2, which is used to represent the steps of purchasing product P2 directly from the shopping cart. The identifier of manual test case 2 is TC002, and the corresponding test steps specifically include: step A, user login (login(username, password)); step D', open the shopping cart (open_cart()); step I, select product P2 (select_product_in_cart(product_id_p2)); step E', order submission (submit_order()); step F', order payment (pay_for_order()), and the corresponding expected results are successful order submission and successful payment.
[0022] Defect reproduction path 1, which is used to represent the steps of the defect situation that the product P1 can still be added to the shopping cart when the stock is insufficient. The identifier of the defect reproduction path 1 is BUG101, and the test steps of the corresponding defect reproduction specifically include: A, user login (login(username, password)); step B, browse the details of product P1 (browse_product(product_id_p1)); step C', add the insufficient stock product P1 to the shopping cart (add_to_cart(product_id_p1_out_of_stock)); step D, view the shopping cart (view_cart()); step E, submit the order (submit_order()). The corresponding actual result is that the order is submitted successfully, but the subsequent payment cannot be made, and the order status is abnormal.
[0023] Defect reproduction path 2, which is used to represent the steps of using coupons during payment to cause the system to report an error. The identifier of the defect reproduction path 2 is BUG102, and the corresponding test steps for defect reproduction include: step A, user login (login(username, password)); step D', open the shopping cart (open_cart()); step I, select product P1 (select_product_in_cart(product_id_p1)); step E', order submission (submit_order()); step J, use coupons (apply_coupon(coupon_code)); step F', order payment (pay_for_order()). The corresponding actual result is that the system reports an error and the payment cannot be completed.
[0024] In this embodiment, manual test case 1 and manual test case 2 respectively show different test scenarios of purchasing goods through the product details page and purchasing goods directly from the shopping cart, and defect reproduction path 1 and defect reproduction path 2 respectively show the test steps for two defect situations: adding goods to the shopping cart when the inventory is insufficient and using coupons during payment, which causes the system to report an error. The four test cases are used to illustrate different test scenarios and defect situations. The functions and performance of the software can be fully verified through the setting of similar first test cases. This embodiment extracts the test script functions and description information of each corresponding test step from the existing first test case, and can subsequently perform cluster analysis on the test steps based on this information, and adjust the test cases based on the results of the cluster analysis, thereby generating new test cases, which can effectively improve the generation efficiency and coverage of test cases, make full use of existing test resources, and avoid waste of resources.
[0025] Optionally, see Figure 2 In one embodiment, after extracting the test script function and description information of each test step in the first test case, it also includes: 1011. Generate corresponding test nodes based on each test step, where the test nodes correspond to the test steps one by one; 1022. Based on the order of the test steps, add directed edges between the test nodes to generate a test case graph structure.
[0026] In this optional embodiment, the test node is a graphical element used to represent each test step in the test case, and each test node contains the test script function and description information of the corresponding test step. The directed edges added based on the order of the test steps, that is, the graph lines pointing from the previous step to the next step, represent the execution order relationship between the test steps, thereby generating a graph structure that can intuitively display the test case execution process. Such a test case graph structure is helpful for subsequent more in-depth analysis and processing of the test case.
[0027] In this optional embodiment, referring to the example of the first test case mentioned above, the node list of the test node specifically includes: node A, user login (login(username, password)); Node B, browse product p1 details (browse_product(product_id_p1)); Node C, add product p1 to the shopping cart (add_to_cart(product_id_p1)); Node C', add product p1 that is out of stock to the shopping cart (add_to_cart(product_id_p1_out_of_stock)); Node D, view the shopping cart (view_cart()); Node D', open the shopping cart (open_cart()); Node E, submit the order (submit_order()); Node E', order submission (submit_order()); Node F, pay for the order (pay_for_order()); Node F', order payment (pay_for_order()); Node I, select product p2 (select_product_in_cart(product_id_p2)); Node J, apply coupons (apply_coupon(coupon_code)), which are connected by directed edges based on the execution order of the above examples. The corresponding test case graph structure can be found in Figure 3 .
[0028] Optionally, in one embodiment, after adding directed edges between test nodes based on the order of test steps to generate a test case graph structure, the method further includes: traversing the test case graph structure to obtain a second test case.
[0029] In this optional embodiment, the second test case refers to a newly generated test case that does not appear in the existing first test case. After obtaining the test case graph structure, part of the second test case can be obtained by traversing the test case graph structure. For example, on the basis of the above-mentioned four first test cases, a test case is also included, and its path is: A→D'→E'→F'. Therefore, on this basis, a previously undiscovered path will appear in the test case graph structure, namely: A→D'→E'→J→ F'. The newly discovered path is a second test case.
[0030] In this optional embodiment, by traversing the test case graph structure to obtain a test path containing all test steps, the second test case of this type can be found. Among them, the traversal method can be a traversal method such as depth-first search or breadth-first search. By traversing the test graph structure, a test path containing all test steps can be automatically generated without manual writing, thereby further improving the generation efficiency and automation of test cases. In other subsequent methods for generating second test cases, the test graph structure can also be used for clustering and adjustment to quickly discover more second test cases, so that the generated second test cases are more comprehensive and efficient, which is conducive to improving test efficiency and test coverage.
[0031] 102. Cluster the test steps based on the test script function and description information to obtain similar step information; In the present embodiment, after determining the test script function and description information, clustering the test steps refers to classifying the test steps with similar functions or operations together so that similar steps can be uniformly processed or optimized later. Clustering can be based on factors such as the similarity of the test script function, keyword matching of the description information, the operation type or target object of the test steps. Through clustering, complex test cases can be decomposed into parts that are easier to manage and optimize, thereby improving the flexibility and maintainability of the test cases. The obtained similar step information is the clustered test step set, in which the test steps in each set have certain similarities, which helps to adjust and optimize the steps of the test cases later, thereby improving the generation efficiency and test coverage of the test cases.
[0032] Optional, see Figure 4 In one embodiment, based on the test script function and description information, the test steps are clustered to obtain similar step information, including: 1021. When the test script functions are the same, the corresponding test steps are classified into the same category to obtain first same category information; 1022. Calculate the semantic similarity between each description information, classify the test steps whose semantic similarity is greater than a preset similarity threshold into the same category, and obtain second same category information; 1023. Combine the first information of the same type and the second information of the same type to obtain information of the same type of steps.
[0033] In this optional embodiment, a clustering method using the consistency of script functions and the semantic similarity of description information is specifically described. Among them, the consistency of script functions means that if the test script functions of two or more test steps are exactly the same, they are likely to perform the same operation or function, so they can be classified into the same category. For example, in the above-mentioned manual test case 1 and manual test case 2, the script functions used by step E of submitting an order and step E' of order submission are both submit_order(), and the script functions used by step F of order payment and step F' of paying the order are both pay_for_order(), then step E and step E' can be classified into the same category, and step F and step F' can be classified into the same category. The semantic similarity of description information means that if the description information of two or more test steps is semantically close or similar, they may involve the same test scenario or goal, so they can also be classified into the same category. For example, in the above test case, although the test script functions of step D's view_cart() and step D's open_cart() are different, their description information involves browsing the information in the shopping cart. It can be considered that they have certain similarities in semantics, so they can also be classified into the same category according to the preset similarity threshold. Through such a clustering method, similar steps can be identified more accurately, providing a more reliable basis for the adjustment of subsequent steps.
[0034] In this optional embodiment, the consistency of the script function can be determined by directly comparing the name or parameters of the test script function, wherein the function parameters of different objects of the same type in the function can also be defined in a normalized manner. For example, the "id_p1" and "id_p2" fields in the parameters are both used to represent the identification number of the product, and the field "id" can be uniformly used. For example, the browse_product(product_id_p1) function can be adjusted to the browse_product(product_id) function.
[0035] In this optional embodiment, the semantic similarity of the description information can be calculated by a text similarity algorithm, for example, using algorithms such as cosine similarity, Jaccard similarity or edit distance to measure the similarity between the description information. In the calculation of semantic similarity, it is usually necessary to introduce word segmentation and vectorization (Embedding) processing. Word segmentation refers to splitting the text in the description information into independent vocabulary units. For example, "add insufficient inventory of product P1 to the shopping cart" can be segmented into "add / inventory / insufficient / product P1 / to / the shopping cart" for corresponding vectorization processing, and vectorization is the process of treating the segmented vocabulary as an object (Object) and converting the object into a numerical feature vector for calculation. Through word segmentation and vectorization, the description information can be converted into a format that can be understood by the computer, so as to calculate the semantic similarity. In addition. When calculating the semantic similarity of the description information, it is also possible to consider removing stop words in the description information, performing stem extraction or word form restoration and other pre-processing steps to improve the accuracy of the similarity calculation.
[0036] In this optional embodiment, by clustering each step in each first test case, or by using the above-mentioned node list, the corresponding clustering results can be obtained, and the corresponding clustering results specifically include: class 1, node A (user login) (login(username, password)); class 2, node B (browse product P1 details); class 3, node C (add product to shopping cart) (add_to_cart(product_id)); class 4, node D, node D' (view / open shopping cart) (view_cart() / open_cart()); class 5, node E, node E' (submit order) (submit_order()); class 6, node F, node F' (pay order) (pay_for_order()); class 7, node I (select product) (select_product_in_cart(product_id)); class 8, node C' (add out-of-stock product to shopping cart) (add_to_cart(product_id_out_of_stock)); class 9, node J (apply coupon) (apply_coupon(coupon_code)).
[0037] In this optional embodiment, the aforementioned test case graph structure can be used on the basis of the above to define test cases of multiple main paths and test cases of defect paths. Based on the clustered nodes, the main path and defect path are composed of specific node sequences, representing the existing manual test cases and defect reproduction paths. Specifically, it can include main path 1 (manual test case 1), whose path includes: node A (class 1), user login; node B (class 2), browsing product P1 details; node C (class 3), adding product P1 to the shopping cart; node D (class 4), viewing the shopping cart; node E (class 5), submitting an order; node F (class 6): paying an order, and its path can be expressed as A→B→C→D→E→F. Similarly, main path 2, i.e. manual test case 2, can be expressed as A→D'→I→E'→F', defect path 1, i.e. defect reproduction path 1, can be expressed as A→B→C'→D→E, and defect path 2, i.e. defect path reproduction path 2, can be expressed as A→D'→I→E'→J→F'.
[0038] In this optional embodiment, by combining the consistency of the test script function and the semantic similarity of the description information for clustering, similar steps in the test case can be identified more comprehensively and accurately, improving the accuracy and reliability of clustering. After obtaining the similar step information, it can be used in the subsequent test case adjustment steps to generate more efficient and comprehensive test cases. At the same time, through cluster analysis, it is also possible to find redundant or repeated steps that may exist in the test case, thereby further optimizing the quality of the test case, improving the reusability and pertinence of the test case, reducing the test cost, and improving the test efficiency.
[0039] 103. Based on the preset first language model and similar step information, the first test case is adjusted in steps to obtain a second test case.
[0040] In this embodiment, the preset first language model is a model built based on deep learning technology, with powerful natural language understanding and generation capabilities. The model can receive input natural language text, understand its meaning, and generate new natural language text according to preset rules or patterns. The first language model can guide its adjustment processing of the first test case based on different prompts or context information. In the process of step adjustment, the preset first language model can generate new test steps that are similar to but not completely the same as the existing test steps according to the test script function and description information in the same type of step information. In this embodiment, the preset first language model is used to adjust the steps of the first test case, that is, according to the same type of step information, the test steps in the first test case are recombined or adjusted to generate a new test case, that is, the second test case. Among them, the step adjustment can specifically include operations such as adjusting the order of the test steps, replacing some test steps, adding new test steps, or deleting redundant test steps. Through step adjustment, more diverse test cases can be generated, covering more test scenarios and defect situations, thereby improving the comprehensiveness and accuracy of the test. At the same time, by using the preset first language model for step adjustment, the powerful capabilities of the preset first language model can be fully utilized to realize the automatic generation and optimization of test cases, improve test efficiency and test coverage, and realize the efficient generation and optimization of test cases.
[0041] Optional, see Figure 5 In one embodiment, based on the preset first language model and similar step information, the first test case is adjusted in steps, including: 1031. Based on the similar step information, replace the test steps in the first test case with corresponding similar steps; and / or 1032. Determine an insertable position and a corresponding insertion condition in the first test case based on a preset first language model, and insert the test case satisfying the insertion condition into the insertable position; and / or 1033. Determine deletable steps in the first test case based on the preset first language model, and delete corresponding test steps from the first test case; and / or 1034. Based on the similar step information, determine the common step positions of different first test cases, intercept the corresponding first test cases at the common step positions, and reorganize the intercepted different first test cases at the common step positions.
[0042] In this optional embodiment, a plurality of methods for adjusting the steps of the first test case are specifically described. During the specific implementation, one or more of these methods may be used to process the first test case to generate a corresponding second test case.
[0043] In this optional embodiment, step 1031 is a way of replacing steps, which is a node replacement method based on the test case graph structure, and can replace a node step with another node step of the same class in the test path. In the process of this replacement, the replaced nodes usually have similar functions, but there are differences in parameters or conditions, and the performance of the same operation under different conditions can be tested. For example, a first test case is the main path 1, that is, A→B→C→D→E→F, where node C is in class 3, indicating that product P1 is added to the shopping cart. If there is also a node C'' in class 3, indicating that product P2 is added to the shopping cart, a second test case can be obtained, and its path is A→B→C''→D→E→F. Through the obtained second test case, the situation where the user browses product P1 but adds product P2 to the shopping cart can be tested, thereby verifying the product selection logic of the software system.
[0044] In this optional embodiment, step 1032 is a step insertion method, which is a node insertion method based on the test case graph structure, and can insert a new node at the appropriate position of the test path to test the impact of the newly added function or step. In the process of the insertion, it is necessary to ensure that the inserted node has a business logic association with the previous and next steps, and does not destroy the original dependency relationship, so as to ensure the integrity and validity of the test case. For example, the path of a first test case is the main path 1, that is, A→B→C→D→E→F. If it is expected to insert the node J of using the coupon before the node E that submits the order, for this, the preset first large language model will analyze the node E and its preceding and succeeding nodes, and determine the rationality of inserting the node J before the node E, that is, the insertion condition. After confirming that the insertion of the node J meets the insertable condition, it can be determined that the corresponding insertable position is between the node D and the node E, so that the node J is inserted into the insertable position, thereby obtaining a second test case, whose path is A→B→C→D→J→E→F. Through the second test case, the scenario of the user using the coupon before placing an order can be tested to verify the correctness of the coupon function.
[0045] In this optional embodiment, step 1033 is a way of deleting steps, which is a node deletion method based on the test case graph structure, and can delete a node from the test path to simplify the test process. In the process of deletion, it is necessary to ensure that the deleted node will not affect the execution of subsequent steps in the test case, and its removal will not destroy the business logic and dependencies, ensuring the accuracy and effectiveness of the test case. For example, the path of a first test case is the main path 1, that is, A→B→C→D→E→F. If it is expected that the test user directly submits an order without viewing the shopping cart, the node D of viewing the shopping cart can be deleted, thereby obtaining a second test case, whose path is A→B→C→E→F. Through this second test case, the scenario in which the user skips the step of viewing the shopping cart and directly submits the order can be tested to verify whether the software system supports the operation of skipping the shopping cart view.
[0046] In this optional embodiment, step 1034 is a method of path merging, path bifurcation and reorganization, which is a path reorganization method based on the test case diagram structure. It can merge different test paths at common step positions to form a new path, and connect parts of different paths to test new operation sequences and business processes. By combining different starting points, intermediate steps and subsequent processes, complex business scenarios can be tested. For example, the paths of two first test cases are main path 1 and main path 2, namely A→B→C→D→E→F and A→D'→I→E'→F', wherein the common step positions are the existing similar nodes, namely the node A commonly included by both, and the similar nodes D and D', nodes E and E', nodes F and F', wherein, by regarding nodes D and D' as the same node, and regarding nodes E and E' as the same node, multiple intercepted paths can be obtained, namely path A→B→C→D / D', path A→D / D', path D / D'→E / E', path D / D'→I→E / E', and path E / E'→F / F'. Therefore, different second test cases can be reorganized accordingly. For example, the path of a second test case can be A→B→C→D→I→E→F, that is, in the main path 1, the node I of the main path 2 is merged, and the test user directly selects the product P2 in the shopping cart to purchase after viewing the shopping cart.
[0047] In this optional embodiment, step 1034 can support path interception and reorganization of multiple test cases. For example, the paths of three first test cases are main path 1, defect path 1 and defect path 2, namely A→B→C→D→E→F, A→B→C'→D→E and A→D'→I→E'→J→F'. In these test cases, common step positions can be identified, such as node A, node B, node C / C' which can be regarded as the same node, node D / D' which can be regarded as the same node, node E / E' which can be regarded as the same node, and node F / F' which can be regarded as the same node. Based on these common step positions, path interception and reorganization can be performed. For example, the A→B→C→D part of the main path 1 can be combined with the D'→I→E'→J→F' of the defective path 2, and the same nodes D, E, and F are used for the D', E', and F' nodes, respectively, to obtain a second test case path A→B→C→D→I→E→J→F, that is, starting from the starting point A of the main path 1, passing through nodes B and C, then forking at node D (viewing the shopping cart), adding node I (selecting product P2), passing through node E (submitting the order), inserting node J (using coupons), and finally reaching node F (paying the order). This tests the complex scenario where the user selects product P1 and product P2 in the shopping cart at the same time and uses coupons. Through such path reorganization, more complex and diverse business scenarios can be tested, and the coverage and effectiveness of test cases can be improved. At the same time, this method of path merging and path forking and reorganization can also help discover potential defects and anomalies and improve the quality and stability of software systems.
[0048] This optional embodiment can obtain more second test cases through the above-mentioned path combination method. These test cases cover different test scenarios and business logics, thereby improving the comprehensiveness and accuracy of the test, being able to effectively cover more software functions and business processes, being able to discover potential defects and anomalies that may exist in the software system, and further improving the quality and stability of the software system. At the same time, since these test cases are generated in an automated manner, the test efficiency can be greatly improved, and the workload of manual test case writing and testing can be reduced. This method can also simplify the design process of test cases based on graph structure and clustering processing, making the generation of test cases more efficient and intelligent. In addition, this method can also flexibly adjust the complexity and coverage of the test cases according to actual test requirements to meet the requirements of different test stages and test objectives, and ensure the quality and stability of the software system.
[0049] Optional, see Figure 6 In one embodiment, after adjusting the steps of the first test case based on the preset first large language model and the similar step information to obtain the second test case, the method further includes: 1035. Verify the business logic of the second test case based on the preset second largest language model to determine a feasible test case; 1036. Perform step analysis on feasible test cases based on the preset third language model, and generate optimization instructions when it is determined that the corresponding test steps have defects; 1037. Optimize the second test case based on the optimization instruction.
[0050] In this optional embodiment, the preset second largest language model is a model for path feasibility analysis, which can receive the test case path as input and verify the feasibility of the path based on business logic and rules. The corresponding rules can be manually input into the large language model and the large language model can be trained and fine-tuned through prompt words to make the preset second largest language model, or it can be built-in in the large language model or obtained from the business logic library through retrieval-augmented generation (RAG) technology. These rules are manually configured or the large language model can understand strong binding restriction rules, such as the live broadcast of the product should not be viewed before submitting the order and paying the order, and the new order should not be created. The account cannot be cancelled before the electronic account assets are transferred or cancelled. Through the business logic verification of the preset second largest language model, it can be determined whether there are steps that violate the business logic or rules in the second test case, so as to screen out feasible test cases. Through the verification of the second largest language model, it can be ensured that the generated second test case conforms to the actual business logic and requirements, thereby avoiding invalid or erroneous test cases and improving the accuracy and effectiveness of the test. For the test case that passes the verification, it can be used as a feasible test case for subsequent test execution steps. For example, for the second test case A→B→C→D →J→E→F obtained above, the second largest language model can verify and determine that the steps of using coupon J before submitting order E comply with business rules, thereby determining that the second test case is feasible, and the corresponding test case can effectively execute and implement the corresponding test tasks.
[0051] In this optional embodiment, the preset third language model is a model for step defect analysis, which can perform a detailed analysis of each test step in the test case to check whether there are potential defects or deficiencies. The third language model is also built based on deep learning technology, has a strong natural language understanding and analysis ability, can identify key information and operations in the test steps, and judge whether there are defects in the test steps according to the preset defect detection rules or patterns. For example, for the second test case A→B→C→D→J→E→F obtained above, the preset third language model can be concretized into multiple test steps, and analyzed through the test steps, operation instructions and expected results corresponding to the step tasks, and determine the corresponding expected results, such as the information obtained according to the second test case: 1. User login; Operation: Enter the username and password, click the login button; Function: login(username, password). 2. Browse the details of product P1; Operation: Search for product P1 on the homepage, click product P1 to enter the details page; Function: browse_product(product_id_p1). 3. Add product P1 to the shopping cart; Operation: On the product details page, click the "Add to Cart" button; Function: add_to_cart(product_id_p1); 4. View the shopping cart: Operation: Click the shopping cart icon at the top of the page to view the shopping cart contents; Function: view_cart(). 5. Use coupons; Operation: On the shopping cart page, enter the coupon code and click the "Use" button; Function: apply_coupon(coupon_code). 6. Submit the order; Operation: Click the "Submit Order" button to enter the order confirmation page; Function: submit_order(). 7. Pay the order; Operation: Select the payment method, confirm the payment, and complete the order payment; Function: pay_for_order(). The corresponding expected results are that the system successfully applies the coupon, the order amount is correctly deducted, the order is successfully submitted, and the payment is successful.
[0052] In this optional embodiment, when it is determined that the corresponding test step has defects, for example, in the above example, it is determined that since the "view shopping cart" in the above steps is an optional step in the actual test scenario, there is no direct association and program linkage for the use of coupons, so the third language model will judge that the step may be redundant, thereby generating an optimization instruction, and it is recommended to delete the step or adjust it to a conditional step. Based on the optimization instruction, the second test case A→B→C→D→J→E→F can be optimized to obtain the optimized test case A→B→C→J→E→F, that is, after the user logs in, directly browse the details of the product P1, add the product P1 to the shopping cart, and then use the coupon to submit and pay the order, thereby simplifying the test process and improving the test efficiency. Through such step analysis and optimization, it can be ensured that each step in the test case has a clear purpose and expected results, avoid redundant and invalid test steps, and further improve the quality and effectiveness of the test case. At the same time, this method can also flexibly adjust the steps and processes of the test case according to the actual test needs and scenarios to meet the requirements of different test stages and test objectives.
[0053] In this embodiment, the above-mentioned preset first language model, preset second language model and preset third language model can adopt the same type of large language model, such as a specific version of GPT, Claude and Gemini models, or different large language models. In the specific generation process, different prompt words can be used for training and fine-tuning according to the needs of different tasks, and chain calls can be made through tools such as LangChain to achieve the collaborative work of multiple large language models, thereby completing the generation, verification and optimization of test cases. In this way, the advantages of different large language models can be fully utilized to improve the generation efficiency and quality of test cases. At the same time, this method also has high flexibility and scalability, and can conveniently add or replace large language models according to actual test requirements and scenarios to meet the requirements of different test stages and test objectives. At the same time, with the continuous development and improvement of large language model technology, more test case generation and optimization methods based on large language models can be explored in the future to further improve the test effect and stability of the software system.
[0054] Optionally, in one embodiment, after adjusting the steps of the first test case based on the preset first large language model and similar step information to obtain the second test case, it also includes: associating the test script function corresponding to the second test case to generate an automated test script.
[0055] In this optional embodiment, the test script function refers to a function used to execute each test step in the test case, which generally includes a function name, parameters, and specific execution logic. After the second test case is generated, in order to apply it to the actual automated testing process, it is necessary to associate the corresponding test script function to execute these test cases through an automated testing tool or framework. For example, for the second test case A→B→C→D→J→E→F, the following test script functions can be associated with it: login(username, password) is used to log in to the mall system; browse_product(product_id_p1) is used to browse the details of product P1; add_to_cart(product_id_p1) is used to add product P1 to the shopping cart; view_cart() is used to view the shopping cart; apply_coupon(coupon_code) is used to use coupons; submit_order() is used to submit an order; pay_for_order() is used to pay an order. Thus, the corresponding automated test script can be obtained, through which the above test cases can be executed in the automated testing tool or framework to realize the automated testing of the software system.
[0056] In the present embodiment, the generation of the automated test script can greatly improve the test efficiency, reduce the time and cost of manually writing test scripts. At the same time, since the automated test script is generated based on the test case, the accuracy and effectiveness of the test script can be ensured, and the reliability and stability of the test can be improved. In addition, the automated test script can also be conveniently adjusted and optimized according to the actual test requirements and scenarios to meet the requirements of different test stages and test objectives. Through the above-mentioned test case generation method, a detailed test case document and an automated test script can be provided, and the test case document includes test steps, operating instructions and expected results, which can clearly show the test process and test objectives of each test case, and help testers understand and execute the test case. At the same time, the generation of the automated test script can make the test process more efficient and accurate, and reduce the possibility of manual intervention and errors.
[0057] In order to execute the corresponding steps in the above method embodiment and each possible implementation method, the following provides an implementation method of a test case generation device. Figure 7 , Figure 7 This is a functional module diagram of an embodiment of a test case generation device in an embodiment of the present invention. In this embodiment, the test case generation device includes: Extraction module 201, used to extract the test script function and description information of each test step in the first test case; Clustering model 202, clustering test steps based on test script functions and description information to obtain similar step information; The adjustment module 203 adjusts the steps of the first test case based on the preset first large language model and similar step information to obtain a second test case.
[0058] Optionally, in one embodiment, the extraction module 201 is further specifically used to: generate corresponding test nodes based on each test step, and the test nodes correspond to the test steps one by one; based on the order of the test steps, add directed edges between each test node to generate a test case graph structure.
[0059] Optionally, in one embodiment, after adding directed edges between test nodes based on the order of test steps to generate a test case graph structure, the method further includes: traversing the test case graph structure to obtain a second test case.
[0060] Optionally, in one embodiment, the clustering module 202 is specifically used to: when the test script functions are the same, classify the corresponding test steps into the same category to obtain first similar information; calculate the semantic similarity between the description information, classify the test steps with semantic similarity greater than a preset similarity threshold into the same category to obtain second similar information; merge the first similar information and the second similar information to obtain similar step information.
[0061] Optionally, in one embodiment, the adjustment module 203 is specifically used to: replace the test steps in the first test case with corresponding steps of the same type based on the same step information; and / or determine the insertable position and the corresponding insertion condition in the first test case based on the preset first large language model, and insert the test case that meets the insertion condition into the insertable position; and / or determine the deletable steps in the first test case based on the preset first large language model, and delete the corresponding test steps from the first test case; and / or determine the common step position of different first test cases based on the same step information, intercept the corresponding first test case at the common step position, and reorganize the intercepted different first test cases at the common step position.
[0062] Optionally, in one embodiment, the adjustment module 203 is specifically used to: verify the business logic of the second test case based on a preset second largest language model to determine a feasible test case; perform step analysis on the feasible test case based on a preset third largest language model, and generate optimization instructions when it is determined that the corresponding test steps have defects; and optimize the second test case based on the optimization instructions.
[0063] Optionally, in one embodiment, after adjusting the steps of the first test case based on the preset first large language model and similar step information to obtain the second test case, it also includes: associating the test script function corresponding to the second test case to generate an automated test script.
[0064] Since the embodiments of the device part correspond to the embodiments of the above-mentioned method, please refer to the above-mentioned method embodiments for the introduction of the test case generation device provided in the embodiments of the present invention. The embodiments of the present invention will not be repeated here, and it has the same beneficial effects as the above-mentioned test case generation method.
[0065] The present invention also provides a computer device, which includes a memory and a processor. The memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor executes the test case generation method as described above. Figure 8 3 is a functional module diagram of a computer device provided by an embodiment of the present invention. The computer device 300 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 310 (for example, one or more processors) and a memory 320, and one or more storage media 330 (for example, one or more mass storage devices) storing application programs 333 or data 332. Among them, the memory 320 and the storage medium 330 may be temporary storage or permanent storage. The program stored in the storage medium 330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the computer device 300. Furthermore, the processor 310 may be configured to communicate with the storage medium 330 to execute a series of instruction operations in the storage medium 330 on the computer device 300.
[0066] The computer device 300 may also include one or more power supplies 340, one or more wired or wireless network interfaces 350, one or more input and output interfaces 360, and / or one or more operating systems 331, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Figure 8 The illustrated computer device structure does not constitute a limitation on the computer device, and may include more or fewer components than illustrated, or combine certain components, or arrange the components differently.
[0067] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the test case generation method as described above.
[0068] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. If the integrated module or unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0069] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A test case generation method, characterized in that: include: Extracting the test script function and description information of each test step in the first test case; Clustering the test steps based on the test script function and the description information to obtain similar step information; Based on the preset first large language model and the similar step information, the first test case is adjusted in steps to obtain a second test case.
2. The test case generation method according to claim 1, characterized in that: The clustering of the test steps based on the test script function and the description information to obtain similar step information includes: When the test script functions are the same, the corresponding test steps are classified into the same category to obtain first same category information; Calculating the semantic similarity between each of the description information, classifying the test steps whose semantic similarity is greater than a preset similarity threshold into the same category, and obtaining second similar information; The first similar information and the second similar information are combined to obtain the similar step information.
3. The test case generation method according to claim 1, characterized in that: The step adjustment of the first test case based on the preset first large language model and the similar step information includes: Based on the similar step information, the test step in the first test case is replaced with a corresponding similar step; and / or Determine an insertable position and a corresponding insertion condition in the first test case based on the preset first large language model, and insert the test case satisfying the insertion condition into the insertable position; and / or Determine the deletable steps in the first test case based on the preset first large language model, and delete the corresponding test steps from the first test case; and / or Based on the same type of step information, the common step positions of different first test cases are determined, the corresponding first test cases are intercepted at the common step positions, and the intercepted different first test cases are reorganized at the common step positions.
4. The test case generation method according to claim 3, characterized in that: After extracting the test script function and description information of each test step in the first test case, the method further includes: Based on each of the test steps, a corresponding test node is generated, wherein the test node corresponds to the test step one by one; Based on the order of the test steps, directed edges are added between the test nodes to generate a test case graph structure.
5. The test case generation method according to claim 4, characterized in that: After adding directed edges between the test nodes based on the order of the test steps to generate a test case graph structure, the method further includes: The test case graph structure is traversed to obtain the second test case.
6. The test case generation method according to claim 1, characterized in that: After the first test case is adjusted based on the preset first large language model and the similar step information to obtain the second test case, the method further includes: Performing business logic verification on the second test case based on a preset second largest language model to determine a feasible test case; Performing step analysis on the feasible test case based on a preset third language model, and generating optimization instructions when it is determined that a defect exists in the corresponding test step; The second test case is optimized based on the optimization instruction.
7. The test case generation method according to any one of claims 1 to 6, characterized in that: After the first test case is adjusted based on the preset first large language model and the similar step information to obtain the second test case, the method further includes: Associate the test script function corresponding to the second test case to generate an automated test script.
8. A test case generating device, characterized in that: include: An extraction module, used to extract the test script function and description information of each test step in the first test case; A clustering model is used to cluster the test steps based on the test script function and the description information to obtain similar step information; The adjustment module adjusts the steps of the first test case based on the preset first large language model and the similar step information to obtain a second test case.
9. A computer device, characterized in that: The computer device comprises: a memory and at least one processor, wherein instructions are stored in the memory; The at least one processor calls the instructions in the memory to enable the computer device to execute the test case generating method according to any one of claims 1 to 7.
10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, the test case generation method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Clustering learning method, testing step clustering method and related device
CN112835798A
Test case generation method and device and electronic equipment
CN117632721A
Test case automatic generation method and device, electronic equipment and storage medium
CN118760613A
Unit test case generation system based on large language model
CN119105965A