Test case generation method and related product

By analyzing the paths and event identifiers in the state machine diagram to generate test cases, the problem of incomplete and inaccurate test cases caused by complex state machine diagrams is solved, achieving more comprehensive test coverage and improving the effectiveness of test cases.

CN120994532APending Publication Date: 2025-11-21TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410605722.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-15
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

The test cases generated by existing state machine diagrams have become increasingly complex, resulting in incomplete or inaccurate coverage and affecting the effectiveness of the test cases.

Method used

By acquiring the state machine diagram, analyzing its paths, and generating test cases, we ensure that each path and associated event is tested at least once. We use the state machine adjacency matrix and path search algorithm to determine all paths and generate test cases in combination with event identifiers.

Benefits of technology

This improved the completeness and accuracy of test cases, broadened the coverage, ensured that each path and each event was tested at least once, and enhanced the effectiveness of test cases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994532A_ABST
    Figure CN120994532A_ABST
Patent Text Reader

Abstract

The invention discloses a test case generation method and a related product. The generation method comprises the steps that a state machine diagram is obtained, the state machine diagram comprises a plurality of states and a plurality of events used for triggering the states to be converted, the events comprise respective identifiers, and the events with the incidence relation comprise the same identifier; the state machine diagram is analyzed to obtain multiple paths, each path in the multiple paths comprises a starting state, an intermediate state, an ending state and an event used for triggering the starting state, the intermediate state and the ending state to be converted, the multiple states comprise the state included in each path, and the multiple events comprise the event included in each path; and generating a test case based on each path and the identifier of the event included in each path. Therefore, the coverage degree of the test case is greatly expanded, so that the integrity and the accuracy of the test case are improved, and the effectiveness of the test case can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a test case generation method and related products. BACKGROUND

[0002] A state machine diagram is used to display a state machine to describe the process of transition and behavior change between different states of things. In actual application, a business system can be designed based on a state machine diagram to generate test cases of the business system. However, with the rapid development of business, the evolution of the state machine diagram becomes more and more complex.

[0003] For example, the transition between two states can be triggered by multiple events, or there can be a correlation relationship between the multiple events triggering the state transition, and the multiple events cannot be combined at will. Therefore, the test cases generated based on such a complex state machine diagram can not be complete and accurate, which can affect the effectiveness of the test cases. SUMMARY

[0004] Embodiments of the present application provide a test case generation method and related products to improve the completeness and accuracy of the test cases, thereby improving the effectiveness of the test cases.

[0005] Embodiments of the present application disclose the following technical solutions:

[0006] In a first aspect, the embodiments of the present application provide a test case generation method, comprising:

[0007] obtaining a state machine diagram, the state machine diagram comprising a plurality of states and a plurality of events for triggering the plurality of states to transition, the plurality of events comprising respective identifiers, events having a correlation relationship comprising the same identifier;

[0008] analyzing the state machine diagram to obtain a plurality of paths, each path in the plurality of paths comprising a start state, an intermediate state, an end state, and events for triggering the start state, the intermediate state, and the end state to transition, the plurality of states comprising states included in each path, and the plurality of events comprising events included in each path;

[0009] generating test cases based on the each path and identifiers of the events included in the each path.

[0010] In a second aspect, the embodiments of the present application provide a test case generation apparatus, comprising:

[0011] a state machine diagram obtaining module configured to obtain a state machine diagram, the state machine diagram comprising a plurality of states and a plurality of events for triggering the plurality of states to transition, the plurality of events comprising respective identifiers, events having a correlation relationship comprising the same identifier;

[0012] a state machine graph analysis module configured to analyze the state machine graph to obtain a plurality of paths, each of the plurality of paths including a start state, an intermediate state, an end state, and events for triggering the start state, the intermediate state, and the end state to transition, the plurality of states including states included in each of the plurality of paths, and the plurality of events including events included in each of the plurality of paths;

[0013] a test case generation module configured to generate a test case based on the each of the plurality of paths and the events included in the each of the plurality of paths.

[0014] In a third aspect, an embodiment of the present application provides an electronic device, the device comprising a processor and a memory:

[0015] the memory is configured to store a computer program and transmit the computer program to the processor;

[0016] the processor is configured to execute steps of the test case generation method according to instructions in the computer program.

[0017] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, the computer readable storage medium being configured to store program code, the program code being configured to execute steps of the test case generation method according to the first aspect.

[0018] In a fifth aspect, an embodiment of the present application provides a computer program product, comprising a computer program or instructions, which, when executed by a processor, implement steps of the test case generation method according to the first aspect.

[0019] From the above technical solutions, it can be seen that the embodiments of the present application have the following advantages:

[0020] In the embodiments of this application, a state machine graph can be acquired first, the state machine graph including a plurality of states and a plurality of events for triggering the plurality of states to be converted, events having an association relationship in the plurality of events including an association identifier. Then, the state machine graph can be analyzed to obtain a plurality of paths, each path in the plurality of paths including a start state, an intermediate state, an end state, and events for triggering the start state, the intermediate state and the end state to be converted, the plurality of states including the states included in each path, and the plurality of events including the events included in each path. Next, for each path, a test case corresponding to each path can be generated based on each path and the association identifier. As can be seen, the state machine graph can be used to determine each path and events having an association relationship, so as to test from two angles of the path and the events having an association relationship, i.e., each path is tested at least once and each event is tested at least once, so that the coverage of the test case is greatly widened, and therefore, the completeness and accuracy of the test case are improved, thereby improving the effectiveness of the test case. BRIEF DESCRIPTION OF DRAWINGS

[0021] Figure 1 A flowchart of a test case generation method provided by the embodiments of this application;

[0022] Figure 2a A schematic diagram of a state machine graph provided by the embodiments of this application;

[0023] Figure 2b Another schematic diagram of a state machine graph provided by the embodiments of this application;

[0024] Figure 3 A structural schematic diagram of a test case generation apparatus provided by the embodiments of this application;

[0025] Figure 4 A structural schematic diagram of a server provided by the embodiments of this application;

[0026] Figure 5 A structural schematic diagram of a terminal device provided by the embodiments of this application. DETAILED DESCRIPTION

[0027] In order to facilitate understanding, the following first introduces the terms that may be involved in the embodiments of this application.

[0028] The state machine, composed of a state register and a combinational logic circuit, can perform state transition according to a preset state according to a control signal, and is a control center for coordinating the actions of related signals and completing specific operations. Among them, the state machine can include a finite state machine (FSM) representing a mathematical model of a finite number of states and transitions and actions between these states. The state machine involved in the embodiments of the present application is a finite state machine.

[0029] As described above, with the rapid development of business, the state machine graph becomes more and more complex. In the related art, Pymodel (a tool implemented based on Python) can be used to test coverage from two angles of state and state transition, that is, test each state at least once and test each possible state transition at least once, thereby generating test cases. Alternatively, GraphWalker (a tool implemented based on Java) can be used to test coverage from two angles of state and state transition, thereby generating test cases. However, the above Pymodel and GraphWalker can only test coverage from two angles of state and state transition, and therefore, in the face of a complex state machine graph, for example, in the case where the transition between two states can be triggered by multiple events, or in the case where multiple events triggering state transition can have an association relationship and cannot be combined at will, the above method still cannot generate accurate and complete test cases, and may result in repeated or missed test cases, thereby affecting the effectiveness of the test cases.

[0030] Based on the above problems, the embodiments of the present application provide a method for generating test cases, which can include: first, obtaining a state machine graph, the state machine graph including a plurality of states and a plurality of events for triggering the plurality of states to transition, events having an association relationship in the plurality of events including an association identifier. Then, the state machine graph can be analyzed to obtain a plurality of paths, each path in the plurality of paths including a start state, an intermediate state, an end state, and events for triggering the start state, the intermediate state, and the end state to transition, the plurality of states including the states included in each path, and the plurality of events including the events included in each path. Next, for each path, a test case corresponding to each path can be generated based on each path and the association identifier.

[0031] As can be seen, with the aid of the state machine graph, each path and events having an association relationship can be determined, so as to test coverage from two angles of path and events having an association relationship, that is, test each path at least once and test each event at least once, so that the coverage of the test cases is greatly widened, and therefore, the completeness and accuracy of the test cases can be improved, thereby improving the effectiveness of the test cases.

[0032] It should be noted that the embodiments of the present application do not limit the execution subject of the technical solutions of the present application. For example, the test case generation method provided by the embodiments of the present application can be applied to a user terminal or a server, or be processed by the user terminal and the server cooperatively. As an example, the user terminal includes but is not limited to a mobile phone, a computer, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, etc. The server can be a stand-alone server, a cluster server or a cloud server.

[0033] In order for those skilled in the art to better understand the technical solutions of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0034] Figure 1 A flowchart of a test case generation method provided by an embodiment of the present application is shown in FIG. 1. In conjunction with FIG. 1, the test case generation method provided by the embodiments of the present application can include the following steps. Figure 1

[0035] S101: Obtain a state machine graph.

[0036] In the embodiments of the present application, the state machine graph can be obtained by drawing by a user through a Finite State Machine Editor (a kind of finite state machine tool). The state machine graph can include a plurality of states and a plurality of events for triggering the plurality of states to be converted, the plurality of events include respective identifiers, and events having an association relationship include the same identifier. In order to facilitate understanding, the state machine graph will be described exemplarily below in conjunction with the drawings.

[0037] Figure 2a A schematic diagram of a state machine graph provided by an embodiment of the present application is shown in FIG. 2. In conjunction with FIG. 2, the state machine graph provided by the embodiments of the present application can include the following steps. Figure 2a ​In this context, multiple states can include state 1, state 2, state 3, state 4, and state 5. Multiple events used to trigger transitions between these states can include event A1, event A2, event B1, event B2, event C1, event C2, event D, and event E. Specifically, a transition from state 1 to state 2 can be triggered by either event A1 or event A2; a transition from state 2 to state 3 can be triggered by event E; a transition from state 1 to state 3 can be triggered by event D; a transition from state 2 to state 4 can be triggered by either event B1 or event B2; and a transition from state 2 to state 5 can be triggered by either event C1 or event C2. Furthermore, regarding the transitions from state 1 to state 2 and from state 2 to state 4, events A1, A2, B1, and B2 are related. This relationship is such that if a transition from state 1 to state 2 is triggered by event A1, then a transition from state 2 to state 4 can only be triggered by event B1; and if a transition from state 1 to state 2 is triggered by event A2, then a transition from state 2 to state 4 can only be triggered by event B2. Therefore, among the four events mentioned above, events A1 and B1 can include the same identifier, such as tag1, and events A2 and B2 can include the same identifier, such as tag2.

[0038] S102: Analyze the state machine diagram to obtain multiple paths.

[0039] Each of the multiple paths includes a start state, an intermediate state, an end state, and an event that triggers the transition between the start state, intermediate state, and end state. The multiple states can include the states included in each path, that is, the start state, intermediate state, and end state in each path; the multiple events can include the events included in each path, that is, the events in each path that trigger the transition between the start state, intermediate state, and end state.

[0040] Based on this, in the embodiment of the present application, the process of analyzing the state machine graph, that is, step S102, can specifically include: traversing the state machine graph to determine a plurality of states and a plurality of events in the state machine graph; determining a start state and an end state from the plurality of states, the start state being a state with a start identifier in the plurality of states, and the end state being a state that does not transition to other states in the plurality of states; establishing a state machine adjacency matrix based on the plurality of states and the plurality of events, the rows and columns of the state machine adjacency matrix being used to represent the plurality of states, and an element in the state machine adjacency matrix being used to represent whether there is an event for triggering a transition between the state represented by the row corresponding to the element and the state represented by the column corresponding to the element; and performing path search based on the start state, the end state, and the state machine adjacency matrix to obtain a plurality of paths. Since each path is from a starting point to an ending point, by determining the start state and the end state and with the aid of the state machine adjacency matrix, all paths from the start state to the end state can be accurately determined, which helps subsequent testing coverage from the perspective of the paths, thereby improving the accuracy of the test cases. For ease of understanding, the analysis process can be exemplarily illustrated below in combination with Figure 2a the state machine graph shown in FIG. 1.

[0041] As mentioned earlier, in the embodiment of the present application, the start state and the end state can be determined based on the start identifier and the state machine graph. Figure 2a Based on this, the plurality of states can include state 1, state 2, state 3, state 4, and state 5, and the plurality of events for triggering the plurality of states to transition can include event A1, event A2, event B1, event B2, event C1, event C2, event D, and event E. Based on this, the start identifier can be set as start, so that the state pointed to by start is the start state, that is, state 1 is the start state of each path. Further, in combination with the state machine graph shown in FIG. 1, in the path from state 1 to state 2 and then to state 4, since state 4 does not have an edge pointing to other states, that is, it does not transition to other states, state 4 is the end state of the path, and state 2 is the intermediate state of the path. In the path from state 1 to state 2 and then to state 3, since state 3 does not have an edge pointing to other states, that is, it does not transition to other states, state 3 is the end state of the path, and state 2 is the intermediate state of the path. In the path from state 1 to state 2 and then to state 5, since state 5 does not have an edge pointing to other states, that is, it does not transition to other states, state 5 is the end state of the path, and state 2 is the intermediate state of the path. Figure 2a

[0042] In addition, for ease of understanding, the above state machine adjacency matrix can be exemplarily illustrated below in combination with Table 1.

[0043] Table 1

[0044]

[0045]

[0046] As mentioned earlier, the rows and columns of the state machine adjacency matrix are used to represent multiple states. An element in the state machine adjacency matrix indicates whether an event exists that triggers a transition from the state represented by the row corresponding to that element to the state represented by the column corresponding to that element. Based on this, for example, referring to Table 1 above, the state machine adjacency matrix can include 5 rows and 5 columns, representing states 1, 2, 3, 4, and 5. Specifically, the element in the first row and first column is 0, which indicates that there is no event that triggers a transition from state 1 to state 2; the element in the first row and second column is 1, which indicates that there is an event that triggers a transition from state 1 to state 2. In this way, by combining the start state and end state of each path with the aforementioned state machine adjacency matrix, all paths transitioning from a specific start state to a specific end state can be determined using a path search algorithm. It should be noted that in this embodiment, the algorithm for path search based on the adjacency matrix is ​​not specifically limited; any existing or future algorithm that can perform path search based on the adjacency matrix can be used.

[0047] Furthermore, in practical applications, state machine diagrams may contain cyclic paths. For example, combining... Figure 2b As shown, there is a path that transitions from state 1 to state 2, then to state 5, and finally back to state 1, then transitions from state 1 to state 2 again in a loop. This cyclical path can cause the state machine to enter an infinite loop, generating unusable test cases. Therefore, in this embodiment, the path search process can include: performing a path search based on the start state, end state, and state machine adjacency matrix to obtain multiple first paths; for each first path, obtaining the number of times each state appears in that first path; and determining multiple paths based on the multiple first paths and the number of times each state appears in each first path. These multiple paths include paths where the state in each of the multiple first paths appears 1 times, and paths where the first state with a frequency of 2 times is the end state. In each of the multiple paths, the frequency of each state is less than or equal to 2.

[0048] Still with Figure 2bFor example, the path from state 1 to state 2, from state 2 to state 5, and finally from state 5 to state 1, and then from state 1 to state 2, and so on, in the state machine graph, is taken as an example. Through the above path searching manner, it can be determined that the state with the first occurrence number of 2 is state 1. Moreover, since the occurrence number of each state in each path is less than or equal to 2, when the state 1 with the occurrence number of 2 appears for the first time, the cycle of the path ends. Therefore, one of the final obtained paths is the path from state 1 to state 2, from state 2 to state 5, and finally from state 5 to state 1. In addition, the multiple paths can also include a path in which each state appears only once, for example, the path from state 1 to state 2, and from state 2 to state 3.

[0049] S103: generating a test case based on each path and the identifiers of events included in each path.

[0050] In the embodiments of the present application, the test case can be generated based on each path in the state machine graph and the combination of multiple events used to trigger state transition.

[0051] In actual applications, not all event combinations are available. As mentioned earlier, there can be an association relationship between multiple events. For example, if event A1 is used to trigger the transition from state 1 to state 2, then event B1 must be used to trigger the transition from state 2 to state 4. If event A2 is used to trigger the transition from state 1 to state 2, then event B2 must be used to trigger the transition from state 2 to state 4. This association relationship makes multiple events unable to be combined at will. Therefore, in the embodiments of the present application, the multiple paths and the identifiers of events included in each path can be further combined to filter to obtain effective event combinations, thereby helping to improve the completeness and accuracy of the test case and improve the effectiveness of the test case. For ease of understanding, the following describes a possible implementation.

[0052] As a possible implementation, the process of generating a test case, that is, step S103, can include: performing intersection calculation on the identifiers of events included in each path in turn to obtain a calculation result corresponding to each path; based on the calculation results corresponding to the multiple paths respectively, filtering a second path from the multiple paths, and the calculation result corresponding to the second path is a non-empty set; and based on the second path, generating a first test case corresponding to the second path. The test case can include the first test case generated above. As mentioned earlier, events with an association relationship include the same identifier. Therefore, when the calculation result is an empty set through the intersection calculation on the identifiers of events, it can be indicated that the event combination has an incorrect association relationship, and therefore is an invalid event combination, which needs to be filtered out. For ease of understanding, the following describes the process of intersection calculation through multiple examples.

[0053] As an example, the identification of event 1 is "tag1||tag2", and the identification of event 2 is "tag3". Since there is no same identification between event 1 and event 2, the calculation result of the intersection calculation of the identification of event 1 and the identification of event 2 is an empty set, and therefore the combination needs to be filtered.

[0054] As another example, the identification of event 1 is "tag1||tag2", the identification of event 2 is "tag2", and the identification of event 3 is "tag3". Since there is a same identification tag2 between event 1 and event 2, the calculation result of the intersection calculation of the identification of event 1 and the identification of event 2 is "tag2", but the calculation result of the intersection calculation with the identification of event 3 (i.e. the intersection calculation of tag2 and tag3) is an empty set, and therefore the combination needs to be filtered.

[0055] As yet another example, the identification of event 1 is "tag1||tag2", the identification of event 2 is "tag2", and the identification of event 3 is "tag2||tag3". Since there is a same identification tag2 between event 1 and event 2, the calculation result of the intersection calculation of the identification of event 1 and the identification of event 2 is "tag2", and the calculation result of the intersection calculation with the identification of event 3 (i.e. the intersection calculation of tag2 and tag2||tag3) is "tag2", and therefore the combination does not need to be filtered, and the corresponding path is the second path.

[0056] Further, in actual applications, the test cases described above can include normal test cases or abnormal test cases, and the abnormal test cases can include abnormal event triggered abnormal test cases and reentrant event triggered abnormal test cases. Based on this, the first test case corresponding to the second path described above can be embodied as a normal test case. The generation mode of the abnormal test case can be further generated by the first test case, which will be described in detail below.

[0057] As a possible implementation, the process of generating the test case, i.e., step S103, can include: sequentially performing intersection calculation on the identification of the events included in each path to obtain a calculation result corresponding to each path; based on the calculation results corresponding to the plurality of paths respectively, screening a second path from the plurality of paths, the calculation result corresponding to the second path being a non-empty set; based on the second path, generating a first test case corresponding to the second path; traversing the first test case to trigger an abnormal event or a reentry event in the first test case; based on the abnormal event or the reentry event, generating a second test case corresponding to the second path, the second test case being used to simulate the abnormal event or the reentry event. The test case can include the first test case and the second test case generated above. In this way, by generating the first test case and the second test case, the coverage of the test case can be greatly widened, which can be applied to both normal test environment and abnormal test environment, thus helping to improve the completeness and accuracy of the test case, and thus the effectiveness of the test case can be improved. In addition, it should be noted that the way of screening the second path can be referred to the description above, and will not be repeated here.

[0058] Specifically, the abnormal event in the first test case can be any event, i.e., by traversing the first test case, triggering any event in the first test case to enter an abnormal state. In this way, by generating the second test case through the abnormal event, the abnormal event can be simulated to verify whether the business system corresponding to the state machine can respond reasonably to the abnormality.

[0059] The reentry event in the first test case can also be any event, i.e., by traversing the first test case, triggering any event in the first test case to enter a reentry state. The reentry state can include a normal reentry state and an abnormal reentry state, the normal reentry state being that a certain event executes reentry in response to a reentry request, and the abnormal reentry state being that a certain event executes reentry after an abnormality occurs and recovers to normal. In this way, by generating the second test case through the reentry event, the reentry event can be simulated to verify whether the business system corresponding to the state machine can perceive the reentry request and respond reasonably, not repeat processing, and whether the business system can perceive that the event needs to reenter after recovering to normal and execute it.

[0060] In addition, in actual application, the second test case can be repeatedly generated due to the same path or event in advance, and therefore, in the embodiment of the present application, the second test case can be further processed to achieve the effect of deduplication. Specifically, the method for generating the test case can further include: obtaining a first path pool and a second path pool, the first path pool including test paths divided according to events, and the second path pool including test paths divided according to states; dividing the second test case according to events in the second path to obtain a plurality of first test paths, and dividing the second test case according to states in the second path to obtain a plurality of second test paths; deleting, from the plurality of first test paths, a first test path that is the same as a test path in the first path pool based on the first path pool to obtain remaining first test paths, and deleting, from the plurality of second test paths, a second test path that is the same as a test path in the second path pool based on the second path pool to obtain remaining second test paths; and generating a new second test case based on the remaining first test paths and the remaining second test paths.

[0061] According to the embodiment of the present application, the first test path is obtained by dividing the second test case according to each event in the second path, and the second test path is obtained by dividing the second test case according to each state in the second path. Further, in the embodiment of the present application, the first path pool and the second path pool can be constructed in advance, the first path pool being used to store test paths divided according to defined events, and the second path pool being used to store test paths divided according to defined states. In this way, the first path pool can be used to delete duplicate paths in the first test path, and the second path pool can be used to delete duplicate paths in the second test path, thereby achieving the effect of deduplication, which is helpful for generating a new second test case based on the remaining first test paths and the remaining second test paths, avoiding duplication of test cases, and improving the effectiveness of the test cases.

[0062] Further, in the embodiment of the present application, the method for generating the test case can further include: in response to a test case generation request, outputting the test case according to a format or a language template included in the test case generation request. In this way, the test case matched with the test case generation request can be outputted, improving the ease of use and the writing efficiency.

[0063] In actual application, the format included in the use case generation request can be a text use case format or an automated use case format. The text use case format can include at least one of a txt format (a text format), an xmind format (a mind map format), and an excel format (an electronic spreadsheet format). The automated use case can output a corresponding use case framework according to different language templates to obtain a test case. The use case framework can include at least one of Selenium (a framework for web application testing), Appium (a framework for mobile application testing), Pytest (a python test-based framework), and JUnit / TestNG (a framework for Java testing).

[0064] Based on the related content of the steps S101-S103, in the embodiment of the application, the state machine graph can be acquired first, the state machine graph includes a plurality of states and a plurality of events for triggering the plurality of states to convert, events having a correlation relationship in the plurality of events include a correlation identifier. Then, the state machine graph can be analyzed to obtain a plurality of paths, each path in the plurality of paths includes a start state, an intermediate state, an end state, and events for triggering the start state, the intermediate state, and the end state to convert, the plurality of states include the states included in each path, and the plurality of events include the events included in each path. Next, for each path, the test case corresponding to each path can be generated based on each path and the correlation identifier. As can be seen, the state machine graph can be used to determine each path and events having a correlation relationship, so as to test from two angles of the path and the events having a correlation relationship, that is, to test each path at least once and each event at least once. In this way, the coverage of the test case is greatly widened, and therefore, the completeness and accuracy of the test case can be improved, so that the effectiveness of the test case can be improved.

[0065] Based on the test case generation method provided in the foregoing embodiment, the embodiment of the application can also correspondingly provide a test case generation device. The test case generation device will be described below in combination with embodiments and drawings.

[0066] Figure 3 A structural schematic diagram of a test case generation device provided in the embodiment of the application is shown in FIG. 3. As shown in FIG. 3, the test case generation device 300 provided in the embodiment of the application includes: Figure 3

[0067] The state machine graph acquisition module 301 is configured to acquire a state machine graph, the state machine graph includes a plurality of states and a plurality of events for triggering the plurality of states to convert, the plurality of events include respective identifiers, and events having a correlation relationship include the same identifier. ​

[0068] The state machine graph analysis module 302 is configured to analyze the state machine graph to obtain a plurality of paths, each of the plurality of paths including a start state, an intermediate state, an end state, and events for triggering transitions of the start state, the intermediate state, and the end state, the plurality of states including states included in each of the plurality of paths, and the plurality of events including events included in each of the plurality of paths;

[0069] The test case generation module 303 is configured to generate a test case based on the each of the plurality of paths and the events included in the each of the plurality of paths.

[0070] Optionally, the state machine graph analysis module 302 includes:

[0071] The state machine graph traversal module is configured to traverse the state machine graph to determine the plurality of states and the plurality of events in the state machine graph.

[0072] The state determination module is configured to determine a start state and an end state from the plurality of states, the start state being a state having a start identifier in the plurality of states, and the end state being a state that does not transition to another state in the plurality of states.

[0073] The matrix establishment module is configured to establish a state machine adjacency matrix based on the plurality of states and the plurality of events, rows and columns of the state machine adjacency matrix being used to represent the plurality of states, and an element in the state machine adjacency matrix being used to represent whether there is an event for triggering a transition from a state represented by a row corresponding to the element to a state represented by a column corresponding to the element.

[0074] The path search module is configured to perform path search based on the start state, the end state, and the state machine adjacency matrix to obtain the plurality of paths.

[0075] Optionally, the path search module includes:

[0076] The path search submodule is configured to perform path search based on the start state, the end state, and the state machine adjacency matrix to obtain a plurality of first paths.

[0077] The occurrence number acquisition module is configured to, for each of the plurality of first paths, acquire an occurrence number of a state in the each of the plurality of first paths.

[0078] The path determination module is configured to determine the plurality of paths based on the plurality of first paths and the number of occurrences of each state in the first paths, the plurality of paths including paths in which the number of occurrences of a state in the plurality of first paths is 1 and paths in which a state with a first number of occurrences is 2, and in each path in the plurality of paths, the number of occurrences of each state is less than or equal to 2.

[0079] Optionally, the test case generation module 303 comprises:

[0080] The intersection calculation module is configured to perform intersection calculation on the identifiers of the events included in each path in sequence to obtain a calculation result corresponding to each path.

[0081] The path screening module is configured to screen a second path from the plurality of paths based on the calculation results corresponding to the plurality of paths respectively, the calculation result corresponding to the second path being a non-empty set.

[0082] The first test case generation module is configured to generate a first test case corresponding to the second path based on the second path, the test case including the first test case.

[0083] Optionally, the test case generation module 303 comprises:

[0084] The intersection calculation module is configured to perform intersection calculation on the identifiers of the events included in each path in sequence to obtain a calculation result corresponding to each path.

[0085] The path screening module is configured to screen a second path from the plurality of paths based on the calculation results corresponding to the plurality of paths respectively, the calculation result corresponding to the second path being a non-empty set.

[0086] The first test case generation module is configured to generate a first test case corresponding to the second path based on the second path.

[0087] The test case traversal module is configured to traverse the first test case to trigger an abnormal event or a reentrant event in the first test case.

[0088] The second test case generation module is configured to generate a second test case corresponding to the second path based on the abnormal event or the reentrant event, the second test case being used to simulate the abnormal event or the reentrant event, the test case including the first test case and the second test case.

[0089] Optionally, the test case generation apparatus 300 further comprises:

[0090] a path pool obtaining module, configured to obtain a first path pool and a second path pool, the first path pool comprising test paths of test cases divided according to events, and the second path pool comprising test paths of test cases divided according to states;

[0091] a test case dividing module, configured to divide the second test cases based on events in the second paths to obtain a plurality of first test paths, and divide the second test cases based on states in the second paths to obtain a plurality of second test paths;

[0092] a test path deleting module, configured to delete, based on the first path pool, the same first test paths as the test paths in the first path pool from the plurality of first test paths to obtain remaining first test paths, and delete, based on the second path pool, the same second test paths as the test paths in the second path pool from the plurality of second test paths to obtain remaining second test paths;

[0093] a third test case generating module, configured to generate new second test cases based on the remaining first test paths and the remaining second test paths.

[0094] Optionally, the test case generating apparatus 300 further comprises:

[0095] a test case outputting module, configured to output the test cases according to a format or a language template included in the case generation request in response to a case generation request.

[0096] The following introduces the structure of a control device implementing the construction method of the knowledge base or the knowledge processing method in the form of a server and a terminal device.

[0097] Figure 4 A server structure diagram is provided for the embodiments of the present application. The server 900 can be quite different due to different configurations or performances, and can include one or more central processing units (CPUs) 922 (for example, one or more processors) and a memory 932, one or more storage media 930 (for example, one or more mass storage devices) storing application programs 942 or data 944. The memory 932 and the storage media 930 can be temporary storage or persistent storage. The programs stored in the storage media 930 can include one or more modules (not shown in the figure), and each module can include a series of instruction operations in the server. Further, the central processing unit 922 can be configured to communicate with the storage media 930 and execute a series of instruction operations in the storage media 930 on the server 900.

[0098] Server 900 may also include one or more power supplies 926, one or more wired or wireless network interfaces 950, one or more input / output interfaces 958, and / or one or more operating systems 941, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSD TM etc.

[0099] The steps performed by the server in the above embodiments can be based on this Figure 4 The server structure shown.

[0100] The CPU 922 is used in the following steps:

[0101] Obtain a state machine diagram, which includes multiple states and multiple events that trigger transitions between the multiple states. Each of the multiple events includes its own identifier, and events with a relationship include the same identifier.

[0102] The state machine diagram is analyzed to obtain multiple paths. Each path includes a start state, an intermediate state, an end state, and an event for triggering the transition between the start state, the intermediate state, and the end state. The multiple states include the states included in each path, and the multiple events include the events included in each path.

[0103] Test cases are generated based on the identifiers of each path and the events included in each path.

[0104] This application also provides another control device, such as... Figure 5 As shown, for ease of explanation, only the parts related to the embodiments of this application are shown. For specific technical details not disclosed, please refer to the method section of the embodiments of this application. The terminal can be any terminal device including mobile phones, tablets, personal digital assistants (PDAs), point-of-sale (POS) terminals, in-vehicle computers, etc. Taking a mobile phone as an example:

[0105] Figure 5 This is a block diagram illustrating a portion of the structure of a mobile phone related to the terminal provided in the embodiments of this application. (Reference) Figure 5The mobile phone includes: radio frequency (RF) circuit 1010, memory 1020, input unit 1030, display unit 1040, sensor 1050, audio circuit 1060, wireless fidelity (WiFi) module 1070, processor 1080, and power supply 1090, and the like. Those skilled in the art can understand that Figure 5 The mobile phone structure shown in the figure does not constitute a limitation on the mobile phone, and can include more or fewer components than shown, or combine certain components, or different component arrangements.

[0106] The following will be described in detail Figure 5 The various components of the mobile phone will be described in detail:

[0107] The RF circuit 1010 can be used for receiving and sending signals in the process of information or call, especially, receiving the downlink information of the base station and processing by the processor 1080; in addition, sending the uplink data to the base station. Usually, the RF circuit 1010 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (LNA), a duplexer, and the like. In addition, the RF circuit 1010 can also communicate with the network and other devices through wireless communication. The above wireless communication can use any communication standard or protocol, including but not limited to global system of mobile communication (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), long term evolution (LTE), email, short message service (SMS), and the like.

[0108] The memory 1020 can be used to store software programs and modules, and the processor 1080 can execute various function applications and data processing of the mobile phone by running the software programs and modules stored in the memory 1020. The memory 1020 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.), and the like; and the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), and the like. In addition, the memory 1020 can include a high-speed random access memory, and can also include a non-volatile memory, for example, at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device.

[0109] The input unit 1030 can be used to receive inputted digital or character information, and to generate key signal input related to the user settings and function control of the mobile phone. Specifically, the input unit 1030 can include a touch panel 1031 and other input devices 1032. The touch panel 1031, also called a touch screen, can collect the touch operation of a user thereon or nearby (such as the operation of the user using a finger, a stylus, or any suitable object or accessory on or near the touch panel 1031), and drive the corresponding connection device according to the pre-set program. Optionally, the touch panel 1031 can include two parts of a touch detection device and a touch controller. The touch detection device detects the touch position of the user and detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, and converts it into touch coordinates, and then sends it to the processor 1080, and can also receive the command from the processor 1080 and execute it. In addition, the touch panel 1031 can be implemented in various types such as a resistive type, a capacitive type, an infrared type, and a surface acoustic wave type. In addition to the touch panel 1031, the input unit 1030 can also include other input devices 1032. Specifically, the other input devices 1032 can include one or more of a physical keyboard, a function key (such as a volume control key, an on-off key, etc.), a trackball, a mouse, a joystick, and the like.

[0110] The display unit 1040 can be used to display information input by a user or information provided to the user as well as various menus of the phone. The display unit 1040 can include a display panel 1041, which can optionally be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like. Further, a touch panel 1031 can cover the display panel 1041, and when the touch panel 1031 detects a touch operation thereon or proximate thereto, it transmits to the processor 1080 to determine the type of touch event, and then the processor 1080 provides corresponding visual output on the display panel 1041 according to the type of touch event. Although in the above embodiment, the touch panel 1031 and the display panel 1041 are implemented as two independent components to realize the input and output functions of the phone, in some embodiments, the touch panel 1031 and the display panel 1041 can be integrated to realize the input and output functions of the phone. Figure 5

[0111] The phone can also include at least one sensor 1050, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor can include an ambient light sensor and a proximity sensor, wherein the ambient light sensor can adjust the brightness of the display panel 1041 according to the brightness of ambient light, and the proximity sensor can turn off the display panel 1041 and / or the backlight when the phone is moved to the ear. As one of the motion sensors, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), and when at rest, it can detect the magnitude and direction of gravity, which can be used for applications that identify the posture of the phone (such as landscape / portrait screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), and the like. As for other sensors that the phone can also be configured, such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, and the like, they will not be described here.

[0112] The audio circuit 1060, the speaker 1061, and the microphone 1062 can provide an audio interface between the user and the phone. The audio circuit 1060 can convert received audio data into an electrical signal, which is transmitted to the speaker 1061 to be converted into a sound signal for output; on the other hand, the microphone 1062 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1060 to be converted into audio data, which is then output to the processor 1080 for processing, and then transmitted to another phone via the RF circuit 1010, or output to the memory 1020 for further processing.

[0113] ​WiFi belongs to short distance wireless transmission technology, and the WiFi module 1070 can help the user to send and receive emails, browse web pages and access streaming media, etc. It provides the user with wireless broadband Internet access. Figure 5 The WiFi module 1070 is shown, but it is understood that it does not belong to the necessary structure of the mobile phone, and can be omitted as needed without changing the essence of the application.

[0114] The processor 1080 is the control center of the mobile phone, which connects all parts of the mobile phone through various interfaces and lines, executes various functions of the mobile phone and processes data by running or executing software programs and / or modules stored in the memory 1020 and calling data stored in the memory 1020, thereby collecting overall data and information of the mobile phone. Optionally, the processor 1080 can include one or more processing units; preferably, the processor 1080 can integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, etc., and the modem processor mainly processes wireless communication. It is understood that the above-mentioned modem processor can also not be integrated into the processor 1080.

[0115] The mobile phone also includes a power supply 1090 (such as a battery) for supplying power to various components, and preferably the power supply can be logically connected to the processor 1080 through a power management system, so as to realize the functions of managing charging, discharging and power consumption management, etc. through the power management system.

[0116] Although not shown, the mobile phone can also include a camera, a Bluetooth module, etc., which will not be described here.

[0117] In the embodiments of the present application, the processor 1080 included in the terminal also has the following functions:

[0118] Obtain a state machine graph, the state machine graph includes a plurality of states and a plurality of events for triggering the plurality of states to transition, the plurality of events include respective identifiers, and events having an association relationship include the same identifier;

[0119] Analyze the state machine graph to obtain a plurality of paths, each path in the plurality of paths includes a start state, an intermediate state, an end state, and events for triggering the start state, the intermediate state and the end state to transition, the plurality of states include the states included in each path, and the plurality of events include the events included in each path;

[0120] Generate test cases based on the each path and the identifiers of the events included in the each path.

[0121] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined target, and can be implemented entirely or partially by using software, hardware (such as a processing circuit or a memory) or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an integral module or unit that includes the functions of the module or unit.

[0122] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.

[0123] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or other forms.

[0124] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0125] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0126] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or say the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (English full name: Read-Only Memory, English abbreviation: ROM), a random access memory (English full name: Random Access Memory, English abbreviation: RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0127] The above embodiments are only used to illustrate the technical solutions of the present application, rather than limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for generating test cases, characterized in that, include: Obtain a state machine diagram, which includes multiple states and multiple events that trigger transitions between the multiple states. Each of the multiple events includes its own identifier, and events with a relationship include the same identifier. The state machine diagram is analyzed to obtain multiple paths. Each path includes a start state, an intermediate state, an end state, and an event for triggering the transition between the start state, the intermediate state, and the end state. The multiple states include the states included in each path, and the multiple events include the events included in each path. Test cases are generated based on the identifiers of each path and the events included in each path.

2. The test case generation method according to claim 1, characterized in that, The analysis of the state machine diagram yields multiple paths, including: Traverse the state machine diagram to determine the plurality of states and the plurality of events in the state machine diagram; A start state and an end state are determined from the plurality of states, wherein the start state is the state with a start identifier among the plurality of states, and the end state is the state among the plurality of states that does not transition to other states. A state machine adjacency matrix is ​​established based on the multiple states and the multiple events. The rows and columns of the state machine adjacency matrix are used to represent the multiple states. An element in the state machine adjacency matrix is ​​used to indicate whether there is an event that triggers a transition from the state represented by the row corresponding to the element to the state represented by the column corresponding to the element. Path search is performed based on the start state, end state, and the adjacency matrix of the state machine to obtain the multiple paths.

3. The test case generation method according to claim 2, characterized in that, The path search based on the start state, end state, and the adjacency matrix of the state machine yields the multiple paths, including: Path search is performed based on the start state, end state, and the adjacency matrix of the state machine to obtain multiple first paths; For each first path, obtain the number of times the state appears in each first path; Based on the plurality of first paths and the occurrence count of states in each of the first paths, the plurality of paths are determined. The plurality of paths include paths in the plurality of first paths where the occurrence count of a state is 1, and paths in the plurality of first paths where the first state with an occurrence count of 2 is used as the ending state. In each of the plurality of paths, the occurrence count of each state is less than or equal to 2.

4. The test case generation method according to claim 1, characterized in that, The generation of test cases based on each path and the identifiers of the events included in each path includes: The intersection of the event identifiers included in each path is calculated sequentially to obtain the calculation result corresponding to each path; Based on the calculation results corresponding to the multiple paths, a second path is selected from the multiple paths, and the calculation results corresponding to the second path are a non-empty set; Based on the second path, a first test case corresponding to the second path is generated, and the test case includes the first test case.

5. The test case generation method according to claim 1, characterized in that, The generation of test cases based on each path and the identifiers of the events included in each path includes: The intersection of the event identifiers included in each path is calculated sequentially to obtain the calculation result corresponding to each path; Based on the calculation results corresponding to the multiple paths, a second path is selected from the multiple paths, and the calculation results corresponding to the second path are a non-empty set; Based on the second path, generate the first test case corresponding to the second path; Iterate through the first test case and trigger any exception or reentrancy event in the first test case. Based on the abnormal event or reentrancy event, a second test case corresponding to the second path is generated. The second test case is used to simulate the abnormal event or reentrancy event. The test case includes the first test case and the second test case.

6. The test case generation method according to claim 5, characterized in that, The method for generating test cases also includes: Obtain a first path pool and a second path pool. The first path pool includes test paths that divide test cases according to events, and the second path pool includes test paths that divide test cases according to states. The second test case is divided based on the events in the second path to obtain multiple first test paths, and the second test case is divided based on the states in the second path to obtain multiple second test paths; Based on the first path pool, first test paths that are the same as test paths in the first path pool are deleted from the plurality of first test paths to obtain the remaining first test paths; and based on the second path pool, second test paths that are the same as test paths in the second path pool are deleted from the plurality of second test paths to obtain the remaining second test paths. A new second test case is generated using the remaining first test path and the remaining second test path.

7. The method for generating test cases according to any one of claims 1 to 6, characterized in that, The method for generating test cases also includes: In response to a test case generation request, the test cases are output according to the format or language template included in the test case generation request.

8. A test case generation device, characterized in that, include: A state machine diagram acquisition module is used to acquire a state machine diagram, which includes multiple states and multiple events that trigger the transitions of the multiple states. The multiple events include their own identifiers, and events with related relationships include the same identifier. The state machine diagram analysis module is used to analyze the state machine diagram to obtain multiple paths. Each path includes a start state, an intermediate state, an end state, and an event for triggering the transition between the start state, the intermediate state, and the end state. The multiple states include the states included in each path, and the multiple events include the events included in each path. The test case generation module is used to generate test cases based on each path and the identifiers of the events included in each path.

9. An electronic device, characterized in that, The device includes a processor and a memory: The memory is used to store computer programs and to transfer the computer programs to the processor; The processor is configured to execute the steps of the test case generation method according to any one of claims 1 to 7, based on instructions in the computer program.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program, which, when executed by a terminal device, implements the steps of the test case generation method according to any one of claims 1 to 7.

11. A computer program product, characterized in that, It includes a computer program that, when executed by a terminal device, implements the steps of the test case generation method according to any one of claims 1 to 7.