Test case generation method and device, equipment and storage medium
By constructing a current knowledge graph from demand documents and historical knowledge graphs, the method aligns current demand points with historical test cases to generate more accurate test cases, addressing the inaccuracy in existing test case generation methods.
Patent Information
- Application Number
- CN202510396673.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-31
- Publication Date
- 2025-07-15
AI Technical Summary
The test cases generated in the prior art are not accurate enough to effectively utilize the key points in the historical test cases and requirements documents for accurate matching.
By constructing the current knowledge graph and historical knowledge graph, using language models for matching and comparison, a test case for the current demand point is generated, the test point is determined first and the accuracy is evaluated before the test case is generated.
Improve the accuracy of test cases, ensure the matching of test points and use cases at the demand point level, reduce the workload of repeated tests, and improve the testing efficiency.
Smart Images

Figure CN120316005A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of testing technologies, and in particular, to a test case generation method, apparatus, device, and storage medium. Background Art
[0002] Currently, in some technologies, in order to improve the generation efficiency of test cases, a test case knowledge graph is constructed based on historical test cases, and a knowledge graph to be processed is constructed based on key points in a requirements document. According to a target node in the knowledge graph to be processed, a path including the target node is retrieved in the test case knowledge graph as a similar use case path, and a test case for the requirements document is constructed based on the similar use case path and the knowledge graph to be processed. In these technologies, the generated test cases still have the problem of being inaccurate and need to be improved. Summary of the Invention
[0003] This application provides a test case generation method, a test case generation apparatus, an electronic device, a computer-readable storage medium, and a computer program product to at least solve the problem that test cases in related technologies are inaccurate.
[0004] This application provides a test case generation method, including:
[0005] Obtain a requirements document of a target product, and extract requirement information from the requirements document, where the requirement information represents at least one current requirement point included in the requirements document and the relationship between the current requirement points, and the current requirement point represents a function that the target product currently needs to implement;
[0006] Construct a current knowledge graph according to the relationship between the current requirement points;
[0007] Input the current knowledge graph and a historical knowledge graph into a first model to obtain test points for the current requirement points, where the historical knowledge graph represents at least the relationship between historical requirement points of the target product and historical test cases associated with each of the historical requirement points;
[0008] Input the test points, the current knowledge graph, and the historical knowledge graph into a second model to obtain test cases for the current requirement points.
[0009] This application also provides a test case generation apparatus, including:
[0010] An information extraction module, configured to obtain a requirements document of a target product, and extract requirement information from the requirements document, where the requirement information represents at least one current requirement point included in the requirements document and the relationship between the current requirement points, and the current requirement point represents a function that the target product currently needs to implement;
[0011] A knowledge graph construction module for constructing a current knowledge graph based on the relationships between current requirement points;
[0012] A test point generation module for inputting the current knowledge graph and a historical knowledge graph into a first model to obtain test points for the current requirement points, where the historical knowledge graph at least represents the relationships between historical requirement points of the target product and the historical test cases associated with each of the historical requirement points;
[0013] A test case generation module for inputting the test points, the current knowledge graph, and the historical knowledge graph into a second model to obtain test cases for the current requirement points.
[0014] This application also provides an electronic device, including: a memory for storing a computer program; a processor for implementing the steps of any of the above test case generation methods when executing the computer program.
[0015] This application also provides a computer-readable storage medium storing a computer program, where the computer program, when executed by a processor, implements the steps of any of the above test case generation methods.
[0016] Through this application, on the one hand, a current knowledge graph is constructed based on the relationships between current requirement points, and a historical knowledge graph is constructed based on the relationships between historical requirement points and the historical test cases associated with each historical requirement point. In this way, the current requirement points in the current knowledge graph can be matched and compared with the historical requirement points in the historical knowledge graph, and the historical test cases of the historical requirement points that match the current requirement points can be used as a reference to generate test cases for the current requirement points. Since the matching is at the requirement point level, the generated test cases can be relatively accurate. On the other hand, this application first obtains test points. In this way, testers can first evaluate the accuracy of the test points, and when the accuracy evaluation of the test points passes, generate test cases based on the test points, the current knowledge graph, and the historical knowledge graph, which can also achieve the purpose of improving the accuracy of the test cases. Description of the Drawings
[0017] To more clearly illustrate the embodiments of this application, the following will briefly introduce the drawings required for the embodiments. Obviously, the drawings in the following description are only some embodiments of this application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0018] Figure 1 It is a schematic diagram of the content architecture of a requirements document provided for some embodiments of this application;
[0019] Figure 2Flow diagram of the test case generation method provided for some embodiments of the present application;
[0020] Figure 3 Schematic diagram of the current knowledge graph provided for some embodiments of the present application;
[0021] Figure 4 Schematic diagram of the historical knowledge graph provided for some embodiments of the present application;
[0022] Figure 5 Module schematic diagram of the test case generation device provided for some embodiments of the present application;
[0023] Figure 6 Module schematic diagram of the electronic device provided for some embodiments of the present application. Detailed implementation manners
[0024] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present application.
[0025] It should be noted that in the description of the present application, the terms "include", "comprise" or any other variant thereof are intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects, rather than to describe a specific order or sequence.
[0026] Before elaborating on the solution of the present application, relevant concepts will be explained first.
[0027] The requirements document refers to a formal document used to describe the expected functions, performance, and design constraints of a product. Among them, the product includes but is not limited to software products, hardware products, etc. Referring to Figure 1 , the content architecture diagram of the requirements document provided for some embodiments of the present application. As Figure 1As shown, a requirements document may include one or more requirement points. Requirement points are used to characterize the functions that the product needs to implement. For example, Web login authentication can be used as the first requirement point, Portal login authentication can be used as the second requirement point, and supporting the update of the home page avatar can be used as the third requirement point. One or more requirement points can be divided into a functional module. For example, Web login authentication and Portal login authentication can be divided under the functional module "Login Authentication", and the user's update of the home page avatar can be divided under the functional module "User Interface Operations".
[0028] Each requirement point can separately have requirement point attributes. Requirement point attributes include but are not limited to requirement numbers (such as Figure 1 "0111", "0112" in
[0029] ), the functional module to which the requirement belongs, requirement priority, functional description, design constraints, acceptance criteria, etc. Among them, the requirement priority refers to the importance level of the requirement point. For example, the more important the requirement point, the higher its requirement priority can be. The functional description can include but is not limited to the input conditions, processing flow, and expected output of the function characterized by the requirement point. Design constraints refer to the constraints that need to be followed during the development or use of the function characterized by the requirement point. For example, the input value of parameter A cannot be greater than 1000. The acceptance criteria refer to the expected results of the function characterized by the requirement point. Figure 1 There can be a dependency relationship between requirement points. This dependency relationship refers to the execution sequence order between the functions characterized by different requirement points. For example,
[0030] in
[0031]
[0032] before the user updates the home page avatar, it is necessary to first log in to the user's personal home page through Web login authentication or client login authentication. Therefore, the requirement point "User updates home page avatar" depends on the requirement points "Web login authentication" and "Web login authentication". There can also be an inclusion relationship between requirement points. For example, the requirement point "Web login authentication" can include sub-requirement points a and b. Among them, sub-requirement point a is "Use the number of operator a for Web login authentication", and sub-requirement point b is "Use the number of operator b for Web login authentication".
[0031] Usually, based on the requirement numbers, requirement priorities, etc. of each requirement point in the requirements document, requirement point management can be carried out, such as managing the development sequence of requirement points, allocating developers for each requirement point, etc. Developers can carry out the functional development of requirement points based on the functional description, design constraints, etc. in the requirements document. Testers can design test cases based on the functional description, design constraints, acceptance criteria, etc. in the requirements document.
[0032] A test case refers to a verification plan used to verify whether a function meets the acceptance criteria (i.e., the expected result) after developers have completed the development of the function represented by a requirement point. A test case can include, but is not limited to, a test case description, preconditions, test steps, expected results, etc. Each requirement point can correspond to one or more test cases. For multiple test cases corresponding to the same requirement point, different test cases can be used to verify the function represented by the requirement point from different perspectives. For example, when verifying "Web login authentication", test cases c1 and c2 can be designed.
[0033] In test case c1, the precondition is that the mobile phone number number1 registered on the product registration page has been obtained; the test steps are: open the Web login page > enter number1 on the Web login page > click the "Login" button on the Web login page; the expected result is: successful login.
[0034] In test case c2, the precondition is that the unregistered mobile phone number number2 on the product registration page has been obtained; the test steps are: open the Web login page > enter number2 on the Web login page > click the "Login" button on the Web login page; the expected result is: login failure, and a prompt indicating that the mobile phone number has not been registered appears.
[0035] If the actual result obtained after the user operates according to the preconditions and test steps of the test case is consistent with the expected result in the test case, it indicates that the test case has passed.
[0036] There can also be a dependency relationship between test cases. This dependency relationship represents the execution sequence between test cases. For example, assume that test case c3 is designed for the requirement point "User updates the homepage avatar". In test case c3, the precondition is that the mobile phone number number1 registered on the product registration page has been obtained; the test steps are: on the page after successful Web login, click the "My Homepage" button to jump to the user's personal homepage > on the personal homepage, click the user avatar to jump to the user avatar update page > update the user avatar on the update page > click the "OK" button to complete the user avatar update; the expected result is: the user successfully updates the avatar. Since the execution of test case c3 needs to be carried out after the execution of test case c1 is completed, it can be considered that test case c3 depends on test case c1.
[0037] Currently, in some technologies, in order to improve the generation efficiency of test cases, a test case knowledge graph is constructed based on historical test cases, and a knowledge graph to be processed is constructed based on key points in the requirements document. According to the target nodes in the knowledge graph to be processed, a path including the target nodes is retrieved in the test case knowledge graph as a similar use case path, and test cases for the requirements document are constructed based on the similar use case path and the knowledge graph to be processed. For example, assume that the test case includes test step a: the user clicks the button "My Homepage" and is redirected to the user's personal homepage > the user's personal homepage updates the user's birthday information. At the same time, the requirements document includes key points: "user", "login", "My Homepage", "replace", "user avatar". Then, "user", "My Homepage", and "birthday information" can be used as nodes in the test case knowledge graph, and "click" and "update" can be used as edges in the test case knowledge graph to construct the test case knowledge graph. At the same time, "user", "My Homepage", and "user avatar" are used as nodes in the knowledge graph to be processed, and "login" and "replace" are used as edges in the knowledge graph to be processed to construct the knowledge graph to be processed. Furthermore, the nodes "user", "My Homepage", and "user avatar" in the knowledge graph to be processed are used as target nodes, and a path including any of the target nodes is searched for in the test case knowledge graph as a similar use case path, and test cases for the requirements document are obtained based on these similar use case paths and the knowledge graph to be processed. In these technologies, the paths including any of the target nodes are all used as similar use case paths, which has the problem of being inaccurate. For example, in the above test case knowledge graph, the path including "My Homepage" is for updating the birthday information, but in the knowledge graph to be processed, the path including "My Homepage" is for updating the user avatar. Therefore, it is inaccurate to use the path including "My Homepage" in the test case knowledge graph as a similar use case path, and the test cases generated based on these technologies are not accurate enough.
[0038] In view of this, the present application provides a test case generation method, which can improve the accuracy of test cases. The test case generation method can be applied to a test case generation system or an electronic device running the test case generation system. The electronic device includes but is not limited to a tablet computer, a notebook computer, a desktop computer, etc. Referring to Figure 2 , it is a schematic flowchart of the test case generation method provided by some embodiments of the present application. Figure 2 In
[0039] Step S201, obtain the requirements document of the target product, and extract requirement information from the requirements document. The requirement information represents at least one current requirement point included in the requirements document and the relationship between the current requirement points. The current requirement point represents the function that the target product needs to implement currently.
[0040] Specifically, the target product can be the target software product or target hardware product to be tested. Regarding the requirements document, reference can be made to the relevant description above, which will not be elaborated here.
[0041] The current requirement points refer to the requirement points that have not been verified yet. The relationships between the current requirement points can include inclusion relationships and dependency relationships. For example, Figure 1 Based on the hierarchical structure among the current requirement points in the requirements document as described above, the inclusion relationships between the current requirement points can be determined. Additionally, based on the preconditions, function descriptions, etc. of each current requirement point, the dependency relationships between the current requirement points can be determined.
[0042] In this embodiment, an extraction model can be integrated in the test case generation system. The requirement information can be extracted through the extraction model. The extraction model can be a language model. With an appropriate first prompt as a cue, the extraction model can understand the content in the requirements document and output the requirement information. For example, the first prompt can be designed as "Please extract the requirement points, the inclusion relationships and dependency relationships between the requirement points in this document, where the requirement points represent product functions, the inclusion relationship refers to the relationship of the scope size between the product functions represented by the requirement points, and the dependency relationship refers to the execution sequence between the product functions represented by the requirement points." Inputting the first prompt and the requirements document into the extraction model, the extraction model can output the requirement information.
[0043] When extracting the requirement information, the function module to which each current requirement point belongs, as well as the requirement number, requirement priority, function description, design constraint, acceptance criterion, etc. of each current requirement point can also be extracted. Among them, the requirement number, requirement priority, function description, design constraint, acceptance criterion, etc. of the current requirement point can be used as the requirement point attributes of the current requirement point.
[0044] The requirement information output by the extraction model can be a complete descriptive statement. For example, the requirement information output by the extraction model can be: "The requirements document includes requirement points 'Web login authentication', 'client login authentication' and 'user updates the homepage avatar'. Among them, there is a dependency relationship between the requirement points 'Web login authentication' and 'user updates the homepage avatar'. The requirement point 'Web login authentication' belongs to the function module 'login authentication', and the requirement point attributes of 'Web login authentication' are: requirement number 011, requirement priority is high, function description is to authenticate the login initiated from the Web page..."
[0045] In this embodiment, the current requirement points, the function modules to which the current requirement points belong, the requirement point attributes of the current requirement points, and the relationships between the current requirement points can be extracted from the requirement information, and the extracted information can be stored in a structured storage manner. The so-called structured storage manner means organizing and storing the information extracted from the requirement information in a specified format in a database. For example, the information extracted from the requirement information can be stored in the structured storage manner shown in Table 1:
[0046] Table 1 Structured storage manner
[0047]
[0048] In Table 1, the ellipsis is for simplified description and does not constitute a limitation to this application. Based on this structured storage manner, the current requirement points, the function modules to which the current requirement points belong, the requirement point attributes of the current requirement points, and the relationships between the current requirement points extracted from the requirement document can be intuitively viewed.
[0049] Step S202: Construct the current knowledge graph according to the relationships between the current requirement points.
[0050] Based on the information stored in a structured manner in step S201, the current knowledge graph can be constructed. Specifically, the nodes in the current knowledge graph can include current module nodes representing the function modules to which the current requirement points belong, and current requirement nodes representing the current requirement points. The edges in the current knowledge graph can represent the relationships between the current requirement points and the required function modules, as well as the relationships between the current requirement points. The requirement point attributes of the current requirement points can be used as the node attributes of the current requirement nodes. For ease of understanding, refer to Figure 3 for a schematic diagram of the current knowledge graph provided in some embodiments of this application. Figure 3 In, the current requirement points "Web login authentication", "client login authentication", and "user update home page avatar" are current requirement nodes, and "login authentication" and "user interface operation" are current function nodes. The connections between the nodes represent the relationships between the nodes. Each current requirement node can have node attributes, that is, the requirement point attributes of the current requirement points.
[0051] Step S203: Input the current knowledge graph and the historical knowledge graph into the first model to obtain the test points of the current requirement points. The historical knowledge graph at least represents the relationships between the historical requirement points of the target product, as well as the historical test cases associated with each historical requirement point.
[0052] Specifically, the first model can be integrated into the test case generation system. Historical requirement points refer to the requirement points that have been verified. The historical test cases associated with the historical requirement points refer to the test cases used when verifying the historical requirement points. Based on the function modules to which the historical requirement points belong, the historical test cases associated with the historical requirement points, and the relationships between the historical requirement points, a historical knowledge graph can be constructed. For ease of understanding, refer to Figure 4 for the schematic diagram of the historical knowledge graph provided by some embodiments of this application. As Figure 4 shown, the historical knowledge graph may include historical requirement nodes representing historical requirement points, historical function nodes representing the function modules to which the historical requirement points belong, and historical use case nodes representing historical test cases. The node attributes of the historical requirement nodes are the requirement point attributes of the historical requirement points, and the node attributes of the historical use case nodes are the preconditions, test steps, expected results, etc. of the historical test cases.
[0053] In this embodiment, the first model can be a language model. Inputting the current knowledge graph, the historical knowledge graph, and an appropriate third prompt into the first model, the first model can search for historical requirement points in the historical requirement points of the historical knowledge graph whose similarity to the current requirement point exceeds the similarity threshold according to the current requirement point in the current knowledge graph, and use the test cases of the corresponding historical requirement points as references to output the test points of the current requirement point.
[0054] Test points refer to one or more sub - functions that need to be verified when verifying the function represented by the current requirement point. For example, the test points for the current requirement point "Web login authentication" may specifically include test point A and test point B. Among them, test point A is "enter the successfully registered mobile phone number number1 on the Web login page for login", and test point B is "enter the un - successfully registered mobile phone number number2 on the Web login page for login". For each test point, test cases can be designed respectively, that is, the test points can be in one - to - one correspondence with the test cases.
[0055] Generally, each current requirement point can have multiple different test points. In this way, the function represented by the current requirement point can be verified from multiple different perspectives, thus ensuring the reliability of the function verification. After obtaining the test points, the tester can perform manual checks on the test points, such as checking whether the test points are reasonable, or whether the test points can comprehensively verify the current requirement point, and whether there is redundancy in the test points. If the check passes, step S204 can be continued. If the check fails, the tester can regenerate the test points through the first model or manually modify the test points.
[0056] Step S204: Input the test points, the current knowledge graph, and the historical knowledge graph into the second model to obtain the test cases for the current requirement point.
[0057] Specifically, the second model can be integrated into the test case generation system. The second model can also be a language model. By inputting the test points, the current knowledge graph, the historical knowledge graph, and a suitable fourth prompt into the second model, the first model can, according to the current requirement points in the current knowledge graph, search for historical requirement points in the historical requirement points of the historical knowledge graph whose similarity to the current requirement points exceeds the similarity threshold, and use the test cases of the corresponding historical requirement points as references to output the test cases for each test point.
[0058] In this embodiment, the above extraction model, first model, and second model are the same language model. By having multiple rounds of conversations with the language model, the test cases for the current requirement points can be obtained. Specifically, in the first round of conversation, the requirement document is input into the language model to obtain requirement information; in the second round of conversation, the current knowledge graph and the historical knowledge graph are input into the language model to obtain test points; in the third round of conversation, the test points, the current knowledge graph, and the historical knowledge graph are input into the language model to obtain test cases.
[0059] In some other embodiments, the above extraction model, first model, and second model can be different models. This application does not limit this.
[0060] In summary, in the technical solutions of some embodiments of this application, on the one hand, a current knowledge graph is constructed based on the relationships between current requirement points, and a historical knowledge graph is constructed based on the relationships between historical requirement points and the historical test cases associated with each historical requirement point. In this way, the current requirement points in the current knowledge graph can be matched and compared with the historical requirement points in the historical knowledge graph, and the historical test cases of the historical requirement points that match the current requirement points can be used as references to generate the test cases for the current requirement points. Since the matching is at the requirement point level, the generated test cases can be relatively accurate. On the other hand, this application first obtains the test points. In this way, the testers can first evaluate the accuracy of the test points, and when the accuracy evaluation of the test points passes, then generate the test cases based on the test points, the current knowledge graph, and the historical knowledge graph, which can also achieve the purpose of improving the accuracy of the test cases.
[0061] The technical solutions of this application are further elaborated below.
[0062] In some embodiments, considering that the current knowledge graph includes the requirement point attributes of each current requirement point, and the historical knowledge graph includes the requirement point attributes of each historical requirement point, the first model can generate test points based on the following method:
[0063] Compare the requirement point attributes of the current requirement point in the current knowledge graph with the requirement point attributes of each historical requirement point in the historical knowledge graph to obtain the first historical requirement point that matches the current requirement point in the historical knowledge graph;
[0064] Generate test points with reference to the historical test cases associated with the first historical requirement point.
[0065] Specifically, for any current requirement point, the requirement point attributes of the current requirement point can be compared with the requirement point attributes of each historical requirement point for similarity. If there is a historical requirement point whose similarity to the current requirement point exceeds the similarity threshold, the corresponding historical requirement point can be used as the first historical requirement point. The first historical requirement point selected based on this method can be a requirement point that is the same as or similar to the current requirement point. Since the current requirement point and the first historical requirement point are the same or similar, the test cases for the current requirement point and the first historical requirement point should also be similar. Generating test points for the current requirement point with reference to the historical test cases associated with the first historical requirement point is relatively accurate.
[0066] By comparing the requirement point attributes of the current requirement point with the requirement point attributes of each historical requirement point, the similarity between the current requirement point and the historical requirement points can be evaluated from multiple dimensions such as function description and acceptance criteria, thereby improving the screening accuracy of the first historical requirement point.
[0067] In some embodiments, if the first model fails to find the first historical requirement point in the historical knowledge graph, it means that there is no historical requirement point in the historical knowledge graph that matches the current requirement point. In this case, the first model can also generate test points based on the following method:
[0068] Based on the historical test cases in the historical knowledge graph, determine the target technical field related to the historical test cases, and search for the first requirement point that matches the current requirement point among the requirement points in the target technical field;
[0069] Generate test points with reference to the historical test cases associated with the first requirement point.
[0070] Specifically, the target technical field is the technical field of the target product, such as the communication field or the artificial intelligence field, etc. The requirement points in the target technical field can be the knowledge learned by the first model during the training process.
[0071] Using historical test cases associated with the first requirement point in the target technical field as a reference can ensure that the generated test points belong to the target technical field, thereby avoiding the situation where the test points generated by the first model do not match the technical field of the target product when the reference information is insufficient. That is, when there is no historical requirement point matching the current requirement point in the historical knowledge graph, the generation accuracy of the test points can be ensured as much as possible.
[0072] In some embodiments, each test point is used to achieve its corresponding test objective. The test objective refers to one or more expected objectives to be achieved when testing the function represented by the current requirement point. For example, the test objective A is: when entering a successfully registered mobile phone number on the Web login page, if the password or verification code is correct, the authentication passes; the test objective B is: when entering an unregistered mobile phone number on the Web login page, the authentication fails. Normally, a corresponding test point can be generated for each test objective respectively. If multiple test points are generated for the same test objective, there will be a problem of duplicate testing. For example, for the above test objective A, if the test point A1 "log in by entering the successfully registered mobile phone number number1 on the Web login page" and the test point A2 "log in by entering the successfully registered mobile phone number number2 on the Web login page" are generated. Since the functional logics corresponding to the test point A2 and the test point A3 are the same, therefore, when the test for the test point A1 passes, the test for the test point A2 will also necessarily pass, and when the test for the test point A1 fails, the test for the test point A2 will also necessarily fail. By testing one of the test points A1 and A2, the test objective can be achieved. If the test points A1 and A2 are tested simultaneously, it will cause the problem of duplicate testing and increase the test workload.
[0073] In view of this, inputting the test points, the current knowledge graph, and the historical knowledge graph into the second model in step 204 above may include:
[0074] For the first test point and the second test point in the test points, if the test objectives achieved by the first test point and the second test point are the same, then one of the first test point and the second test point is removed;
[0075] Input the unremoved test points, the current knowledge graph, and the historical knowledge graph into the second model.
[0076] In this way, it is possible to avoid the first model generating multiple test points for the same test objective, thereby causing the problem of increased test workload.
[0077] In some embodiments, the second model can generate test cases based on the following method:
[0078] Compare the requirement point attributes of the current requirement point in the current knowledge graph with the requirement point attributes of each historical requirement point in the historical knowledge graph to obtain the second historical requirement point that matches the current requirement point in the historical knowledge graph;
[0079] In the historical test cases associated with the second historical requirement point, search for the first historical test case that matches the test point;
[0080] Generate test cases with reference to the first historical test case.
[0081] Specifically, theoretically, the first historical requirement point and the second historical requirement point should be the same. However, considering that the inference logics of different models are different, or the inference logics of the same model in different inference processes are not completely the same, the first historical requirement point and the second historical requirement point can be the same or not completely the same.
[0082] The principle of screening the second historical requirement point and the first historical test case is similar to the principle of screening the first historical requirement point, and the principle of generating test cases is similar to the principle of generating test points, which will not be elaborated here.
[0083] By screening the second historical requirement point that matches the current requirement point in the historical knowledge graph, and using the first historical test case that matches the test point as a reference in the historical test cases associated with the second historical requirement point to generate test cases, the generation accuracy of the test cases can be guaranteed.
[0084] In some embodiments, for any current requirement point in the current knowledge graph, the first model or the second model can also find the historical requirement point that matches the current requirement point based on the following method;
[0085] According to the target function module to which the current requirement point in the current knowledge graph belongs, search for the target historical requirement point under the target function module in the historical knowledge graph;
[0086] Compare the requirement point attributes of the current requirement point with the requirement point attributes of each target historical requirement point to obtain the historical requirement point that matches the current requirement point in the historical knowledge graph.
[0087] It can be understood that the historical requirement point that matches the current requirement point should belong to the same function module. Therefore, by only comparing the requirement point attributes of the current requirement point with the requirement point attributes of each target historical requirement point, the search workload can be greatly reduced.
[0088] In some embodiments, if the second model fails to find the second historical requirement point or the first historical test case in the historical knowledge graph, the second model can also generate test cases based on the following method:
[0089] Determine the target technical field related to the historical test cases in the historical knowledge graph, and search for the second requirement point that matches the current requirement point among the requirement points of the target technical field;
[0090] In the historical test cases associated with the second requirement point, search for the second historical test case that matches the test point;
[0091] Generate test cases with reference to the second historical test case.
[0092] In this way, when there is no historical requirement point that matches the current requirement point in the historical knowledge graph, the generation accuracy of the test cases can be ensured as much as possible.
[0093] In some embodiments, after obtaining the test cases for the current requirement point, the test cases can be sorted to obtain the execution priorities of the respective test cases. Among them, for the first test case and the second test case in the test cases, if the execution of the second test case depends on the execution result of the first test case, the execution priority of the first test case is higher than that of the second test case. In this way, it is ensured that the test cases are executed in sequence according to the dependency relationship, avoiding the problem that the second test case fails to execute due to the execution of the second test case before the first test case is completed.
[0094] In some embodiments, the generated test cases may be redundant. After obtaining the test cases for the current requirement point, the test cases can also be input into the language model, and the language model eliminates the redundant test cases and outputs the test cases without redundancy. In this way, the test workload can be reduced.
[0095] In some embodiments, after obtaining the test cases for the current requirement point, the current requirement point and the association relationship between the current requirement and the test cases can be added to the historical knowledge graph. In this way, in the process of generating test cases for subsequent requirement points, the test cases for the current requirement point can be used as a reference.
[0096] From the description of the above implementation manners, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation manner.
[0097] With reference to Figure 5 , the block diagram of the test case generation device provided in some embodiments of the present application.
[0098] An information extraction module 501, configured to obtain a requirements document of a target product and extract requirements information from the requirements document, where the requirements information represents at least one current requirement point included in the requirements document and the relationships between the current requirement points, and the current requirement point represents a function that the target product currently needs to implement.
[0099] A knowledge graph construction module 502, configured to construct a current knowledge graph according to the relationships between the current requirement points.
[0100] A test point generation module 503, configured to input the current knowledge graph and a historical knowledge graph into a first model to obtain test points for the current requirement points, where the historical knowledge graph represents at least the relationships between the historical requirement points of the target product and the historical test cases associated with each historical requirement point.
[0101] A test case generation module 504, configured to input the test points, the current knowledge graph, and the historical knowledge graph into a second model to obtain test cases for the current requirement points.
[0102] In some embodiments, the current knowledge graph includes the requirement point attributes of each current requirement point, and the historical knowledge graph includes the requirement point attributes of each historical requirement point; the first model generates test points based on the following method:
[0103] Compare the requirement point attributes of the current requirement points in the current knowledge graph with the requirement point attributes of each historical requirement point in the historical knowledge graph to obtain first historical requirement points in the historical knowledge graph that match the current requirement points;
[0104] Generate test points with reference to the historical test cases associated with the first historical requirement points.
[0105] In some embodiments, if the first model does not find a first historical requirement point in the historical knowledge graph, the first model also generates test points based on the following method:
[0106] Determine a target technical field related to the historical test cases according to the historical test cases in the historical knowledge graph, and search for a first requirement point that matches the current requirement point among the requirement points in the target technical field;
[0107] Generate test points with reference to the historical test cases associated with the first requirement point.
[0108] In some embodiments, the current knowledge graph includes the requirement point attributes of each current requirement point, and the historical knowledge graph includes the requirement point attributes of each historical requirement point; the second model generates test cases based on the following method:
[0109] Compare the requirement point attributes of the current requirement point in the current knowledge graph with the requirement point attributes of each historical requirement point in the historical knowledge graph to obtain a second historical requirement point that matches the current requirement point in the historical knowledge graph;
[0110] In the historical test cases associated with the second historical requirement point, search for a first historical test case that matches the test point;
[0111] Generate test cases with reference to the first historical test case.
[0112] In some embodiments, if the second model fails to find a second historical requirement point or a first historical test case in the historical knowledge graph, the second model also generates test cases based on the following method:
[0113] Based on the historical test cases in the historical knowledge graph, determine the target technical field related to the historical test cases, and search for a second requirement point that matches the current requirement point among the requirement points in the target technical field;
[0114] In the historical test cases associated with the second requirement point, search for a second historical test case that matches the test point;
[0115] Generate test cases with reference to the second historical test case.
[0116] In some embodiments, each test point is used to achieve its respective corresponding test objective; the test case generation module 504 is specifically configured to:
[0117] For the first test point and the second test point in the test points, if the test objectives achieved by the first test point and the second test point are the same, then eliminate one of the first test point and the second test point;
[0118] Input the uneliminated test points, the current knowledge graph, and the historical knowledge graph into the second model.
[0119] In some embodiments, after obtaining the test cases for the current requirement point, the test case generation module 504 is further configured to:
[0120] Sort the test cases to obtain the execution priorities of each test case. Among them, for the first test case and the second test case in the test cases, if the execution of the second test case depends on the execution result of the first test case, then the execution priority of the first test case is higher than that of the second test case; and / or
[0121] Add the current requirement point and the association relationship between the current requirement and the test cases to the historical knowledge graph.
[0122] For the description of the features in the embodiments corresponding to the test case generation device, reference can be made to the relevant descriptions in the embodiments corresponding to the sample data processing method, which will not be elaborated here one by one.
[0123] With reference to Figure 6 , an embodiment of the present application further provides an electronic device, including a memory 10 and a processor 20. A computer program is stored in the memory 10, and the processor 20 is configured to run the computer program to execute the steps in any of the above-mentioned embodiments of the test case generation method.
[0124] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any of the above-mentioned embodiments of the test case generation method when running.
[0125] In an exemplary embodiment, the above-mentioned computer-readable storage medium may include, but is not limited to: USB flash drive, read-only memory (ROM for short), random access memory (RAM for short), mobile hard disk, magnetic disk, or optical disc, etc., various media that can store computer programs.
[0126] An embodiment of the present application further provides a computer program product. The above-mentioned computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above-mentioned embodiments of the test case generation method.
[0127] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above-mentioned embodiments of the test case generation method.
[0128] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. For the sake of clarity of the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0129] The above has introduced in detail a test case generation method, apparatus, device, and storage medium provided by the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.
Claims
1. A test case generation method, characterized in that, The method includes: Obtaining a requirements document of a target product, and extracting requirements information from the requirements document, where the requirements information represents at least one current requirement point included in the requirements document and the relationships between the current requirement points, and the current requirement point represents a function that the target product currently needs to implement; Constructing a current knowledge graph based on the relationships between the current requirement points; Inputting the current knowledge graph and a historical knowledge graph into a first model to obtain test points for the current requirement points, where the historical knowledge graph represents at least the relationships between the historical requirement points of the target product and the historical test cases associated with each of the historical requirement points; Inputting the test points, the current knowledge graph, and the historical knowledge graph into a second model to obtain test cases for the current requirement points.
2. The method according to claim 1, wherein The current knowledge graph includes the requirement point attributes of each of the current requirement points, and the historical knowledge graph includes the requirement point attributes of each of the historical requirement points; the first model generates the test points based on the following method: Comparing the requirement point attributes of the current requirement points in the current knowledge graph with the requirement point attributes of each of the historical requirement points in the historical knowledge graph to obtain a first historical requirement point in the historical knowledge graph that matches the current requirement point; Generating the test points with reference to the historical test cases associated with the first historical requirement point.
3. The method according to claim 2, wherein If the first model does not find the first historical requirement point in the historical knowledge graph, the first model also generates the test points based on the following method: Determining a target technical field related to the historical test cases according to the historical test cases in the historical knowledge graph, and searching for a first requirement point that matches the current requirement point among the requirement points in the target technical field; Generating the test points with reference to the historical test cases associated with the first requirement point.
4. The method according to claim 1, characterized in that, The current knowledge graph includes the requirement point attributes of each of the current requirement points, and the historical knowledge graph includes the requirement point attributes of each of the historical requirement points; the second model generates the test cases based on the following method: Comparing the requirement point attributes of the current requirement points in the current knowledge graph with the requirement point attributes of each of the historical requirement points in the historical knowledge graph to obtain a second historical requirement point in the historical knowledge graph that matches the current requirement point; Searching for a first historical test case that matches the test points among the historical test cases associated with the second historical requirement point; Generating the test cases with reference to the first historical test case.
5. The method according to claim 4, wherein If the second model does not find the second historical requirement point or the first historical test case in the historical knowledge graph, the second model also generates the test cases based on the following method: Determining a target technical field related to the historical test cases according to the historical test cases in the historical knowledge graph, and searching for a second requirement point that matches the current requirement point among the requirement points in the target technical field; In the historical test cases associated with the second requirement point, search for the second historical test case that matches the test point; Generate the test case with the second historical test case as a reference.
6. The method according to any one of claims 1 to 5, characterized in that, Each of the test points is used to achieve its corresponding test objective; the inputting of the test point, the current knowledge graph, and the historical knowledge graph into the second model includes: For the first test point and the second test point among the test points, if the test objectives achieved by the first test point and the second test point are the same, then eliminate one of the first test point and the second test point; Input the uneliminated test points, the current knowledge graph, and the historical knowledge graph into the second model.
7. The method according to any one of claims 1 to 5, characterized in that, After obtaining the test case for the current requirement point, the method further includes: Sort the test cases to obtain the execution priorities of the respective test cases. Among them, for the first test case and the second test case in the test cases, if the execution of the second test case depends on the execution result of the first test case, then the execution priority of the first test case is higher than that of the second test case; and / or Add the association relationship between the current requirement point, the current requirement, and the test case to the historical knowledge graph.
8. A test case generation device, characterized in that, The device includes: An information extraction module, configured to obtain a requirement document of a target product and extract requirement information from the requirement document. The requirement information represents at least one current requirement point included in the requirement document and the relationship between the current requirement points, and the current requirement point represents the function that the target product currently needs to implement; A knowledge graph construction module, configured to construct a current knowledge graph according to the relationship between the current requirement points; A test point generation module, configured to input the current knowledge graph and the historical knowledge graph into a first model to obtain the test points of the current requirement point. The historical knowledge graph represents at least the relationship between the historical requirement points of the target product and the historical test cases associated with each of the historical requirement points; A test case generation module, configured to input the test points, the current knowledge graph, and the historical knowledge graph into a second model to obtain the test cases of the current requirement point.
9. An electronic device, characterized in that, Includes: A memory, configured to store a computer program; A processor, configured to implement the steps of the test case generation method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, where the computer program, when executed by a processor, implements the steps of the test case generation method according to any one of claims 1 to 7.