Test case generation method, device and storage medium
By establishing a finite state machine model and a functional block diagram model and converting it into a target finite state machine model, the problem of low accuracy of test cases in the prior art is solved, and more efficient test case generation and more comprehensive software function description are achieved.
Patent Information
- Application Number
- CN202010912176.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-02
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2040-09-02
AI Technical Summary
The test cases generated in the prior art are of low accuracy and it is difficult to accurately describe the logical relationship between software functions and inputs and outputs.
By establishing a finite state machine model and a functional block diagram model, combined with preset conversion rules, the functional block diagram model is converted into a transformed finite state machine model that describes the change of the software's running state, and is associated with the finite state machine model to generate the target finite state machine model. Based on this model, test cases are generated using a traversal algorithm.
It improves the accuracy and coverage of test cases, can describe software functions more comprehensively, avoids state explosion problems, and automatically generates test cases, reduces human errors and improves test design efficiency.
Smart Images

Figure CN114201381B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of software testing for embedded software development, and in particular relates to a test case generation method, equipment and storage medium. Background Art
[0002] Software testing is an important guarantee of software quality. In the field of software testing, the writing of test cases and test scripts has always been an important task of software testing. The quality of test cases and test scripts has a significant impact on the quality of testing and the quality of the tested software. For the same requirements, the quality of test cases and test scripts written by testers of different levels varies greatly, and manual writing of test cases and test scripts is labor-intensive and inefficient.
[0003] Model based testing (MBT) is a testing method in the field of software testing. It automatically generates test cases and test codes by establishing test scenarios or models (hereinafter referred to as models). It is an emerging technology for software testing. Compared with traditional testing technologies, MBT is more intuitive and easier to understand. It can automatically generate test data and has high test coverage. The logical path of the test case can be easily displayed, which is convenient for checking requirements and codes, and saves a lot of repetitive code writing. The code of the test case is generated by the model, which can improve the test efficiency. In addition, the MBT model is intuitive and easier to understand. It automatically generates test cases and test scripts through algorithms, which can improve the quality of test design and test cases.
[0004] like Figure 1 As shown, Figure 1 This is a flowchart based on MBT testing. Figure 1 The steps of MBT testing are generally as follows: 100. Analyze software requirements and specifications; 101. Build a model based on the requirements; 102. Check whether the model is passed and if so, execute steps 103 and 104; if not, return to step 101; 103. Generate test cases based on the model; 104. Generate test scripts based on the model or test cases.
[0005] A lot of research has been conducted on MBT testing technology both at home and abroad, and some MBT testing methods have been formed. At present, the typical MBT testing methods are as follows: testing methods based on causal diagram models, testing methods based on decision tables (DecisionTables) models, testing methods based on orthogonal table models, testing modeling methods based on FSM (Finite-state machine) finite state machine models, testing methods based on UML (Unified Modeling Language) unified modeling language, and testing methods based on FBD (Function Block Diagram) function block diagram models.
[0006] The FSM model is a mathematical model that represents a finite number of states and the transitions and actions between these states. The FSM model can better describe the running state and migration process of the software. At the same time, the FSM model is a strong semantic description model. Therefore, automatically generating test cases based on the FSM model is a relatively common test case automatic generation method. However, for software with many signals and a large number of logical relationships between signals, the FSM model is difficult to intuitively and clearly describe the logical relationship between signals, and even state explosion may occur due to the increase in the number of signals. The FBD model has the advantages of clear logic, simplicity and intuition in describing the logical operation relationship between signals, so it has become a commonly used programming language for embedded control software. At the same time, the FBD model can accurately and concisely describe software requirements, so automatically generating test cases based on the FBD model has also become a research hotspot.
[0007] However, many embedded control software not only involve a large number of input and output signals, but also have logical relationships between the signals. Therefore, whether using the FSM model or the FBD model, it is impossible to accurately describe the software functions, resulting in low accuracy of the generated test cases. Summary of the invention
[0008] The main purpose of the present invention is to provide a test case generation method, device and storage medium to solve the problem of low accuracy of test cases generated in the prior art.
[0009] In view of the above problems, in a first aspect, the present invention provides a test case generation method, comprising:
[0010] Establish a finite state machine model based on the states of all software operations in the software requirements specification and the trigger conditions for transitions between different software operation states;
[0011] According to the input and output in the software requirement specification, the logical relationship between input and output, and the constraint relationship between all inputs, a function block diagram model based on a function block diagram-like language is established;
[0012] According to the effective state of the function block diagram model, a software running state is selected in the finite state machine model as the pre-state of the function block diagram model;
[0013] According to a preset conversion rule, the function block diagram model is converted into a conversion finite state machine model that describes the state change process of the software running, and according to the pre-state of the function block diagram model, the conversion finite state machine model is associated with the finite state machine model to obtain a target finite state machine model;
[0014] Based on the target finite state machine model, a preset traversal algorithm is used to generate a test case for each path.
[0015] The present invention also provides a test case generation device, comprising a memory and a processor;
[0016] The memory stores a computer program, which implements the steps of the test case generation method when executed by the processor.
[0017] The present invention also provides a storage medium on which a computer program is stored. When the computer program is executed by a controller, the steps of the test case generation method described above are implemented.
[0018] Compared with the prior art, one or more embodiments of the above scheme may have the following advantages or beneficial effects:
[0019] The test case generation method, device and storage medium of the present invention describe the requirements of software based on two models, the FSM model and the FBD model, and convert the FBD model into a complete FSM model, thereby realizing hybrid modeling by integrating the two models, the FSM model and the FBD model. The method, device and storage medium can accurately and comprehensively describe the running process status of the software, and can accurately describe the logical relationship between the software input and output, thereby improving the accuracy of the generated test cases. At the same time, the method not only extracts the data combination of the FBD model, but also extracts the conversion relationship between the data combinations of the FBD model, thereby allowing the test cases to cover more scenarios and improve the test coverage, while also avoiding the problem of state explosion when converting the FBD model to the FSM model. The method and device of the present invention can also realize the test case generation by automatically generating test cases, thereby avoiding human errors and improving the efficiency of test design.
[0020] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0022] Figure 1 It is a flowchart based on MBT test;
[0023] Figure 2 It is a schematic diagram of the state transition diagram of the FSM model;
[0024] Figure 3 It is a schematic diagram of a FBD model;
[0025] Figure 4 Automatically generate test case flowcharts based on FBD models;
[0026] Figure 5 A flowchart of a test case generation method embodiment of the present invention;
[0027] Figure 6 A schematic diagram of a FSM model established for the present invention;
[0028] Figure 7 A schematic diagram of another FBD model established for the present invention;
[0029] Figure 8 Schematic diagram for solving the entry state when a latch exists;
[0030] Fig. 9 for Figure 7 AND_1 conversion example diagram in the figure;
[0031] Fig.10 for Fig. 9 The corresponding process FSM model;
[0032] Fig.11 The process FSM model obtained by transforming the RS_1 model elements;
[0033] Fig.12 The process FSM model obtained by transforming the GT_1 model elements;
[0034] Fig.13 The process FSM model obtained by transforming the OR_1 model element;
[0035] Fig.14 for Figure 6 and Figure 7 The target FSM model obtained after the corresponding model is converted;
[0036] Fig.15 Flowchart for generating test cases based on the Postman algorithm;
[0037] Fig.16 Flowchart of the algorithm for converting FBD model to FSM;
[0038] Fig.17 for Fig.16 Flowchart of step 165;
[0039] Fig.18 It is a structural schematic diagram of an embodiment of a test case generating device of the present invention. DETAILED DESCRIPTION
[0040] The following will describe the implementation methods of the present invention in detail with reference to the accompanying drawings and embodiments, so that the implementation process of how the present invention applies technical means to solve technical problems and achieve technical effects can be fully understood and implemented accordingly. It should be noted that as long as there is no conflict, the various embodiments of the present invention and the various features in the embodiments can be combined with each other, and the technical solutions formed are all within the protection scope of the present invention.
[0041] The FSM model is a mathematical model that represents a finite number of states and the transitions and actions between these states. The state of the system in the previous cycle and the current input determine the state of the next cycle. A finite state machine M can be represented by a six-tuple M = (S, I, O, δ, λ, s), where:
[0042] S={s0,s1,s2,s3……s n}, is a finite state set;
[0043] I={i0,i1,i2,i3……i n}, is an input event set, which allows to contain empty events, represented by "-";
[0044] O={o0,o1,o2,o3……o n}, is an output event set, which allows to contain empty events, represented by "-";
[0045] :S×I→S, is a transfer function;
[0046] λ: S×I→O, is an output function;
[0047] s0∈S is the initial state of M.
[0048] When the finite state machine is in state s i ∈S, if an input stimulus i∈I is received, the new state that the finite state machine will enter is given by δ(s,i), and the output response λ(s,i) is generated at the same time. After the execution is completed, the finite state machine enters the new state s i ∈S. Figure 2 As shown, Figure 2This is a schematic diagram of the state transition diagram of the FSM model. If the state machine is in the V1 state, if it receives the stimulus b, it will generate output x and the state will be transferred to the V2 state. The principle of the V2 state to the V3 state and the V3 state to the V1 state can be referred to the above record and will not be repeated here.
[0049] The automatic test case generation method based on the FSM model is generally divided into the following steps:
[0050] 1) Establish the FSM model of the software;
[0051] 2) Establish coverage criteria for test case generation;
[0052] 3) Starting from the initial state, traverse the migration path of the FSM model. Each time a complete migration path is traversed, the migration path is converted into a test case;
[0053] 4) Repeat the traversal process of step 3) until the coverage criterion is met.
[0054] FBD is a PLC programming language specified by the IEC 61131 standard. It consists of functions and function blocks. These functions and function blocks are interconnected with each other or connected with variables through connecting lines to form a graphical description language, such as Figure 3 shown. Figure 3 This is a schematic diagram of an FBD model. Figure 3 As shown, the elements of the FBD model may include input variables such as Data_In1-Data_In5, Parameter parameter variables, greater than, and, or logic, latch RS, Data_Out1 output variable, etc.
[0055] Figure 4 It is a flowchart for automatically generating test cases based on the FBD model. Figure 4 As shown in the figure, automatically generating test cases based on the FBD model generally includes the following steps:
[0056] 401. Analyze the software requirements specifications and extract the input and output, logical relationships, and constraint relationships in the requirements specifications;
[0057] 402. By building a model in FBD language according to the requirement specifications;
[0058] 403. Establish rules for FBD model conversion data combination table;
[0059] 404. Convert the FBD model into a data combination table according to the FBD model and the conversion rule;
[0060] 405. Automatically generate test cases based on the data combination table.
[0061] Embodiment 1
[0062] In order to solve the above technical problems existing in the prior art, an embodiment of the present invention provides a test case generation method.
[0063] Figure 5 A flow chart of a test case generation method embodiment of the present invention is shown in FIG. Figure 5 As shown, the test case generation method of this embodiment may specifically include the following steps:
[0064] 500. Establish an FSM model according to the running states of all software in the software requirement specification and the trigger conditions for transitions between the running states of different software;
[0065] Specifically, the core of establishing the FSM model is action and state. A state is composed of a set of variables and their values, representing a certain state of the software under test. An action is a combination of a set of operations or a combination of a set of variables and their changes. An action is a trigger condition for migration between states. Through an action, one can enter another state from one state.
[0066] There is a pointing relationship between states and actions, and between states. The state can be used to index the actions that can be performed by the state, the state can be used to index the previous state and the next state of the state, and the action can be used to index the previous state and the next state of the action.
[0067] When establishing an FSM model, the modeling elements in Table 1 can be used, where Table 1 is the modeling elements of the FSM model:
[0068] Table 1
[0069]
[0070] In this embodiment, according to the running states of all software in the software requirement specification and the trigger conditions for the transition between the running states of different software, when establishing the FSM model, it can be implemented according to the following steps:
[0071] 5001) Analyze the requirements specifications, analyze the main states of software operation, and form a FSM state list;
[0072] 5002) analyzing the triggering conditions for the transitions between different states, establishing the transition relationships between different states, and connecting the different states with the transition relationships;
[0073] 5003) Find the initial state of all states, take the initial state as the starting point, and connect all states in series to form a FSM model.
[0074] Figure 6 A schematic diagram of a FSM model established by the present invention. Figure 6As shown, the FSM model migrates from the initial state S0 to the state S1 through the transition A01, the state S1 migrates to the state S3 through the transition A11, and the state S3 migrates to the state S5 through the transition A31. Other paths are similar to the above path description and will not be repeated here.
[0075] 501. According to the input and output in the software requirement specification, the logical relationship between input and output, and the constraint relationship between all inputs, establish an FBD model based on the function block diagram language;
[0076] Specifically, in the process of establishing the FBD model, it is mainly used to establish the logical relationship between the software input and output signals using a graphical modeling method according to the software requirements. The basic elements of the FBD model follow the IEC61131 standard, and constraints and state elements are added on the basis of the FBD language, as shown in Table 2. Table 2 shows the modeling elements of the FBD model.
[0077] Table 2
[0078]
[0079]
[0080]
[0081]
[0082] In a specific implementation process, the FBD model can be established according to the following steps:
[0083] 5011) Analyze the requirement specifications and extract all the inputs and outputs involved in the requirements;
[0084] 5022) Define the data type, value range, and default test data of input and output;
[0085] 5033) Analyze the relationship between all inputs and outputs, describe the relationship between inputs and outputs using FBD model elements, and draw an FBD model diagram;
[0086] 5044) Analyze the constraint relationship between inputs and express the constraint relationship on the FBD model;
[0087] 5055) Analyze the effective state of the FBD model, and select a state on the established FSM state diagram as the pre-state of the FBD.
[0088] Figure 7 FIG. 1 is a schematic diagram of another FBD model established by the present invention. Figure 7The model elements of the FBD model of the present embodiment shown may include analog input variable 1, parameters (which may be set to 160), constraints (which may be set to be mutually exclusive), Boolean input variables 1-3, greater than GT_1, AND_1, or OR_1, latch RS_1 and Boolean output variable 1.
[0089] 502. According to the effective state of the FBD model, a software running state is selected in the FSM model as the pre-state of the FBD model;
[0090] In a specific implementation process, a software running state can be selected in the FSM model as the pre-state of the FBD model according to the effective state of the FBD model. For example, in this embodiment, it can be known that the state S3 of the FBD model in the FSM model is effective according to the software requirements. At this time, the state S3 in the FSM model can be used as the pre-state of the FBD model, and the pre-state of the FBD model is marked as state 3 in the FBD model.
[0091] 503. According to a preset conversion rule, the FBD model is converted into a conversion FSM model that describes the state change process of the software operation, and according to the pre-state of the FBD model, the conversion FSM model is associated with the FSM model to obtain a target FSM model;
[0092] Specifically, step 503 can be implemented according to the following steps:
[0093] 5031), taking the pre-state of the function block diagram model as the initial state, solving a group of function model elements in the function block diagram model that have a connection relationship with each output model element, and obtaining the entry state of the group of function model elements; wherein the connection relationship here includes direct connection and / or indirect connection. For example, Figure 7 The output model element in is a Boolean output variable, and a group of functional model elements connected to the output model element are a functional model element representing a latch, a functional model element representing logical AND, a functional model element representing logical OR, and a functional model element representing greater than.
[0094] Specifically, the FBD model can be traversed. The FBD model has an output as the root node and is a tree structure. Through the deep traversal algorithm, each model element of the FBD model is searched in turn. For a traversed model element, it is assumed that the model element is FA. If the model element FA is the input model element corresponding to the input variable or the source model element corresponding to the output variable, the next model element is traversed again. If the model element FA is a functional model element, the model element FA can be converted.
[0095] In practical applications, the reason for solving the entry state of a group of functional model elements that are connected to each output model element is that there are RS latch / SR latch model elements in the FBD model. These model elements will affect the final output, resulting in the output change of each functional model element not being able to affect the final output variable. Figure 7 For example, when the GT_1 model element representing greater than is converted, if the Boolean input variable 2 is valid, the Boolean output variable 1 remains invalid regardless of whether the simulation input variable 1 takes a value greater than 160 or a value less than 160, so that the influence of the greater than GT_1 module on the Boolean output variable 1 cannot be tested. Therefore, when the GT_1 model element representing greater than is converted, it is necessary to enter the entry state where the Boolean input variable 1 is valid, the Boolean input variable 2 is invalid, and the Boolean input variable 3 is invalid.
[0096] In a specific implementation process, the method for solving the entry state of the group of functional model elements is as follows:
[0097] If the group of functional model elements includes a functional model element representing a latch, the entry state of the functional model element serially connected to the latch SET port is sequentially migrated to the first state based on the initial state; Figure 8 As shown, Figure 8 Schematic diagram for solving the entry state when a latch exists. Figure 8 In the example, the entry state of each functional model element is sequentially migrated to the initial state S0. Figure 8 The S2 state is shown.
[0098] If the group of functional model elements includes a functional model element representing a latch, the entry state of the functional model element serially connected to the Reset port of the latch is sequentially migrated to a second state based on the initial state; Figure 8 In the example, the entry state of each model element representing the output variable is sequentially migrated to the initial state S0. Figure 8 The S4 state is shown.
[0099] If the group of functional model elements does not include, the entry state of the group of functional model elements maintains the initial state.
[0100] In this embodiment, through the above solution, it can be ensured that in the case of a latch, when the SET port and the Reset port are both 0, it can be determined that the data output by the output port of the latch is clear.
[0101] 5032), according to the preset conversion rules, convert each functional model element into a corresponding expanded FSM model;
[0102] The preset conversion rules in this embodiment may be as follows:
[0103] Each direct input interface of each functional model element covers at least two situations: true and false. If the input interface is a non-Boolean value, it covers at least two different values.
[0104] The direct output interface of each functional model element covers at least two situations: true and false. If the output interface is a non-Boolean value, it covers at least two different values.
[0105] Each direct input of each functional model element triggers at least a change in a direct output of the functional block diagram model while other direct inputs remain unchanged.
[0106] by Figure 7 Take AND_1 in the example, when AND_1 converts the FSM model, AND_1 is connected in series to the SET end of the RS latch, so the entry state is Figure 8 S2 shown in Figure 1. At the same time, in order to meet the transformation rules of model elements, the transformation results are as follows: Fig. 9 .in, Fig. 9 for Figure 7 AND_1 transformation example diagram. Fig. 9 When state 2 migrates, there may be three situations: Aand31: AND_1_I1=1 / AND_1_I2=1, and the resulting state is Sand31: AND_1_Q=1; Aand32: AND_1_I1=1 / AND_1_I2=0, and the resulting state is Sand32: AND_1_Q=0; Aand33: AND_1_I1=0AND_1_I2=1, and the resulting state is Sand33: AND_1_Q=0.
[0107] 5033), for each transition and state of each expanded FSM model, solving the data combination of input variables and output variables that meets the expectations to obtain the corresponding process FSM model;
[0108] In practical applications, the conversion of FBD model elements into FSM model transition and state combinations requires a combination of input variables and output variables, and the input connection of the model element FA may not be an input variable, but a model element. Therefore, the transition / state combination converted into the expanded FSM model diagram in step 5032) is a set of intermediate variable combinations that need to be further solved. Figure 7 Take AND_1 as an example, the I1 input of AND_1 is GT_1, so the converted value is Fig. 9 The expanded FSM model combination shown is based on the direct input / output combination of the element, and is not a data combination of the input variables and output variables of the FBD model. The data combination of the input variables and output variables needs to be further solved.
[0109] In a specific implementation process, step 5033) may be implemented as follows:
[0110] 50331), select a transition state pair ACTi / STi from the transition state pair set FSMa / c; wherein each of the unfolded FSM models contains x transitions, the i-th transition is defined as ACTi, and the only exit state of the transition ACTi is STi; ACTi and STi constitute a pair of transition state combinations ACTi / STi; the set of all transition state combinations ACTi / STi constitutes the transition state pair set FSMa / c of each of the unfolded FSM models;
[0111] 50332), starting from each functional model element, traversing the functional block diagram model in depth, and assigning the data in the conversion ACTi to the direct input element corresponding to the functional model element as the output data of the direct input element;
[0112] Specifically, if the current forward model element obtained by traversal represents an input model element, the input variable and the value of the input variable are added to the transformation ACTi; if the current forward model element obtained by traversal represents a functional model element, all direct input data combinations of the current forward model element are solved according to the type and output of the current forward model element; taking the current forward model element obtained by traversal as the starting point of the next traversal, the functional block diagram model is deeply traversed forward, and all the solved direct input data combinations of the current forward model element are assigned to the direct input element corresponding to the next forward model element as the output data of the direct input element, until all model elements of each functional model element are traversed.
[0113] 50333) Taking each functional model element as the starting point, traverse the functional block diagram model backward in breadth, and assign the data in the state STi to the direct output element of the functional model element as the output data of the direct output element and the input data of the corresponding position.
[0114] Specifically, if the current backward model element obtained by traversal represents an output variable, the output variable and the value of the output variable are added to the state STi; if the current backward model element obtained by traversal represents an input variable, all direct input and direct output data combinations of the current backward model element are solved according to the type and output of the current backward model element; with the current backward model element obtained by traversal as the starting point of the next traversal, the functional block diagram model is traversed backward breadthwise, and all direct input and direct output data combinations of the current backward model element solved are assigned to the direct input model elements and direct output model elements corresponding to the next backward functional model element, until all backward model elements of each functional model element are traversed.
[0115] by Figure 7 For example, AND_1 is solved to obtain the expanded FSM model as follows Fig. 9 After step 5033), the final converted process FSM model is as follows: Fig.10 . Fig.10 for Fig. 9 The corresponding process FSM model; such as Fig.10 , Fig. 9 Among them, Aand1: Set = 0 / Rset = 1, the values assigned are Aand1: analog input variable 1 = 159; Boolean input variable 1 = 0; Boolean input variable 2 = 1; Boolean input variable 3 = 1. Others are similar and will not be repeated here.
[0116] Similarly, we can Figure 7 According to the conversion principle, the model conversions of RS_1, AND_1, GT_1, and OR_1 are performed in sequence according to the depth traversal rule. The FSM model of AND_1 conversion is as follows: Fig.10 As shown, the FSM model obtained by RS_1 conversion is as follows Fig.11 As shown, the FSM model obtained by GT_1 conversion is as follows Fig.12 As shown, the FSM model obtained by OR_1 conversion is as follows Fig.13 As shown. Among them, Fig.11 The process FSM model obtained by transforming the RS_1 model elements; Fig.12 The process FSM model obtained by transforming the GT_1 model elements; Fig.13 The process FSM model obtained by converting the OR_1 model elements.
[0117] 5034) All process FMS models are reorganized to obtain a conversion FSM model.
[0118] In practical applications, all process FMS models are actually integrated into a complete FSM model diagram to obtain the conversion FSM model.
[0119] Specifically, when all process FMS models are reorganized, constraint-based deletion and / or deletion of duplicate transformations can be performed. The constraint-based deletion is as follows: all process finite state machine models are traversed, and the data combination of each transformation in all process finite state machine models is compared with the constraint conditions. If the data combination conflicts with the constraint conditions, all states and transformations at the back end of the transformation export are deleted. For example, Figure 7 As shown, Boolean input variables 1 and 3 are required to be mutually exclusive, and the state Fig.11In Ars42, the Boolean input variable 1 and the Boolean input variable 3 are equal, so Ars42 and Srs42 are deleted. The others are similar and will not be explained one by one here.
[0120] Traverse all the process finite state machine models, if the data combination of the two exit transitions of the same state is exactly the same, then the transition is considered to be repeated, the two transitions and the exit state paths of the two transitions are merged, the second transition and the exit state of the transition are deleted, and the path after the exit state of the second transition is merged into the exit state of the first transition. Figure 10-13 The variable data of the transformations Ars1, Aand1, Agt1, and Aor1 after the state S3 are exactly the same, so Aand1, Agt1, Aor1, Sand1, Sgt1, and Sor1 will be deleted, and the paths after Sand1, Sgt1, and Sor1 will be merged into Srs1. The others are similar and will not be explained one by one here.
[0121] In this embodiment, after steps 5031-5034), the conversion FSM model corresponding to the FBD model can be obtained, and according to the pre-state of the FBD model, the conversion FSM model is associated with the FSM model to obtain the target FSM model. Fig.14 for Figure 6 and Figure 7 The target FSM model obtained after the corresponding model is converted. Fig.14 Reference to relevant definitions in Figure 10-13 shown.
[0122] It should be noted that, in this embodiment, after obtaining the conversion FSM model, an FSM state diagram corresponding to the conversion FSM model can be generated and output to intuitively view the graphics corresponding to the conversion FSM model generated by FBD, which is conducive to checking and verifying the results.
[0123] 504. Based on the target FSM model, a preset traversal algorithm is used to generate a test case for each path.
[0124] In a specific implementation, the preset traversal algorithm is calculated based on the following criteria:
[0125] First, state coverage: Each state in the FSM model must be covered once;
[0126] Second, transition coverage: Each transition in the FSM model must be covered once;
[0127] Third, transition / state coverage criteria: Each transition / state pair in the FSM model must be covered once; a transition / state pair refers to a combination of a transition and the only exit state of the transition.
[0128] The preset traversal algorithms in this embodiment may include the W algorithm, the D algorithm, the UIO algorithm, and the postman algorithm. In this embodiment, the postman algorithm is used as an example only. Fig.15 Flowchart for generating test cases based on the Postman algorithm.
[0129] 5041. Start traversal from the initial state;
[0130] 5042. Obtain the i-th transition of the current state Sin and the transition exit state Soi in sequence;
[0131] 5043. Determine whether there is an exit conversion in the exit state Soi; if so, execute step 5044; if not, execute step 5045;
[0132] 5044. Determine whether the exit state Soi appears repeatedly in the current traversal path; if so, execute step 5045; if not, execute step 5046;
[0133] 5045. Generate a test case for the path between the initial state and Soi, and execute step 5047;
[0134] 5046. Set the exit state Soi as the current state Sin, and return to step 5042;
[0135] 5047. Determine whether the coverage criteria have been met. If so, end. If not, return to step 5041.
[0136] Table 3 Fig.15 Generated test cases.
[0137] Table 3
[0138]
[0139] The test case generation method of this embodiment describes the software requirements based on the FSM model and the FBD model, and converts the FBD model into a complete FSM model, realizing hybrid modeling by integrating the FSM model and the FBD model. It can not only accurately describe the running process status of the software, but also accurately describe the logical relationship between the software input and output, and can describe the functions of the software more comprehensively. At the same time, it not only extracts the data combination of the FBD model, but also extracts the conversion relationship between the data combinations of the FBD model, so that the test cases cover more scenarios and improve the test coverage, but also avoids the state explosion problem of the FBD model conversion to the FSM model, and can automatically generate test cases, which not only avoids human errors but also improves the efficiency of test design.
[0140] The following describes the complete implementation process of the algorithm for converting the FBD model to FSM:
[0141] Fig.16 The flowchart of the algorithm for converting the FBD model into FSM is as follows: Fig.16 As shown, the algorithm for converting the FBD model to the FSM may include the following steps:
[0142] 160. Establish the initial state;
[0143] The previous state of the FBD model must be a state element of an already established FSM model. Get the previous state of the FBD model as the initial state, assuming it is S0, and associate it with the FSM model where the previous state is located.
[0144] 161. Traverse the FBD model;
[0145] Traverse the FBD model. The FBD model has an output as the root node and is a tree structure. Through the depth traversal algorithm, each model element of the FBD model is searched in turn.
[0146] 162. Is it an input variation or an output variation? If so, return to step 161; if not, execute step 163;
[0147] 163. Solve the entry state of the obtained model element;
[0148] 164. Convert the obtained model elements into an unfolded FSM model;
[0149] 165. Solve the data combination of input variables and output variables of the transition / state of the expanded FSM model;
[0150] 166. Are the transformation / state solutions of all unfolded FSM models completed? If so, execute step 167; if not, return to step 165;
[0151] 167. Are all function blocks in the FBD model decomposed? If so, execute step 168; if not, return to step 161;
[0152] 168. Delete and merge repeated paths from the final result of test decomposition to obtain a conversion FSM model;
[0153] 169. Generate the FSM state diagram corresponding to the FSM model.
[0154] Fig.17 for Fig.16 The flowchart of step 165 in FIG. Fig.17 As shown, the implementation steps of step 165 may specifically include the following steps:
[0155] 1651. Select a conversion state pair ACTi / STi from the conversion state pair set FSMac;
[0156] 1652. Starting from the model element FA, the FBD model is deeply traversed forward, and the data combination of ACTi is passed to the output of the direct input model of the model element FA;
[0157] 1653. Whether the current forward model element represents an input model element, if so, execute step 1654, if not, execute step 1655;
[0158] 1654. Add the input variable and the value of the input variable to the transformation ACTi, and execute step 1657;
[0159] 1655. Solve the direct input data combination of the current forward model element according to the algorithm according to the type and expected output of the current forward model element;
[0160] 1656. Traverse the FBD model from the current forward model element in depth, and pass the expected input of the current forward model element to the next forward model element as the output data of the direct input element, and return to step 1653;
[0161] 1657. Is the forward traversal completed? If so, execute step 1658; if not, return to step 1652;
[0162] 1658. Starting from the model element FA, the FBD model is traversed backwards in depth to pass the data combination of STi to the input of the direct output model of FA;
[0163] 1659. Whether the current backward model element is an output model element, if so, execute step 16510, if not, execute step 16511;
[0164] 16510. Add the output variable and value to the state STi, and execute step 165913;
[0165] 16511. According to the type and expected output of the current backward model element, solve the direct input and direct output data combination of the current backward model element according to the algorithm;
[0166] 16512. Traverse the FBD model backwards from the current backward model element in depth, and pass the expected output of the current backward model element to the direct input element corresponding to the next backward functional model element as a direct output element, and return to step 1659;
[0167] 16513. Is the backward traversal completed? If so, execute step 165914; if not, return to step 1658;
[0168] 16514. Check whether all conversion state pairs in the set FSMac are solved. If so, end. If not, return to step 1651.
[0169] It should be noted that the method of the embodiment of the present invention can be performed by a single device, such as a computer or a server. The method of this embodiment can also be applied to a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present invention, and the multiple devices will interact with each other to complete the method.
[0170] Embodiment 4
[0171] In order to solve the above technical problems existing in the prior art, an embodiment of the present invention further provides a test case generating device.
[0172] Fig.18 FIG. 1 is a schematic diagram of a structure of an embodiment of a test case generating device of the present invention. Fig.18 As shown, the test case generating device of this embodiment includes an FSM modeling module 181 , an FBD modeling module 182 , an FBD model conversion FSM model module 183 , and an automatic test case generating module 184 .
[0173] The FSM modeling module 181 is used to establish a finite state machine model according to the states of all software operations in the software requirement specification and the trigger conditions for the transition between the states of different software operations;
[0174] The FBD modeling module 182 is used to establish a function block diagram model based on a function block diagram-like language according to the input and output, the logical relationship between the input and output, and the constraint relationship between all inputs in the software requirement specification; and according to the effective state of the function block diagram model, select a software running state in the finite state machine model as the pre-state of the function block diagram model;
[0175] The FBD model conversion FSM model module 183 is used to convert the function block diagram model into a conversion finite state machine model that describes the state change process of the software operation according to a preset conversion rule, and associate the conversion finite state machine model with the finite state machine model according to the pre-state of the function block diagram model to obtain a target finite state machine model;
[0176] The automatic test case generation module 184 is used to generate a test case for each path based on the target finite state machine model and using a preset traversal algorithm.
[0177] In a specific implementation process, the test case generation device of this embodiment may also include a process FSM model 185, which is used to generate a finite state machine state diagram corresponding to the transition finite state machine model; and output the finite state machine state diagram.
[0178] Embodiment 3
[0179] In order to solve the above technical problems existing in the prior art, an embodiment of the present invention further provides a test case generating device.
[0180] The test case generation device includes a memory and a processor; the memory stores a computer program, and when the computer program is executed by the processor, the steps of the test case generation method described in the above embodiment are implemented.
[0181] It should be noted that the devices in the above embodiments are used to implement the corresponding methods in the above embodiments and have the beneficial effects of the corresponding method embodiments, which will not be described in detail here.
[0182] Embodiment 4
[0183] In order to solve the above technical problems existing in the prior art, an embodiment of the present invention provides a storage medium.
[0184] The storage medium provided by the embodiment of the present invention stores a computer program thereon, and when the computer program is executed by a processor, the steps of the test case generation method of the above embodiment are implemented.
[0185] It can be understood that the same or similar parts of the above embodiments can be referenced to each other, and the contents not described in detail in some embodiments can refer to the same or similar contents in other embodiments.
[0186] It should be noted that, in the description of the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, the meaning of "plurality" refers to at least two.
[0187] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.
[0188] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0189] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0190] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module 32, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0191] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.
[0192] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0193] Although the embodiments disclosed in the present invention are as above, the contents described are only embodiments adopted for facilitating the understanding of the present invention and are not intended to limit the present invention. Any technician in the technical field to which the present invention belongs can make any modifications and changes in the form and details of the implementation without departing from the spirit and scope disclosed in the present invention, but the protection scope of the present invention shall still be subject to the scope defined in the attached claims.
Claims
1. A test case generation method, characterized in that: include: Establish a finite state machine model based on the states of all software operations in the software requirements specification and the trigger conditions for transitions between different software operation states; According to the input and output in the software requirement specification, the logical relationship between input and output, and the constraint relationship between all inputs, a function block diagram model based on a function block diagram-like language is established; According to the effective state of the function block diagram model, a software running state is selected in the finite state machine model as the pre-state of the function block diagram model; According to a preset conversion rule, the function block diagram model is converted into a conversion finite state machine model that describes the state change process of the software running, and according to the pre-state of the function block diagram model, the conversion finite state machine model is associated with the finite state machine model to obtain a target finite state machine model; Based on the target finite state machine model, a preset traversal algorithm is used to generate a test case for each path; The function block diagram model includes input model elements, output model elements and function model elements; the function model elements are used to describe the logical relationship between the input model elements and the output model elements; According to the preset conversion rules, the function block diagram model is converted into a conversion finite state machine model that describes the state change process of the software operation, including: Taking the pre-state of the function block diagram model as the initial state, solving a group of function model elements in the function block diagram model that have a connection relationship with each output model element to obtain the entry state of the group of function model elements; wherein the connection relationship includes a direct connection and / or an indirect connection; According to the preset conversion rules, each functional model element is converted into a corresponding expanded finite state machine model; For each transition and state of each of the unfolded finite state machine models, solving a data combination of input variables and output variables that satisfies expectations to obtain a corresponding process finite state machine model; All process finite state machine models are reorganized to obtain the conversion finite state machine model.
2. The test case generation method according to claim 1, characterized in that: Solving a group of functional model elements in the functional block diagram model that are connected to each output model element to obtain the entry state of the group of functional model elements includes: If the group of functional model elements includes a functional model element representing a latch, the entry state of the functional model element serially connected to the SET port of the latch is sequentially migrated to the first state based on the initial state; If the group of functional model elements includes a functional model element representing a latch, the entry state of the functional model element serially connected to the Reset port of the latch is sequentially migrated to a second state based on the initial state; If the group of functional model elements does not include a latch, the entry state of the group of functional model elements maintains the initial state.
3. The test case generation method according to claim 1, characterized in that: The preset conversion rules include: Each direct input interface of each functional model element covers at least two situations: true and false. If the input interface is a non-Boolean value, it covers at least two different values. The direct output interface of each functional model element covers at least two situations: true and false. If the output interface is a non-Boolean value, it covers at least two different values. Each direct input of each functional model element triggers at least a change in a direct output of the functional block diagram model while other direct inputs remain unchanged.
4. The test case generation method according to claim 1, characterized in that: For each transition and state of each of the unfolded finite state machine models, solving a data combination of input variables and output variables that meets the expectations includes: A transition state pair ACTi / STi is selected from the transition state pair set FSMa / c; wherein each of the unfolded finite state machine models contains x transitions, the i-th transition is defined as ACTi, and the only exit state of transition ACTi is STi; ACTi and STi constitute a pair of transition state combinations ACTi / STi; the set of all transition state combinations ACTi / STi constitutes the transition state pair set FSMa / c of each of the unfolded finite state machine models; Taking each functional model element as a starting point, traverse the functional block diagram model in depth, and assign the data in the conversion ACTi to the direct input element corresponding to the functional model element as the output data of the direct input element; The function block diagram model is traversed backwards with each function model element as the starting point, and the data in the state STi is assigned to the direct output element of the function model element as the output data of the direct output element and the input data of the corresponding position.
5. The test case generation method according to claim 4, characterized in that: Taking each functional model element as a starting point, the functional block diagram model is deeply traversed forward, and the data in the conversion ACTi is assigned to the direct input element corresponding to the functional model element as the output data of the direct input element, including: If the current forward model element obtained by traversal represents an input model element, the input variable and the value of the input variable are added to the transformation ACTi; If the current forward model element obtained through traversal represents a functional model element, then all direct input data combinations of the current forward model element are solved according to the type and output of the current forward model element; Taking the current forward model element obtained by traversal as the starting point of the next traversal, the functional block diagram model is traversed forward in depth, and all the direct input data combinations of the solved current forward model element are assigned to the direct input elements corresponding to the next forward model element as the output data of the direct input elements, until all model elements of each functional model element are traversed.
6. The test case generation method according to claim 4, characterized in that: Taking each functional model element as a starting point, the functional block diagram model is traversed backwards in breadth, and the data in the state STi is assigned to the direct output element of the functional model element as the output data of the direct output element and the input data of the corresponding position, including: If the current backward model element obtained by traversal represents an output variable, the output variable and the value of the output variable are added to the state STi; If the current backward model element obtained through traversal represents an input variable, then all direct input and direct output data combinations of the current backward model element are solved according to the type and output of the current backward model element; Taking the current backward model element obtained by traversal as the starting point of the next traversal, the functional block diagram model is traversed backward breadthwise, and all direct input and direct output data combinations of the current backward model element are assigned to the direct input elements corresponding to the next backward functional model element as direct output elements, until all backward model elements of each functional model element are traversed.
7. The test case generation method according to claim 1, characterized in that: Restructuring of all process finite state machine models, including: Traversing all the obtained process finite state machine models, comparing the data combination of each conversion in all the process finite state machine models with the constraint conditions, and if the data combination conflicts with the constraint conditions, deleting all states and conversions at the back end of the conversion exit; and / or, All the process finite state machine models obtained by traversing are considered to be repeated if the data combination of the two exit transitions of the same state is exactly the same. The two transitions and the exit state paths of the two transitions are merged, the second transition and the exit state of the transition are deleted, and the path after the exit state of the second transition is merged into the exit state of the first transition.
8. The test case generation method according to claim 1, characterized in that: After all process finite state machine models are reorganized to obtain the conversion finite state machine model, the method further includes: Generate a finite state machine state diagram corresponding to the conversion finite state machine model; Output the finite state machine state diagram.
9. A test case generating device, characterized in that: including memory and processor; The memory stores a computer program, which, when executed by the processor, implements the steps of the test case generation method according to any one of claims 1 to 8.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the controller, the steps of the test case generating method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Behavioral model-based software security test case generation method
CN101968769A
Method for automatically generating testing case on basis of function block diagram testing module
CN104991863A