Test case generation method and device, equipment and medium
By generating a collection of operation paths from the target log data, identifying exception operation paths and generating exception test cases, the problem that traditional automated testing is difficult to cover complex exception paths is solved, and testing efficiency and security are improved.
Patent Information
- Application Number
- CN202411673281.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-11
AI Technical Summary
Traditional automated testing is difficult to cover all user operation scenarios, especially complex exception paths, and cannot effectively deal with various possible scenarios in the actual production environment.
By generating a set of operation paths based on the target log data, the exception operation paths in the attribute information of the operation path are determined, and an exception test case is generated based on these exception operation paths.
It realizes automatic generation of test cases, accurately identify abnormal test cases, and improves the testing efficiency and safety of automated tests.
Smart Images

Figure CN119597656A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a method, device, equipment and medium for generating a test case. Background Art
[0002] In the current software development process, automated testing is one of the important means to ensure software quality. Through automated testing, some abnormal data or operation behaviors can be identified. Furthermore, a test case is a set of examples compiled for a special goal to verify whether the current operation meets a specific requirement.
[0003] However, traditional automated testing mainly relies on manually written test cases, which is difficult to cover all user operation scenarios, especially complex exception paths. With the increasing complexity of the system and the diversification of user behavior, traditional testing methods are increasingly unable to cope with various possible scenarios in actual production environments. Summary of the invention
[0004] The present invention provides a method, device, equipment and medium for generating a test case. Through the technical solution provided by the embodiments of the present invention, the automatic generation of test cases can be realized, abnormal test cases can be generated more accurately, and the test efficiency and safety of automated testing can be improved.
[0005] In a first aspect, an embodiment of the present invention provides a method for generating a test case, generating an operation path set according to target log data, wherein the target log data includes a timestamp, an operation type, and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp;
[0006] Determine, according to the attribute information of the operation path, an abnormal operation path in the operation path set, wherein the attribute information includes an error type identifier of an erroneous operation in the operation path and / or the operation type in the target log data corresponding to the operation path;
[0007] Generate an abnormal test case according to the abnormal operation path.
[0008] In a second aspect, an embodiment of the present invention provides a test case generation device, comprising:
[0009] An operation path generation module, used to generate an operation path set according to target log data, wherein the target log data includes a timestamp, an operation type and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp;
[0010] a classification module, configured to determine an abnormal operation path in the operation path set according to attribute information of the operation path, wherein the attribute information includes an error type identifier of an erroneous operation in the operation path and / or the operation type in target log data corresponding to the operation path;
[0011] A generation module is used to generate an abnormal test case according to the abnormal operation path.
[0012] In a third aspect, an embodiment of the present invention provides an electronic device, the electronic device comprising:
[0013] at least one processor; and,
[0014] a memory communicatively connected to the at least one processor; wherein,
[0015] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute a test case generation method described in any one of the embodiments of the present invention.
[0016] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement a test case generation method described in any one of the embodiments of the present invention when executed.
[0017] The embodiment of the present invention provides a method, device, equipment and medium for generating a test case, the method comprising: generating an operation path set according to target log data, wherein the target log data comprises a timestamp, an operation type and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp; determining an abnormal operation path in the operation path set according to the attribute information of the operation path, wherein the attribute information comprises an error type identifier of an erroneous operation in the operation path, and / or the operation type in the target log data corresponding to the operation path; generating an abnormal test case according to the abnormal operation path. Specifically, the abnormal operation path can be determined by generating an operation path set from the target log data and then analyzing the operation path attribute information, and then generating an abnormal test case according to the abnormal operation path. Through this method, the automatic generation of test cases can be realized, and abnormal test cases can be accurately identified, thereby improving the test efficiency and security of automated testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 A flowchart of a method for generating a test case provided by an embodiment of the present invention;
[0020] Figure 2 A flowchart of another method for generating a test case provided by an embodiment of the present invention;
[0021] Figure 3 A schematic diagram of the structure of a test case generation device provided by an embodiment of the present invention;
[0022] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0023] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0024] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0025] It should be noted that the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the technical solution of the present disclosure are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0026] Figure 1A flowchart of a test case generation method provided in an embodiment of the present invention, the method can be applicable to a scenario of automatic generation of test cases based on log data, the method can be executed by a test case generation device, the device can be composed of software and / or hardware and configured on an electronic device, for example, the electronic device includes a computer or a server.
[0027] like Figure 1 As shown, including:
[0028] Step 110: Generate an operation path set according to the target log data, wherein the target log data includes a timestamp, an operation type, and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp.
[0029] Among them, the target log data represents the data that meets the search conditions in the standardized log data. The search conditions are determined based on at least one of the timestamp, operation location information, and object identification of the log data as the search term. The target log data includes a timestamp, an operation type, and an operation content. The timestamp represents the time when the operation occurs. The operation type is the type corresponding to the operation content. If the operation content is to click a button, the operation type is a click type. The operation content represents the object of the operation, for example, input data, a clicked button, or a selected option. The operation path set includes several operation paths. The operation path represents the operation content of the target object arranged according to the timestamp.
[0030] For example, the operation path is determined according to operations sequentially performed on the target object in the target log data.
[0031] Optionally, step 110 includes:
[0032] According to at least one of the timestamp, the operation location information, and the object identifier, target log data in the standardized log data is determined, wherein the standardized log data is obtained by standardizing the format of the original log data.
[0033] The target log data is sorted according to the object identifier and the timestamp to obtain an operation sequence, and the operation path set is generated according to the operation content in the operation sequence.
[0034] It should be noted that due to the wide range of sources of raw log data, for example, raw data includes at least one of the sources such as the operation log of the Web application, the API call log generated by the backend service system, the database operation log, and the operation log generated locally by the user terminal, there are cases where the formats of the log data are not the same. Therefore, it is necessary to standardize the raw log data to obtain standard log data. For example, standardization can include character unification and format unification, such as standardization to a JSON text in a preset format.
[0035] Optionally, the target log data also includes: operation location information and object identification.
[0036] It should be noted that, since standard log data may include log data of different users, different functional modules and different times, the operation path includes the operation content of the same target object in the target log data that is executed sequentially.
[0037] Furthermore, the target log data still needs to be sorted according to the object identifier and timestamp, and finally generate a time-ordered operation sequence for a specific user. Then, the operation sequence can be extracted to determine the corresponding operation content, and the operation path set can be generated according to the operation content.
[0038] Specifically, for the original log data, it is necessary to first standardize it, generate standard log data, and store the standard log data in a database or distributed storage system. Then, according to at least one of the timestamp, operation location information, and object identifier of the standard log data, search the standard log data to determine the target log data. The target log data is grouped according to the object identifier, and for the target log data with the same object identifier, the target log data corresponding to each object identifier is sorted based on the timestamp to generate the operation sequence corresponding to each target object. Then, according to the operation content of the operation sequence corresponding to each target object, an operation path set is generated.
[0039] For example, the following is a sequence of operations of a certain user after the operations are sorted according to timestamps and object identifiers:
[0040] [2024-10-16 10:45:23][Page:Dashboard][Click][View Report]→
[0041] [2024-10-16 10:45:25][Page:Report Details][Input][Field:Date Range][Value:2024-01-01to 2024-10-01]→
[0042] [2024-10-16 10:45:30][Page:Report Details][Click][Generate Report].
[0043] The operation path represented by the above sequence is:
[0044] [Enter Dashboard]->[View Report]->[Enter Time Range]->[Generate Report];
[0045] Among them, each part of the operation path represents the operation content of the target object.
[0046] Step 120: determine an abnormal operation path in the operation path set based on the attribute information of the operation path, wherein the attribute information includes an error type identifier of an erroneous operation in the operation path and / or the operation type in the target log data corresponding to the operation path.
[0047] The attribute information of the operation path may include the text content of the operation path, specific identifiers, path length and other features. The abnormal operation of the user can be determined through the attribute information, and then the abnormal operation path can be determined.
[0048] Exemplarily, if the operation path includes an error type identifier, the operation path is determined as an abnormal operation path; or, the abnormal operation path in the operation path set is determined according to the time difference or jump sequence between the operation paths.
[0049] Specifically, if the operation path includes an error type identifier, such as "error" or "error", it can be directly determined as an abnormal operation path.
[0050] Specifically, if the time difference between a certain operation path and the next adjacent operation path is less than a set threshold, it is directly determined as an abnormal operation path.
[0051] Specifically, if the jump sequence of the operation path is different from the preset logical sequence and jumps to an unknown page or a dangerous page, the corresponding operation path can also be determined as an abnormal operation path. For example, if the login page directly jumps to the settlement page, the jump sequence of the operation path is considered abnormal.
[0052] Specifically, abnormal operations characterize operational behaviors that deviate from normal operation modes, such as frequent errors in operations, triggering error pages or system crashes. Abnormal determination rules can be defined based on common abnormal operations. Abnormal determination rules include: defining abnormal operations from at least one of error frequency, operation dwell time, and abnormal jumps. Optionally, if an error log appears in the operation path, the path is determined as an abnormal operation path. For example, if the text content of the operation path records the "output error" field or "error", the operation path can be directly determined as an abnormal operation path. It should be noted that the operation mode of this abnormal operation path may involve keyword extraction and specific methods of text analysis, which are not limited here. Optionally, if the operation dwell time exceeds a set threshold and the operation is not completed, the operation path containing the operation is determined as an abnormal operation path. The operation sequence corresponding to this type of operation abnormality includes an error identifier. By scanning the operation sequence associated with the operation path, it is determined whether the operation sequence includes the target log data corresponding to the error identifier. If so, the operation path is determined as an abnormal operation path. Optionally, if there is no error type identifier in the operation content, it is necessary to analyze the operation content in the target log data corresponding to the operation path to determine the abnormal operation path. For example, it is detected whether there is an abnormal jump in the operation path based on the time difference or jump sequence between the operation paths. If so, the operation path is determined as an abnormal operation path.
[0053] Optionally, an abnormal operation path in the operation path set that is uncommon or does not conform to the normal pattern can also be identified by an anomaly detection algorithm. For example, each operation path in the operation path set is used as a sample, and a feature tree is constructed based on feature vectors such as operation steps, error types, and operation types included in the sample, and the path anomaly score is calculated by the split depth of the tree. Determine whether the path is an abnormal operation path based on the path anomaly score. Among them, the feature tree can represent a tree structure with a single operation path as a leaf node obtained by randomly selecting a feature as a segmentation value to segment the operation path set at least once.
[0054] Step 130: Generate an abnormal test case according to the abnormal operation path.
[0055] Specifically, the test ID, test steps and test results required to generate the test case can be determined through the abnormal operation path, and then the abnormal test case can be generated.
[0056] Optionally, for test cases, normal test cases are also included. Normal test cases are generated in the following ways:
[0057] According to the number of occurrences of the operation path, a common operation path in the operation path set is determined.
[0058] Specifically, the common operation path may be an operation path whose occurrence frequency is greater than a preset threshold. Representative test cases may be generated based on the common operation path.
[0059] A test case template is generated according to the common operation path, and the test case template includes an operation step field, a data field to be filled, an expected result field, etc.
[0060] The operation type in the target log data associated with the operation path is mapped to the operation step field in the test case template, and the to-be-filled data field is filled according to the operation content in the target log data associated with the operation path to obtain a test case.
[0061] Specifically, it is necessary to extract the operation type and operation content in the target log data associated with the common operation path, and map them to the operation steps and input parameters in the test case template. For example, the operation content is actually the data entered in the target log data, or the actual operation such as the button clicked, so the operation content can be filled into the data field to be filled. Since the operation corresponding to the common operation path itself is a safe operation, the expected result field can be set to "safe". For example, if the target log data associated with the common operation path includes [2024-10-16 10:45:23]
[0062] [Click][View Report], mapped to the test step: Click the 'View Report' button. If the target log data associated with the common operation path includes [2024-10-16 10:45:25][Input][Date Range:2024-01-01to2024-10-01], mapped to the test step: Enter the time range as '2024-01-01 to 2024-10-01'.
[0063] Specifically, by extracting the content of the target log data and filling it into the corresponding part of the test case template, the generation process of the safe test case can be completed.
[0064] Optionally, if the operation content is data representing a numerical range, the target operation content is determined according to a boundary value corresponding to the operation content in the target log data associated with the operation path;
[0065] Fill the target operation content into the data field to be filled.
[0066] Specifically, if the operation content is to extract data within the time range of 1 o'clock to 3 o'clock, the boundary values are 1 o'clock and 3 o'clock, and then 1 o'clock, 3 o'clock, and values near 1 o'clock and 3 o'clock can be determined as target operation content, and the target operation content is filled into the data field to be filled.
[0067] Furthermore, by testing the data corresponding to the boundary values, it is possible to ensure that the system can work correctly under critical conditions, improve the accuracy of the test, and ensure that the system will not crash or fail due to extreme conditions.
[0068] Optionally, you can also randomly sample each operation content, determine the target operation content based on the sampling results, and then fill it into the data field to be filled. In this way, you can ensure the randomness and diversity of data selection and the accuracy of test case generation. Random sampling is a method of randomly selecting samples from operation logs or input data to ensure that the selected data can cover the diversity of operation data. Avoid bias through random selection.
[0069] It should be noted that after the test cases are generated, they need to be executed to simulate real operating behaviors. For example, an automated test environment is built by testing servers, virtual machines, or containers. Each test case will be executed in a different test environment to simulate real operating behaviors. Multiple test cases can be executed in parallel. In particular, for test scenarios with high-frequency operation paths, multiple test cases need to be executed in parallel. In order to ensure the execution efficiency of large-scale parallel testing, sufficient computing resources need to be allocated to execute the tests. When executing each test case, the execution results, execution time, resource usage (such as CPU and / or memory, etc.) of the test are recorded, and a corresponding test report is generated. The results of the test report include: whether the test case passes, the execution time of each test step in the test case, the triggering conditions of abnormal scenarios, etc.
[0070] By performing statistical analysis on the results of each test execution, you can determine which operation paths are prone to trigger errors, which cases take a long time to execute, or under what circumstances the resource usage is the highest. By analyzing the results of test execution, you can locate system modules that may have performance bottlenecks or functional defects. The test case library can be dynamically adjusted based on the results of test execution. For example, after a module in the system to be tested is updated, the operation path may change. New test cases can be generated by automatically analyzing the updated operation logs, and old test cases can be marked as obsolete.
[0071] The embodiment of the present invention provides a method for generating a test case, the method comprising: generating an operation path set according to target log data, wherein the target log data comprises a timestamp, an operation type and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp; determining an abnormal operation path in the operation path set according to the attribute information of the operation path, wherein the attribute information comprises an error type identifier of an erroneous operation in the operation path, and / or the operation type in the target log data corresponding to the operation path; generating an abnormal test case according to the abnormal operation path. Specifically, the abnormal operation path can be determined by generating an operation path set from the target log data, and then analyzing the operation path attribute information, and then generating an abnormal test case according to the abnormal operation path. Through this method, the automatic generation of test cases can be realized, and abnormal test cases can be accurately identified, thereby improving the test efficiency and security of automated testing.
[0072] Figure 2 This is a flow chart of another method for generating a test case provided by an embodiment of the present invention. This embodiment is based on the above embodiments and further defines a method for determining an abnormal operation path in the operation path set. Figure 2 As shown, including:
[0073] Step 210: Generate an operation path set according to the target log data, wherein the target log data includes a timestamp, an operation type, and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp.
[0074] Step 220: For any operation path in the operation path set, determine a feature vector corresponding to the operation path according to the number of steps, operation type, and error type identifier corresponding to the operation path.
[0075] Specifically, the number of steps refers to the number of operation contents included in the operation path. The operation type can be numerically encoded. For example, the numerical code corresponding to the operation type of "click" is 1. The numerical code corresponding to the operation type of "input" is 2. The numerical code corresponding to the operation type of "submit" is 3. Further, if the operation path contains an error operation, the error type identifier of the operation path is determined to be 1, otherwise, the error type identifier is determined to be 0.
[0076] Exemplarily, the way of generating feature vectors by operation paths 1-3 is as follows:
[0077] Operation path 1: [Click Home -> Click Login -> Enter Username -> Enter Password -> Submit -> Login Successfully]
[0078] Path 2: [Click Home -> Click Login -> Enter Username -> Enter Password -> Submit -> Login Failed]
[0079] Path 3: [Click Home -> Click Register -> Enter Username -> Submit -> System Reports HTTP 500 Error]
[0080] Path 1: [length: 6, error: 0, operation type: [1,1,2,2,3,0]]
[0081] Path 2: [length: 6, error: 1, operation type: [1,1,2,2,3,1]]
[0082] Path 3: [length: 5, error: 1, operation type: [1, 1, 2, 3, 1]];
[0083] Step 230: determine a segmentation feature value according to the feature vector, divide the feature vector into two feature subsets according to the segmentation feature value, and determine the two feature subsets as a left subtree or a right subtree of a feature tree.
[0084] Step 240: For the feature subset corresponding to the left subtree or the right subtree, if the recursive splitting end condition is not met, a subset splitting feature value is determined according to the feature vector corresponding to the feature subset, and the feature vector corresponding to the feature subset is divided into two feature subsets according to the subset splitting feature value, wherein the recursive splitting end condition includes that the operation path set does not include an unsegmented operation path, or that the feature tree reaches a preset splitting depth.
[0085] Among them, the split feature value is any one of the number of steps, operation type and error type identification. The feature vector can be divided into a feature subset that meets the split condition and a feature subset that does not meet the split condition through the split feature value, and then the two feature subsets can be respectively determined as the left subtree or right subtree of the feature tree.
[0086] Specifically, for each layer of the feature tree, the left subtree and the right subtree of the layer can be determined by different segmentation feature values, and then if a left subtree or a right subtree still includes an unsegmented operation path, it needs to be divided again until the recursive segmentation end condition is met. The recursive segmentation end condition includes that the operation path set does not include an unsegmented operation path, or the feature tree reaches a preset split depth.
[0087] For example, if the feature vectors of paths 1-3 are respectively:
[0088] Path 1: [length: 6, error: 0, operation type: [1,1,2,2,3,0]]
[0089] Path 2: [length: 3, error: 0, operation type: [1,1,2]]
[0090] Path 3: [length: 5, error: 1, operation type: [1, 1, 2, 3, 1]]
[0091] For the first split, length > 3 can be used as the split condition of the feature split value, and then the left subtree of the first split includes paths 1 and 3, and the right subtree includes path 2. At this time, the left subtree includes paths 1 and 3, that is, the corresponding operation path set includes the unsplit operation path, and the recursive split end condition is not met, and the split needs to be continued.
[0092] For the second segmentation, the error value = 1 can be used as the segmentation condition of the feature segmentation value, and then based on the above left subtree, the result of the second segmentation is that the left subtree is path 3 and the right subtree is path 1.
[0093] Specifically, at this time, each leaf node represents a single operation path, that is, all operation paths in the operation path set are isolated separately. From left to right, the order of the leaf nodes is path 3, path 1, and path 2. The operation path set does not include an unsplit operation path, and the recursive splitting end condition is met.
[0094] Step 250: If the recursive segmentation end condition is met, an abnormality score is determined according to the path length of the operation path in the feature tree, and an abnormal operation path in the operation path set is determined according to the abnormality score.
[0095] Specifically, after the segmentation is completed, it is necessary to determine the abnormality score according to the path length of the operation path in the feature tree, and then determine the operation path whose abnormality score meets the preset threshold as an abnormal operation path.
[0096] For example, it can be done by Calculate the anomaly score, where h(x) is the average path length of operation path x in the feature tree, E is the expected path length of x under standard conditions, and n is the number of operation paths. Specifically, if an operation path has a shorter average path length, it means that it is significantly different from other operation paths and may be an abnormal path.
[0097] Optionally, determining an abnormality score according to a path length of the operation path in the feature tree, and determining an abnormal operation path in the operation path set according to the abnormality score includes:
[0098] If the operation path set corresponds to at least two feature trees, at least two anomaly scores corresponding to the operation path are determined according to the path lengths of the operation paths in each feature tree.
[0099] An abnormal operation path in the operation path set is determined according to the at least two abnormality scores.
[0100] Specifically, for the same set of operation paths, different segmentation results may be generated due to different selections of segmentation feature values for each segmentation, generating different feature trees, and thus resulting in different anomaly scores for the same operation path in different feature trees. Therefore, the anomaly scores of multiple feature trees may be combined to determine the final anomaly score of the operation path, and then the abnormal operation path in the set of operation paths may be determined based on the final anomaly score. For example, the final anomaly score may be determined by taking the average of at least two anomaly scores, and then the operation path whose final anomaly score is greater than a preset value may be determined as an abnormal operation path.
[0101] In this way, the anomaly score of the operation path can be determined more accurately, thereby improving the accuracy of abnormal test case generation.
[0102] Step 260: Generate an abnormal test case according to the abnormal operation path.
[0103] An embodiment of the present invention provides a method for generating test cases, which specifically defines that an anomaly score can be calculated through a feature tree, and then an abnormal test case is generated according to the abnormal operation path. In this way, the accuracy of determining the abnormal test path can be improved, and the accuracy of generating abnormal test cases can be improved, thereby improving the efficiency of automated testing and test safety.
[0104] Figure 3 A schematic diagram of the structure of a test case generation device provided by an embodiment of the present invention. Figure 3 As shown, the device comprises:
[0105] An operation path generation module 310, configured to generate an operation path set according to target log data, wherein the target log data includes a timestamp, an operation type, and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp;
[0106] A classification module 320, configured to determine an abnormal operation path in the operation path set according to attribute information of the operation path, wherein the attribute information includes an error type identifier of an erroneous operation in the operation path and / or the operation type in target log data corresponding to the operation path;
[0107] The generating module 330 is used to generate an abnormal test case according to the abnormal operation path.
[0108] The test case generation device provided by the embodiment of the present invention can generate an operation path set from target log data, and then analyze the operation path attribute information to determine the abnormal operation path, and then generate an abnormal test case according to the abnormal operation path. Through this method, the automatic generation of test cases can be realized, and abnormal test cases can be accurately identified, thereby improving the test efficiency and safety of automated testing.
[0109] Optionally, the operation path generation module 310 includes:
[0110] A preprocessing unit, configured to determine target log data in the standardized log data according to at least one of the timestamp, the operation location information, and the object identifier, wherein the standardized log data is obtained by standardizing the format of the original log data;
[0111] The sorting unit is used to sort the target log data according to the object identifier and the timestamp to obtain an operation sequence, and generate the operation path set according to the operation content in the operation sequence.
[0112] Optionally, the classification module 320 includes:
[0113] A feature vector generating unit, configured to determine, for any operation path in the operation path set, a feature vector corresponding to the operation path according to the number of steps, the operation type and the error type identifier corresponding to the operation path;
[0114] A recursive unit, configured to determine a segmentation feature value according to the feature vector, divide the feature vector into two feature subsets according to the segmentation feature value, and determine the two feature subsets as a left subtree or a right subtree of a feature tree; for a feature subset corresponding to the left subtree or the right subtree, if a recursive segmentation termination condition is not satisfied, determine a subset segmentation feature value according to the feature vector corresponding to the feature subset, and divide the feature vector corresponding to the feature subset into two feature subsets according to the subset segmentation feature value, wherein the recursive segmentation termination condition includes that the operation path set does not include an unsegmented operation path, or that the feature tree reaches a preset splitting depth;
[0115] An anomaly score determining unit is used to determine an anomaly score according to the path length of the operation path in the feature tree if the recursive segmentation end condition is met, and determine an abnormal operation path in the operation path set according to the anomaly score.
[0116] The identification unit is used to determine the operation path as an abnormal operation path if the operation path includes an error type identifier; or to determine the abnormal operation path in the operation path set according to the time difference or jump sequence between the operation paths.
[0117] Optionally, the anomaly score determination unit is specifically used to: if the operation path set corresponds to at least two feature trees, determine at least two anomaly scores corresponding to the operation path according to the path length of the operation path in each feature tree; and determine the abnormal operation path in the operation path set according to the at least two anomaly scores.
[0118] Optionally, the test case generating device further includes:
[0119] Security test case generation module, including:
[0120] A statistical unit, used to determine a common operation path in the operation path set according to the number of occurrences of the operation path;
[0121] A template generating unit, used to generate a test case template according to the common operation path, wherein the test case template includes an operation step field, a data field to be filled, and an expected result field;
[0122] A mapping unit is used to map the operation type in the target log data associated with the operation path to the operation step field in the test case template, and fill the to-be-filled data field according to the operation content in the target log data associated with the operation path to obtain a test case.
[0123] Optionally, the mapping unit is specifically configured to, if the operation content is data representing a numerical range, determine the target operation content according to a boundary value corresponding to the operation content in the target log data associated with the operation path;
[0124] Fill the target operation content into the data field to be filled.
[0125] The test case generation device provided in the embodiment of the present invention can execute the test case generation method provided in any embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method.
[0126] Figure 4 A schematic diagram of the structure of an electronic device provided for an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0127] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0128] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0129] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a method for generating test cases.
[0130] In some embodiments, the test case generation method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the test case generation method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the test case generation method in any other appropriate manner (e.g., by means of firmware).
[0131] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0132] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0133] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0134] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0135] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0136] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0137] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0138] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for generating a test case, characterized in that: include: Generate an operation path set according to target log data, wherein the target log data includes a timestamp, an operation type, and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp; Determine an abnormal operation path in the operation path set according to attribute information of the operation path, wherein the attribute information includes an error type identifier of an erroneous operation in the operation path and / or the operation type in target log data corresponding to the operation path; Generate an abnormal test case according to the abnormal operation path.
2. The method according to claim 1, characterized in that The target log data also includes: operation location information and object identification; The step of generating an operation path set according to the target log data includes: Determine target log data in the standardized log data according to at least one of the timestamp, the operation location information, and the object identifier, wherein the standardized log data is obtained by standardizing the format of the original log data; The target log data is sorted according to the object identifier and the timestamp to obtain an operation sequence, and the operation path set is generated according to the operation content in the operation sequence.
3. The method according to claim 1, characterized in that The determining, according to the attribute information of the operation path, an abnormal operation path in the operation path set includes: For any operation path in the operation path set, determining a feature vector corresponding to the operation path according to the number of steps, operation type and error type identifier corresponding to the operation path; Determine a segmentation feature value according to the feature vector, divide the feature vector into two feature subsets according to the segmentation feature value, and determine the two feature subsets as a left subtree or a right subtree of a feature tree; For the feature subset corresponding to the left subtree or the right subtree, if the recursive segmentation termination condition is not satisfied, a subset segmentation feature value is determined according to the feature vector corresponding to the feature subset, and the feature vector corresponding to the feature subset is divided into two feature subsets according to the subset segmentation feature value, wherein the recursive segmentation termination condition includes that the operation path set does not include an unsegmented operation path, or that the feature tree reaches a preset splitting depth; If the recursive segmentation termination condition is met, an abnormality score is determined according to the path length of the operation path in the feature tree, and an abnormal operation path in the operation path set is determined according to the abnormality score.
4. The method according to claim 3, characterized in that The determining of an abnormality score according to the path length of the operation path in the feature tree, and determining an abnormal operation path in the operation path set according to the abnormality score, comprises: If the operation path set corresponds to at least two feature trees, determining at least two anomaly scores corresponding to the operation path according to the path length of the operation path in each feature tree; An abnormal operation path in the operation path set is determined according to the at least two abnormality scores.
5. The method according to claim 1, characterized in that The determining, according to the attribute information of the operation path, an abnormal operation path in the operation path set includes: If the operation path includes an error type identifier, determining the operation path as an abnormal operation path; or, An abnormal operation path in the operation path set is determined according to the time difference or jump sequence between the operation paths.
6. The method according to claim 1, characterized in that After generating an operation path set based on the target log data, including: Determining a common operation path in the operation path set according to the number of occurrences of the operation path; Generate a test case template according to the common operation path, wherein the test case template includes an operation step field, a data field to be filled, and an expected result field; The operation type in the target log data associated with the operation path is mapped to the operation step field in the test case template, and the to-be-filled data field is filled according to the operation content in the target log data associated with the operation path to obtain a test case.
7. The method according to claim 6, characterized in that The step of filling the data field to be filled with the operation content in the target log data associated with the operation path includes: If the operation content is data representing a numerical range, determining the target operation content according to a boundary value corresponding to the operation content in the target log data associated with the operation path; Fill the target operation content into the data field to be filled.
8. A test case generation device, characterized in that: include: An operation path generation module, used to generate an operation path set according to target log data, wherein the target log data includes a timestamp, an operation type and an operation content, and the operation path represents the operation content of the target object arranged according to the timestamp; a classification module, configured to determine an abnormal operation path in the operation path set according to attribute information of the operation path, wherein the attribute information includes an error type identifier of an erroneous operation in the operation path and / or the operation type in target log data corresponding to the operation path; A generation module is used to generate an abnormal test case according to the abnormal operation path.
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 computer program is executed by the at least one processor so that the at least one processor can execute a test case generation method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement a test case generation method according to any one of claims 1 to 7 when executed.