Test case generation method and device, electronic equipment and storage medium
By analyzing the type of test objects, selecting the appropriate test model and performing coverage test optimization, the problem of difficulty in quickly generating high-quality test cases in the existing technology is solved, and more efficient and accurate test case generation is achieved.
Patent Information
- Application Number
- CN202411656186.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-03-11
AI Technical Summary
It is difficult for the prior art to quickly generate high-quality test cases, especially in different situations of test objects and test requirements. A single deep learning model cannot meet the requirements, and the quality of the generated test cases cannot be guaranteed.
By receiving test case requests from the user terminal, obtaining test information of the software to be tested, analyzing the test objects to determine the test type, selecting a suitable test model to generate test cases based on the mapping relationship between the predetermined test type and the test model, and optimizing the generated test cases through coverage test.
Ensure that the generated test cases match the test objects, improve the quality and coverage of test cases, and improve the efficiency and accuracy of automatically generating test cases.
Smart Images

Figure CN119597653A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of test case generation and financial technology, and to a test case generation method, device, electronic device and storage medium. Background Art
[0002] As we all know, financial software products must be tested for various functions or interfaces before they are delivered, such as account management, transaction processing, transfer, loan application, and investment operations. As long as there is testing, test cases are needed as the basis of the testing process. Test cases are an important part of software testing and are the foundation and core of software testing.
[0003] In the prior art, one method is that testers generally obtain data and then manually generate a large number of test cases based on the obtained data. Another method is to directly use deep learning models to generate test cases, but different test objects and test requirements often require different test methods or different test models, and a single deep learning model cannot meet the requirements. Even if the test cases generated by the deep learning model are used, the quality cannot be guaranteed.
[0004] Therefore, how to ensure that high-quality test cases can be generated quickly has become a technical problem that needs to be solved urgently. Summary of the invention
[0005] In view of the above, it is necessary to provide a test case generation method to solve the problem of being able to quickly generate high-quality test cases in the process of generating test cases.
[0006] To achieve the above object, the present invention provides a test case generation method, characterized in that the method comprises:
[0007] After receiving a test case request for generating the software to be tested sent by the user terminal, obtaining test information corresponding to the software to be tested, the test information including a test object and test parameters;
[0008] Analyzing the test type of the software to be tested according to the test object;
[0009] Determine the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested;
[0010] Generate a first test case according to the test model and the test parameters;
[0011] A coverage test is performed on the first test case to obtain a second test case, and the second test case is fed back to the user terminal as a target test case.
[0012] In addition, to achieve the above object, the present invention also provides a test case generation device, characterized in that the device comprises:
[0013] The test information acquisition module is used to acquire the test information corresponding to the software to be tested after receiving the test case request for generating the software to be tested sent by the user terminal, wherein the test information includes the test object and the test parameters;
[0014] Test type analysis module: used for analyzing the test type of the software to be tested according to the test object;
[0015] Test model determination module: used to determine the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested;
[0016] A test case generation module: used to generate a first test case according to the test model and the test parameters;
[0017] Test case return module: used to perform coverage test on the first test case to obtain a second test case, and feed back the second test case as a target test case to the user terminal.
[0018] In addition, to achieve the above object, the present invention further provides an electronic device, the electronic device comprising:
[0019] a memory storing at least one computer program; and
[0020] The processor executes the program stored in the memory to implement the test case generation method described above.
[0021] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored, and the at least one computer program is executed by a processor in an electronic device to implement the test case generation method described above.
[0022] In the above technical solution provided by the present invention, by accepting a request to generate a test case, the test information corresponding to the software to be tested is obtained to ensure the integrity and accuracy of the test information; the test type of the software to be tested is analyzed according to the test object in the test information to ensure that the test case generated subsequently matches the test object; then the test model corresponding to the software to be tested is determined according to the test type, and a suitable test model is selected to ensure the generation of high-quality test cases; then a first test case is generated according to the test model and test parameters, and a coverage test is performed on the first test case to obtain a second test case, and the second test case is fed back to the user, and the test case is optimized through coverage testing to ensure that the test case finally generated has a higher coverage rate. The present invention selects the corresponding test model according to the test type of the test object, and performs coverage detection on the test case generated by the selected test model to ensure the coverage rate of the test case, thereby improving the efficiency of automatically generating test cases. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a schematic diagram of an application environment of a test case generation method in one embodiment of the present invention;
[0024] Figure 2 A flow chart of a test case generation method provided by an embodiment of the present invention;
[0025] Figure 3 A schematic diagram of the structure of a test case generation device provided by an embodiment of the present invention;
[0026] Figure 4 is a schematic diagram of a structure of a computer device in one embodiment of the present invention;
[0027] Figure 5 It is another structural schematic diagram of a computer device in one embodiment of the present invention.
[0028] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0030] It should be noted that the descriptions of "first", "second", etc. in the present invention are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0031] The test case generation method provided by the embodiment of the present invention can be applied in Figure 1 In an application environment, the client communicates with the server through a network. After receiving a request for generating a test case for the software to be tested sent by a user terminal, the server obtains test information corresponding to the software to be tested, wherein the test information includes a test object and a test parameter; analyzes the test type of the software to be tested according to the test object; determines the corresponding test model according to a mapping relationship between a predetermined test type and a test model, and the test type of the software to be tested; generates a first test case according to the test model and the test parameters; performs a coverage test on the first test case to obtain a second test case, and feeds the second test case back to the user terminal as a target test case. In the present invention, after receiving a test case request for generating software to be tested, the test information corresponding to the software to be tested is obtained to ensure the integrity and accuracy of the test information and provide a basis for subsequent steps; the test type of the software to be tested is analyzed according to the test object in the test information to ensure that the test case generated subsequently matches the test object; then the test model corresponding to the software to be tested is determined according to the mapping relationship between the test type and the test model, and a suitable test model is selected according to the test type to improve the efficiency and accuracy of generating test cases; then a first test case is generated according to the test model and the obtained test parameters, and a basis is provided for subsequent coverage testing by generating preliminary test cases; finally, a coverage test is performed on the first test case to obtain a second test case, and the second test case is fed back to the user, and the test case is optimized through coverage testing to ensure that the test case finally generated has a higher coverage. The present invention selects a corresponding test model according to the test type of the test object, and performs coverage detection on the test case generated by the selected test model to ensure the coverage of the test case, thereby improving the efficiency and accuracy of automatically generating test cases. Among them, the client can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server side can be implemented by an independent server or a server cluster composed of multiple servers. The present invention is described in detail below through specific embodiments.
[0032] Reference Figure 2 FIG. 1 is a flow chart of a test case generation method provided by an embodiment of the present invention. In the embodiment of the present invention, the test case generation method includes the following steps S1-S5:
[0033] S1. After receiving a test case request for generating a software to be tested sent by a user terminal, obtaining test information corresponding to the software to be tested, wherein the test information includes a test object and test parameters.
[0034] In one embodiment, after receiving a request for generating a test case for the software to be tested sent by a user terminal, the request is parsed to obtain test information corresponding to the software to be tested.
[0035] In one embodiment, the obtaining of the test information corresponding to the software to be tested includes:
[0036] Obtaining the test requirement document uploaded by the user terminal;
[0037] Using a preset keyword recognition algorithm to perform keyword recognition on the test requirement document to obtain document keywords;
[0038] A test object and a test parameter are extracted from the document keywords, and the test object and the test parameter are used as the test information.
[0039] In this embodiment, in order to simplify user operations, the client that sends the test case request can also support users to upload the requirements document of the software to be tested. For example, the client may include a requirements document upload control, and the user can trigger the requirements document upload operation through the requirements document upload control and upload the requirements document of the software to be tested. In this case, in a specific implementation, the requirements document of the software to be tested can be obtained, and then, keyword recognition is performed on the requirements document to obtain the test object and test parameters of the software to be tested.
[0040] When parsing the requirement document, in a specific implementation, keyword recognition can be performed on the requirement document, and the test requirements of the software to be tested can be obtained through the recognized keywords. The embodiment of the present application does not specifically limit the keywords, and the keywords can be determined according to actual conditions. Parsing the requirement document can also be completed by a large language model. In other words, the requirement document can be input into a large language model to obtain the test information of the software to be tested.
[0041] The embodiments of the present application do not specifically limit the software to be tested. The software to be tested may be software corresponding to system software, or software corresponding to application software, software corresponding to embedded software, software corresponding to information security software, software corresponding to industrial software, or software corresponding to other software.
[0042] S2. Analyze the test type of the software to be tested according to the test object.
[0043] In one embodiment, analyzing the test type of the software to be tested according to the test object includes:
[0044] Obtaining a test object from the test information;
[0045] Determine the type of the test object, and if the test object is a process type, determine that the test type of the software to be tested is a first type;
[0046] If the test object is a numerical type, the test object is analyzed to determine whether it is a discrete numerical type or a continuous numerical type. If the test object is a discrete numerical type, the test type of the software to be tested is determined to be the second type. If the test object is a continuous numerical type, the test type of the software to be tested is determined to be the third type.
[0047] If the test object includes both the numerical class and the process class, the test type of the software to be tested is determined to be the fourth type.
[0048] In this embodiment, the test objects are divided into process class, numerical class and multi-factor combination class (including numerical class and process at the same time), wherein the numerical class is further divided into discrete numerical class and continuous numerical class. The test object of the process class usually refers to a system or function that needs to be executed according to a specific process or step, and is characterized by including multiple steps, state transitions and user interactions. For example, the user registration process includes the following steps: the user visits the registration page; the user fills in the user name, password, email and other information; the user submits the registration form; the system verifies the validity of the input information; the system sends a confirmation email; the user clicks the confirmation link to complete the registration. The test object of the discrete numerical class refers to the test object being a specific value or a limited number of values, that is, the value of the test object of the discrete numerical class can be enumerated and counted, such as the number of product purchases, the number of users, etc. The test object of the continuous numerical class refers to the test object that can take any value within a specific interval, such as annualized rate of return, stock price and bond face value. The test object of the multi-factor combination class refers to the test involving multiple variables (factors) and each variable has multiple levels (values). For example, in a financial loan system, the variables are loan type, loan amount and loan term, and each variable has multiple values.
[0049] S3. Determine a corresponding test model according to a predetermined mapping relationship between the test type and the test model and the test type of the software to be tested.
[0050] In one embodiment, the determining the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested includes:
[0051] If the test type of the software to be tested is the first type, obtaining a first model corresponding to the first type as a test model corresponding to the software to be tested;
[0052] If the test type of the software to be tested is the second type, obtaining a second model corresponding to the second type as a test model corresponding to the software to be tested;
[0053] If the test type of the software to be tested is the third type, obtaining a third model corresponding to the third type as a test model corresponding to the software to be tested;
[0054] If the test type of the software to be tested is the fourth type, a fourth model corresponding to the fourth type is obtained as a test model corresponding to the software to be tested.
[0055] In this embodiment, when the test type of the software to be tested is the first type, the first model is selected according to the test model corresponding to the software to be tested. The first model is a finite state machine model, which is a mathematical model that can cover all nodes and all states. The finite state machine model can well generate test cases for the software to be tested whose test object is the approval class. The operating principle of the finite state machine model is to process external events through state transfer and action execution, thereby realizing the behavior control of the software to be tested.
[0056] Specifically, the step of generating test cases from the finite state machine model includes:
[0057] 1. Define states and events.
[0058] First, we need to clarify the states and events of the system. The state represents the condition of the system at a certain moment, and the event is the action that triggers the state transition.
[0059] 2. Draw a state diagram.
[0060] Use state diagrams to visualize the states and transitions of a system. State diagrams can help you clearly see the various states of a system and the transition relationships between them.
[0061] 3. Generate test cases.
[0062] Generate test cases based on the state diagram to ensure that each state and transition is tested. You can use the following methods to generate test cases:
[0063] 3.1 Traverse all states and transitions.
[0064] Make sure that each state and each transition is tested at least once. The state graph can be traversed by depth-first search (DFS) or breadth-first search (BFS).
[0065] 3.2 Path coverage.
[0066] Generate test cases that cover all possible paths. This can be achieved by generating all paths from the initial state to the final state.
[0067] 3.3 Boundary value testing.
[0068] For each state transition, test the boundary values. For example, if the condition for a state transition is that the value of a variable is within a certain range, test the boundary values of the range.
[0069] 3.4 Abnormal path test.
[0070] In addition to normal paths, abnormal paths should also be tested, i.e., state transitions that may lead to system errors.
[0071] In this embodiment, when the test type of the software to be tested is the second type, the second model is selected as the test model corresponding to the software to be tested. The second model is a decision tree model, which can effectively process multi-conditional logic branches and help generate test cases that fully cover various condition combinations. Therefore, for the software to be tested whose test object is a discrete numerical class, this embodiment selects a decision tree model as the test model of the software to be tested.
[0072] Specifically, the step of generating a test case using the decision tree model includes:
[0073] 1. Define input factors and output results
[0074] First, we need to identify the input factors and output results of the system. Input factors are factors that affect the behavior of the system, and output results are the results of the system under a specific input combination.
[0075] Example:
[0076] Input factors:
[0077] Age: User age (discrete values: under 18, 18-65, over 65)
[0078] IsStudent: Is the student (Boolean value: True, False)
[0079] HasDiscount: Is there a discount (Boolean: True, False)
[0080] Output:
[0081] DiscountRate: discount rate (0.0, 0.1, 0.2, 0.3)
[0082] 2. Build a decision tree
[0083] Use decision tree algorithms (such as ID3, C4.5, CART, etc.) to build a decision tree model. The decision tree predicts the value of the target variable through a series of conditional judgments (decision nodes).
[0084] 2.1 Select the root node
[0085] Select the feature with the largest information gain or the smallest Gini impurity as the root node.
[0086] 2.2 Recursive Splitting
[0087] The dataset is divided into subsets according to the selected features, and child nodes are selected recursively until the stopping condition is met (such as all samples in the subset belong to the same category or the number of samples is less than a preset threshold).
[0088] 2.3 Generate leaf nodes
[0089] When the stopping condition is met, a leaf node is generated, which represents the final prediction result.
[0090] 3. Extract decision paths
[0091] Extract all decision paths from the constructed decision tree. Each path from the root node to the leaf node represents a set of input conditions and corresponding output results.
[0092] 4. Generate test cases
[0093] Generate test cases based on the extracted decision paths. Each path corresponds to a test case to ensure that every condition combination is tested.
[0094] In this embodiment, when the test type of the software to be tested is the third type, the third model is selected as the test model corresponding to the software to be tested. The third model is an equivalence class analysis table model. The operating principle of the equivalence class analysis table model is to divide all possible input data into several equivalence classes, and then select a small number of representative data from each equivalence class as test cases. For the software to be tested whose test object is a continuous numerical class, the numerical value of the test object cannot be listed and counted. Therefore, this embodiment selects the equivalence class analysis table as the test model of the software to be tested, which can ensure that each input interval is tested, avoid missing key input values, and thus improve the efficiency and accuracy of generating test cases.
[0095] Specifically, the step of generating test cases from the equivalence class analysis table model includes:
[0096] 1. Define input factors and output results
[0097] First, we need to identify the input factors and output results of the system. Input factors are factors that affect the behavior of the system, and output results are the results of the system under a specific input combination.
[0098] Example:
[0099] Input factors:
[0100] Age: User age (continuous value, range: 0 to 100)
[0101] IsStudent: Is the student (Boolean value: True, False)
[0102] HasDiscount: Is there a discount (Boolean: True, False)
[0103] Output:
[0104] DiscountRate: discount rate (0.0, 0.1, 0.2, 0.3)
[0105] 2. Divide into equivalence classes
[0106] According to the characteristics of input factors, the input values are divided into several equivalence classes. The input values in each equivalence class behave equivalently in the system.
[0107] 2.1 Determine valid and invalid equivalence classes
[0108] Valid equivalence class: input values that meet the system requirements.
[0109] Invalid equivalence class: Input value that does not meet system requirements.
[0110] Example equivalence class partitioning:
[0111] Age:
[0112] Valid equivalence classes: [0,18), [18,65), [65,100]
[0113] Invalid equivalence class: [-1,0), (100,101]
[0114] IsStudent:
[0115] Valid equivalence classes: True, False
[0116] HasDiscount:
[0117] Valid equivalence classes: True, False
[0118] 3. Select representative test cases
[0119] Select one or more representative values from each equivalence class as test cases. At the same time, consider boundary values and outliers.
[0120] Example test case:
[0121] Normal value:
[0122] Age:10,25,70
[0123] IsStudent:True,False
[0124] HasDiscount:True,False
[0125] Boundary values:
[0126] Age:0,18,65,100
[0127] Outliers:
[0128] Age:-1,101
[0129] 4. Generate test cases
[0130] Generate test cases based on selected representative values and document the expected output results.
[0131] In this embodiment, when the test type of the software to be tested is the fourth type, the fourth model is selected as the test model corresponding to the software to be tested. The fourth model is an orthogonal experiment table model, which is a model that designs multi-factor experiments through an orthogonal array, and can obtain more comprehensive test coverage in a smaller number of experiments. The test type is the fourth type, that is, the test object is composed of multiple factors, the applicable scenarios are complex, and the conventional model processing efficiency and accuracy are low. Therefore, this embodiment uses the orthogonal experiment table model as the test model of the software to be tested.
[0132] Specifically, the step of generating test cases from the orthogonal experiment table model includes:
[0133] 1. Define input factors and levels
[0134] First, clarify the input factors of the system and the possible values (levels) of each factor.
[0135] Example:
[0136] Input factors:
[0137] FactorA: Temperature (continuous value, value: 20℃, 30℃, 40℃)
[0138] Factor B: Pressure (continuous value, value: 100kPa, 200kPa, 300kPa)
[0139] Factor C: Humidity (continuous value, value: 40%, 60%, 80%)
[0140] 2. Choose an orthogonal array
[0141] Depending on the number of input factors and levels, choose an appropriate orthogonal array. An orthogonal array is a special kind of matrix in which each level of each factor is evenly distributed in each column.
[0142] Common orthogonal arrays are:
[0143] L4: Applicable to 2 factors, each with 2 levels
[0144] L8: for 2 factors, each with 4 levels, or 3 factors, each with 2 levels
[0145] L9: Applicable to 3 factors, each with 3 levels
[0146] L16: For 4 factors, each with 2 levels, or 2 factors, each with 4 levels
[0147] Example: Choose the L9 orthogonal array because it can handle 3 factors, each with 3 levels (L4, L8, L9, L16 are identifiers of orthogonal arrays, the number after each identifier indicates the number of experiments that the orthogonal array can handle, and the letter "L" indicates that this is an orthogonal array).
[0148] 3. Generate test cases
[0149] Generate test cases based on the orthogonal array and record the expected output values.
[0150] This embodiment selects a corresponding test model for the test type of the software to be tested through a predetermined mapping relationship between the test type and the test model, ensuring that the generated test cases can fully cover various situations of the test object, thereby improving the efficiency of generating test cases.
[0151] S4. Generate a first test case according to the test model and the test parameters.
[0152] In one embodiment, generating a first test case according to the test model and the test parameters includes:
[0153] Obtaining input parameter values and expected parameter values in the test parameters;
[0154] Construct an initial test case according to the input parameter value, execute the initial test case, and obtain an output parameter value;
[0155] Determining whether the output parameter value is included in the expected parameter value;
[0156] If the output parameter value is not included in the expected parameter value, the initial test case is judged to be unqualified;
[0157] If the output parameter value is included in the expected parameter value, the initial test case is used as the first test case.
[0158] In this embodiment, in one embodiment, the input parameter value refers to the input data set for executing the test case. The expected parameter value refers to the output parameter value that should be obtained after the input parameter value is input into the test case. The expected parameter value is usually a numerical range. When the output parameter value is within the numerical range of the expected parameter value, it means that the test case is qualified. If the output parameter value is not within the numerical range of the expected parameter value, the test case is judged to be unqualified, and the initial test case is reconstructed until the output parameter value obtained is within the numerical range of the expected parameter value.
[0159] This embodiment generates a preliminary first test case through a determined test model and acquired test parameters to facilitate subsequent coverage testing.
[0160] S5. Perform a coverage test on the first test case to obtain a second test case, and feed the second test case back to the user terminal as a target test case.
[0161] In one embodiment, performing coverage testing on the first test case to obtain a second test case includes:
[0162] Execute the first test case using a preset test framework to obtain a test result;
[0163] Calculating the coverage value of the test result using a preset coverage tool, and comparing the coverage value with a preset coverage threshold;
[0164] If the coverage value is greater than or equal to the coverage threshold, taking the initial test case as the second test case;
[0165] If the coverage value is less than the coverage threshold, the first test case is modified and the coverage value of the modified first test case is recalculated until the calculated coverage value is greater than or equal to the coverage threshold, and the test case corresponding to the coverage value greater than or equal to the coverage threshold is used as the second test case.
[0166] In this embodiment, the modification of the first test case includes: modifying the title and description, updating the preconditions, adjusting the test steps or updating the expected results, etc. The preset test framework is used to execute the first test case, obtain the test results after the execution is completed, and then use the coverage tool to analyze the test report to obtain the coverage report results, and calculate the coverage value corresponding to the first test case according to the coverage report results. The coverage report results usually include the following information: the number of executed code lines and the total number of lines, the coverage of branches and conditions, the uncovered code area and the number of related lines.
[0167] The calculation of the coverage value includes statement coverage, branch coverage, path coverage and condition coverage.
[0168] The statement coverage is calculated by calculating the ratio of the number of code lines covered by the test cases to the total number of code lines.
[0169] Statement coverage = (total number of code lines / number of executed code lines) × 100%.
[0170] The branch coverage is calculated by calculating the ratio of the number of conditional branches covered by the test case to the total number of conditional branches.
[0171] Branch coverage = (total number of conditional branches / number of covered conditional branches) × 100%.
[0172] The path coverage is calculated by calculating the ratio of the number of code paths covered by the test cases to the total number of paths.
[0173] Path coverage = (total number of code paths / number of covered code paths) × 100%.
[0174] The condition coverage is the ratio of the number of conditional expression results (true / false) covered by the calculated test cases to the total number of conditional expression results.
[0175] Condition coverage rate = (total number of conditional expression results / number of covered conditional expression results) × 100%.
[0176] This embodiment uses a preset test framework to execute a first test case to obtain a test result, calculates the coverage value of the test result, and compares the coverage value with a preset coverage threshold. The first test case is modified according to the comparison result to ensure that the coverage value of the test case is greater than the preset coverage threshold, thereby obtaining a second test case with better effect. By performing a coverage test on the first test case, the test case is optimized to obtain a second test case, ensuring that the test case finally generated has a higher coverage rate.
[0177] In one embodiment, after feeding back the second test case as a target test case to the user terminal, the method includes:
[0178] Determine whether a test case similar to the target test case is stored in a preset database;
[0179] If a test case similar to the target test case is stored in the database, the target test case replaces the similar test case and stores it in the database;
[0180] If the database does not store a test case similar to the target test case, the target test case is stored in the database.
[0181] In this embodiment, after the target test case is fed back to the user terminal, the target test case will be stored in a preset database, which can be a SQL Server database, an Oracle database or a MySQL database, and which database can be selected according to actual needs or application environment. The SQL Server database is a relational database management system that is widely used to store and manage test cases. It provides powerful data storage and query functions, and is suitable for scenarios where a large number of test cases need to be efficiently managed and queried. The Oracle database is also a commonly used relational database for storing and managing test cases. It has a high degree of reliability and security, and is suitable for test case storage requirements with high data security requirements. The MySQL database is an open source relational database management system, which is also widely used to store test cases due to its open source and cost-effectiveness. It supports a large number of concurrent connections and is suitable for test environments that need to handle a large number of user accesses.
[0182] When storing the target test case in the preset database, it is necessary to query whether there is a test case similar to the target test case stored in the preset database. If yes, it means that the target test case is an updated version of the similar test case in the preset database. Therefore, the target test case is stored in the database instead of the similar test case. If no, the target test case is directly stored in the database.
[0183] This embodiment stores the generated target test cases in a preset database, which can easily add, modify and delete cases, thereby improving the scalability and maintainability of test cases, and allowing the test process to be effectively tracked and managed, while also facilitating the reuse of test cases and knowledge transfer.
[0184] In the above technical solution provided by the present embodiment, by accepting a request to generate a test case, the test information corresponding to the software to be tested is obtained to ensure the integrity and accuracy of the test information; the test type of the software to be tested is analyzed according to the test object in the test information to ensure that the test case generated subsequently matches the test object; then the test model corresponding to the software to be tested is determined according to the test type, and a suitable test model is selected to ensure the generation of high-quality test cases; then a first test case is generated according to the test model and test parameters, and a coverage test is performed on the first test case to obtain a second test case, the second test case is fed back to the user, and the test case is optimized through coverage testing to ensure that the test case finally generated has a higher coverage rate. The present invention selects the corresponding test model according to the test type of the test object, and performs coverage detection on the test case generated by the selected test model to ensure the coverage rate of the test case, thereby improving the efficiency of automatically generating test cases.
[0185] like Figure 3 FIG. 1 is a schematic diagram of the structure of a test case generating device provided by an embodiment of the present invention.
[0186] The test case generation device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the test case generation device can include a test information acquisition module 101, a test type analysis module 102, a test model determination module 103, a test case generation module 104, and a test case return module 105. The module of the present invention can also be referred to as a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, and is stored in the memory of the electronic device.
[0187] In this embodiment, the functions of each module / unit are as follows:
[0188] The test information acquisition module 101 is used to acquire the test information corresponding to the software to be tested after receiving a test case request for generating the software to be tested sent by the user terminal, wherein the test information includes a test object and a test parameter;
[0189] Test type analysis module 102: used for analyzing the test type of the software to be tested according to the test object;
[0190] The test model determination module 103 is used to determine the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested;
[0191] Test case generation module 104: used to generate a first test case according to the test model and the test parameters;
[0192] The test case returning module 105 is used to perform coverage testing on the first test case to obtain a second test case, and feed back the second test case as a target test case to the user terminal.
[0193] In one embodiment, when executing the acquisition of the test information corresponding to the software to be tested, the test information acquisition module 101 is used to:
[0194] Obtaining the test requirement document uploaded by the user terminal;
[0195] Using a preset keyword recognition algorithm to perform keyword recognition on the test requirement document to obtain document keywords;
[0196] A test object and a test parameter are extracted from the document keywords, and the test object and the test parameter are used as the test information.
[0197] In one embodiment, when analyzing the test type of the software to be tested according to the test object, the test type analysis module 102 is used to:
[0198] Obtaining a test object from the test information;
[0199] Determine the type of the test object, and if the test object is a process type, determine that the test type of the software to be tested is a first type;
[0200] If the test object is a numerical type, the test object is analyzed to determine whether it is a discrete numerical type or a continuous numerical type. If the test object is a discrete numerical type, the test type of the software to be tested is determined to be the second type. If the test object is a continuous numerical type, the test type of the software to be tested is determined to be the third type.
[0201] If the test object includes both the numerical class and the process class, the test type of the software to be tested is determined to be the fourth type.
[0202] In one embodiment, when the test model determination module 103 determines the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested, it is used to:
[0203] If the test type of the software to be tested is the first type, obtaining a first model corresponding to the first type as a test model corresponding to the software to be tested;
[0204] If the test type of the software to be tested is the second type, obtaining a second model corresponding to the second type as a test model corresponding to the software to be tested;
[0205] If the test type of the software to be tested is the third type, obtaining a third model corresponding to the third type as a test model corresponding to the software to be tested;
[0206] If the test type of the software to be tested is the fourth type, a fourth model corresponding to the fourth type is obtained as a test model corresponding to the software to be tested.
[0207] In one embodiment, when executing the step of generating the first test case according to the test model and the test parameters, the test case generating module 104 is configured to:
[0208] Obtaining input parameter values and expected parameter values in the test parameters;
[0209] Construct an initial test case according to the input parameter value, execute the initial test case, and obtain an output parameter value;
[0210] Determining whether the output parameter value is included in the expected parameter value;
[0211] If the output parameter value is not included in the expected parameter value, the initial test case is judged to be unqualified;
[0212] If the output parameter value is included in the expected parameter value, the initial test case is used as the first test case.
[0213] In one embodiment, when executing the coverage test on the first test case to obtain the second test case, the test case returning module 105 is used to:
[0214] Execute the first test case using a preset test framework to obtain a test result;
[0215] Calculating the coverage value of the test result using a preset coverage tool, and comparing the coverage value with a preset coverage threshold;
[0216] If the coverage value is greater than or equal to the coverage threshold, taking the initial test case as the second test case;
[0217] If the coverage value is less than the coverage threshold, the first test case is modified and the coverage value of the modified first test case is recalculated until the calculated coverage value is greater than or equal to the coverage threshold, and the test case corresponding to the coverage value greater than or equal to the coverage threshold is used as the second test case.
[0218] In one embodiment, when executing the step of feeding back the second test case as the target test case to the user terminal, the test case returning module 105 is used to:
[0219] Determine whether a test case similar to the target test case is stored in a preset database;
[0220] If a test case similar to the target test case is stored in the database, the target test case replaces the similar test case and stores it in the database;
[0221] If the database does not store a test case similar to the target test case, the target test case is stored in the database.
[0222] The present invention provides a test case generation device, which receives a request for generating a test case, obtains test information corresponding to the software to be tested, and ensures the integrity and accuracy of the test information; analyzes the test type of the software to be tested according to the test object in the test information, and ensures that the test case generated subsequently matches the test object; then determines the test model corresponding to the software to be tested according to the test type, and ensures the generation of high-quality test cases by selecting a suitable test model; then generates a first test case according to the test model and test parameters, performs a coverage test on the first test case to obtain a second test case, feeds the second test case back to the user, optimizes the test case through the coverage test, and ensures that the test case finally generated has a higher coverage rate. The present invention selects the corresponding test model according to the test type of the test object, and performs coverage detection on the test case generated by the selected test model, ensures the coverage rate of the test case, and thus improves the efficiency of automatically generating test cases.
[0223] For the specific definition of the test case generation device, please refer to the definition of the test case generation method above, which will not be repeated here. Each module in the above-mentioned test case generation device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0224] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, it implements the functions or steps on the server side of a test case generation method.
[0225] In one embodiment, a computer device is provided. The computer device may be a client, and its internal structure diagram may be as follows: Figure 5As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. When the computer program is executed by the processor, it implements a function or step of generating a test case client side
[0226] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0227] After receiving a test case request for the software to be tested sent by a user, obtaining test information corresponding to the software to be tested, the test information including a test object and test parameters;
[0228] Analyzing the test type of the software to be tested according to the test object;
[0229] Determine the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested;
[0230] Generate a first test case according to the test model and the test parameters;
[0231] A coverage test is performed on the first test case to obtain a second test case, and the second test case is fed back to the user as a target test case.
[0232] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0233] After receiving a test case request for generating the software to be tested sent by the user terminal, obtaining test information corresponding to the software to be tested, the test information including a test object and test parameters;
[0234] Analyzing the test type of the software to be tested according to the test object;
[0235] Determine the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested;
[0236] Generate a first test case according to the test model and the test parameters;
[0237] A coverage test is performed on the first test case to obtain a second test case, and the second test case is fed back to the user terminal as a target test case.
[0238] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0239] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0240] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0241] The above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should be included in the protection scope of the present invention. It should be noted that if software tools or components other than those of the company appear in the embodiments of this application, they are only used for example introduction and do not represent actual use.
Claims
1. A test case generation method, characterized in that: The method comprises: After receiving a test case request for generating the software to be tested sent by the user terminal, obtaining test information corresponding to the software to be tested, the test information including a test object and test parameters; Analyzing the test type of the software to be tested according to the test object; Determine the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested; Generate a first test case according to the test model and the test parameters; A coverage test is performed on the first test case to obtain a second test case, and the second test case is fed back to the user terminal as a target test case.
2. The test case generation method according to claim 1, characterized in that: The obtaining of the test information corresponding to the software to be tested includes: Obtaining the test requirement document uploaded by the user terminal; Using a preset keyword recognition algorithm to perform keyword recognition on the test requirement document to obtain document keywords; A test object and a test parameter are extracted from the document keywords, and the test object and the test parameter are used as the test information.
3. The test case generation method according to claim 1, characterized in that: Analyzing the test type of the software to be tested according to the test object includes: Obtaining a test object from the test information; Determine the type of the test object, and if the test object is a process type, determine that the test type of the software to be tested is a first type; If the test object is a numerical type, the test object is analyzed to determine whether it is a discrete numerical type or a continuous numerical type. If the test object is a discrete numerical type, the test type of the software to be tested is determined to be the second type. If the test object is a continuous numerical type, the test type of the software to be tested is determined to be the third type. If the test object includes both the numerical class and the process class, the test type of the software to be tested is determined to be the fourth type.
4. The test case generation method according to claim 1, characterized in that: The determining of the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested includes: If the test type of the software to be tested is the first type, obtaining a first model corresponding to the first type as a test model corresponding to the software to be tested; If the test type of the software to be tested is the second type, obtaining a second model corresponding to the second type as a test model corresponding to the software to be tested; If the test type of the software to be tested is the third type, obtaining a third model corresponding to the third type as a test model corresponding to the software to be tested; If the test type of the software to be tested is the fourth type, a fourth model corresponding to the fourth type is obtained as a test model corresponding to the software to be tested.
5. The test case generation method according to claim 1, characterized in that: The generating a first test case according to the test model and the test parameters includes: Obtaining input parameter values and expected parameter values in the test parameters; Construct an initial test case according to the input parameter value, execute the initial test case, and obtain an output parameter value; Determining whether the output parameter value is included in the expected parameter value; If the output parameter value is not included in the expected parameter value, the initial test case is judged to be unqualified; If the output parameter value is included in the expected parameter value, the initial test case is used as the first test case.
6. The test case generation method according to claim 1, characterized in that: The performing coverage testing on the first test case to obtain a second test case includes: Execute the first test case using a preset test framework to obtain a test result; Calculating the coverage value of the test result using a preset coverage tool, and comparing the coverage value with a preset coverage threshold; If the coverage value is greater than or equal to the coverage threshold, taking the initial test case as the second test case; If the coverage value is less than the coverage threshold, the first test case is modified and the coverage value of the modified first test case is recalculated until the calculated coverage value is greater than or equal to the coverage threshold, and the test case corresponding to the coverage value greater than or equal to the coverage threshold is used as the second test case.
7. The test case generation method according to claim 1, characterized in that: After feeding back the second test case as a target test case to the user terminal, the method includes: Determine whether a test case similar to the target test case is stored in a preset database; If a test case similar to the target test case is stored in the database, the target test case replaces the similar test case and stores it in the database; If the database does not store a test case similar to the target test case, the target test case is stored in the database.
8. A test case generating device, characterized in that: The device comprises: The test information acquisition module is used to acquire the test information corresponding to the software to be tested after receiving the test case request for generating the software to be tested sent by the user terminal, wherein the test information includes the test object and the test parameters; Test type analysis module: used for analyzing the test type of the software to be tested according to the test object; Test model determination module: used to determine the corresponding test model according to the predetermined mapping relationship between the test type and the test model and the test type of the software to be tested; A test case generation module: used to generate a first test case according to the test model and the test parameters; Test case return module: used to perform coverage test on the first test case to obtain a second test case, and feed back the second test case as a target test case to the user terminal.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the test case generation method as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the test case generating method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Test case generation method and device, server and storage medium
CN120631787A