Test case generation method and device, electronic equipment and storage medium
By generating a comprehensive state model and detecting deviations in collaborative relationships, targeted test cases are automatically generated, which solves the deep-seated defects caused by the disconnection of internal system elements and enables accurate testing of complex fault scenarios.
Patent Information
- Application Number
- CN202511851793.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-09
- Publication Date
- 2026-02-10
AI Technical Summary
Existing technologies are unable to effectively identify and address deep-seated defects caused by the loss of coordination and disconnection between different elements at different levels within a system during its development and evolution. This makes it difficult for testing activities to reach complex failure scenarios, leaving quality risks unresolved.
By acquiring multi-dimensional state data of the system under test, a comprehensive state model is generated, the deviation of the collaborative relationship between any two pieces of information in the multi-dimensional state data is detected, and targeted test cases are automatically generated.
It enables timely and accurate identification and precise testing of the problem of loss of coordination among different levels of elements within the system, solves the deep defects caused by the disconnection of internal elements, and improves the comprehensiveness of test coverage and the accuracy of risk identification.
Smart Images

Figure CN121501684A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software testing technology, and in particular to a test case generation method, apparatus, electronic device, and storage medium. Background Technology
[0002] With microservice architecture and cloud computing becoming mainstream, the deployment scale and logical complexity of software systems have increased dramatically. Rapid iteration and frequent releases of new features have become the norm, placing higher demands on software quality assurance systems. Traditional testing methods primarily focus on the software development phase, aiming to verify the correctness of code logic and compliance with functional requirements.
[0003] Existing technical solutions typically focus on building and evaluating test cases from a single data dimension. One common approach is to rely on static code analysis tools to scan source code, identify code defects or security vulnerabilities based on predefined rule sets, and generate targeted test cases. Another approach is to optimize test case sets or locate problems by analyzing code coverage or error frequency based on historical test execution results or program operation logs.
[0004] However, existing technologies and methods cannot effectively identify and address deep-seated defects caused by the loss of coordination and disconnection between different elements at different levels within a system during its evolution. This makes it difficult for testing activities to reach complex failure scenarios caused by misalignment between code, runtime environment, and actual user operations, leaving potential quality risks. Summary of the Invention
[0005] This application provides a test case generation method, apparatus, electronic device, and storage medium to solve the problem in the prior art that it is impossible to effectively identify and deal with deep defects caused by the loss of coordination and disconnection between different elements at different levels within the system during development and evolution.
[0006] Firstly, this application provides a test case generation method, including: Acquire multi-dimensional state data of the system under test, including static structural information, dynamic operation information and external operation information; Based on the static structural information, the dynamic operational information, and the external operational information, a comprehensive state model is generated to characterize the system under test. Based on the comprehensive state model, the deviation of the collaborative relationship between any two pieces of information in the multi-dimensional state data is detected; If a deviation in the collaborative relationship between any two pieces of information is detected, test cases are generated to verify the collaborative relationship.
[0007] In one possible implementation, generating a comprehensive state model characterizing the system under test based on the static structural information, the dynamic operational information, and the external operational information includes: The static structural information is parsed to generate a control flow graph, and the structural features of each node in the control flow graph are extracted using a graph neural network to obtain the control flow graph node features; The service call sequence in the dynamic operation information is time-series encoded to obtain a time-series feature vector; Cluster analysis is performed on the external operation information to obtain user behavior cluster features; The comprehensive state model is generated based on the control flow graph node features, the temporal feature vector, and the user behavior cluster features.
[0008] In one possible implementation, detecting deviations in the collaborative relationship between any two pieces of information in the multi-dimensional state data based on the comprehensive state model includes: Based on the control flow graph node features and user behavior cluster features in the integrated state model, the deviation of the first collaborative relationship between the static structure information and the external operation information is detected; or; Based on the control flow graph node features and temporal feature vectors in the integrated state model, the deviation of the second collaborative relationship between the static structure information and the dynamic operation information is detected; or; Based on the temporal feature vector and user behavior cluster features in the comprehensive state model, the deviation of the third collaborative relationship between the dynamic operation information and the external operation information is detected.
[0009] In one possible implementation, detecting the deviation of the first collaborative relationship between the static structure information and the external operation information based on the control flow graph node features and user behavior cluster features in the integrated state model includes: Based on the control flow graph node features and the user behavior cluster features, calculate the impact weight of code changes and the frequency of user behavior coverage; Calculate the first deviation score based on the weight of the impact of the code change and the frequency of user behavior coverage; If the first deviation score exceeds the first dynamic threshold, it is determined that the first collaborative relationship has deviated.
[0010] In one possible implementation, detecting the deviation of the second cooperative relationship between the static structural information and the dynamic operational information based on the control flow graph node features and temporal feature vectors in the integrated state model includes: Based on the control flow graph node features and the time-series feature vector, the preset indicators of the service level target are compared with the actual operation indicators in the dynamic operation information; If the fluctuation of the actual operating indicator relative to the preset indicator exceeds the second dynamic threshold, it is determined that the second collaborative relationship has deviated.
[0011] In one possible implementation, detecting the deviation of the third collaborative relationship between the dynamic operation information and the external operation information based on the temporal feature vector and user behavior cluster features in the integrated state model includes: Based on the time-series feature vector and the user behavior cluster features, a correlation model between user behavior clusters and runtime abnormal patterns is established. If the probability of triggering an abnormal mode in any user behavior cluster exceeds the third dynamic threshold, it is determined that the third collaborative relationship has deviated.
[0012] In one possible implementation, generating test cases to verify the collaborative relationship when a deviation is detected between any two pieces of information includes: If a deviation is determined in the first collaboration relationship, a patch use case is generated to cover the path of code change and user behavior deviation; If a deviation is found in the second collaborative relationship, risk-weighted test cases are generated to verify the system's fault tolerance. If a deviation is found in the third collaborative relationship, user scenario verification test cases are generated to verify whether a specific user operation causes a system anomaly.
[0013] In one possible implementation, the step of performing cluster analysis on the external operation information to obtain user behavior cluster features includes: Based on the historical records of the external operation information, the frequency of occurrence of different operation events is statistically analyzed; Based on predefined business rules, determine the business criticality weight of different operational events; Calculate the radius parameter for cluster analysis based on the frequency of occurrence of the events and the business criticality weights; Based on the radius parameter, clustering operations are performed on the operation events in the external operation information to generate user behavior clusters; Extract the user behavior cluster features from the user behavior cluster.
[0014] Secondly, this application provides a test case generation apparatus, comprising: The acquisition module is used to acquire multi-dimensional state data of the system under test, including static structure information, dynamic operation information and external operation information. The first generation module is used to generate a comprehensive state model characterizing the system under test based on the static structural information, the dynamic operation information and the external operation information. The detection module is used to detect deviations in the collaborative relationship between any two pieces of information in the multi-dimensional state data based on the comprehensive state model. The second generation module is used to generate test cases to verify the collaborative relationship when a deviation is detected between any two pieces of information.
[0015] In one possible implementation, the first generation module is specifically used for: The static structural information is parsed to generate a control flow graph, and the structural features of each node in the control flow graph are extracted using a graph neural network to obtain the control flow graph node features; The service call sequence in the dynamic operation information is time-series encoded to obtain a time-series feature vector; Cluster analysis is performed on the external operation information to obtain user behavior cluster features; The comprehensive state model is generated based on the control flow graph node features, the temporal feature vector, and the user behavior cluster features.
[0016] In one possible implementation, the detection module is specifically used for: Based on the control flow graph node features and user behavior cluster features in the integrated state model, the deviation of the first collaborative relationship between the static structure information and the external operation information is detected; or; Based on the control flow graph node features and temporal feature vectors in the integrated state model, the deviation of the second collaborative relationship between the static structure information and the dynamic operation information is detected; or; Based on the temporal feature vector and user behavior cluster features in the comprehensive state model, the deviation of the third collaborative relationship between the dynamic operation information and the external operation information is detected.
[0017] In one possible implementation, the detection module is further configured to: Based on the control flow graph node features and the user behavior cluster features, calculate the impact weight of code changes and the frequency of user behavior coverage; Calculate the first deviation score based on the weight of the impact of the code change and the frequency of user behavior coverage; If the first deviation score exceeds the first dynamic threshold, it is determined that the first collaborative relationship has deviated.
[0018] In one possible implementation, the detection module is further configured to: Based on the control flow graph node features and the time-series feature vector, the preset indicators of the service level target are compared with the actual operation indicators in the dynamic operation information; If the fluctuation of the actual operating indicator relative to the preset indicator exceeds the second dynamic threshold, it is determined that the second collaborative relationship has deviated.
[0019] In one possible implementation, the detection module is further configured to: Based on the time-series feature vector and the user behavior cluster features, a correlation model between user behavior clusters and runtime abnormal patterns is established. If the probability of triggering an abnormal mode in any user behavior cluster exceeds the third dynamic threshold, it is determined that the third collaborative relationship has deviated.
[0020] In one possible implementation, the second generation module is specifically used for: If a deviation is determined in the first collaboration relationship, a patch use case is generated to cover the path of code change and user behavior deviation; If a deviation is found in the second collaborative relationship, risk-weighted test cases are generated to verify the system's fault tolerance. If a deviation is found in the third collaborative relationship, user scenario verification test cases are generated to verify whether a specific user operation causes a system anomaly.
[0021] In one possible implementation, the first generation module is further configured to: Based on the historical records of the external operation information, the frequency of occurrence of different operation events is statistically analyzed; Based on predefined business rules, determine the business criticality weight of different operational events; Calculate the radius parameter for cluster analysis based on the frequency of occurrence of the events and the business criticality weights; Based on the radius parameter, clustering operations are performed on the operation events in the external operation information to generate user behavior clusters; Extract the user behavior cluster features from the user behavior cluster.
[0022] Thirdly, this application provides an apparatus comprising: a processor and a memory, the processor being configured to execute a test case generation program stored in the memory to implement the test case generation method described in any one of the first aspects.
[0023] Fourthly, this application provides a storage medium storing one or more programs that can be executed by one or more processors to implement the test case generation method described in any one aspect.
[0024] Compared with the prior art, the technical solution provided in this application has the following advantages: First, by acquiring multi-dimensional state data of the system under test and generating a comprehensive state model, a unified view that can comprehensively reflect the collaborative relationships of various levels within the system is established, breaking through the limitation of existing technologies that only construct test models from a single dimension, and providing basic support for identifying multi-dimensional collaborative imbalances; Second, by detecting deviations in the collaborative relationships between at least two pieces of information based on the comprehensive state model, proactive discovery of interaction imbalances between code structure, runtime state, and user behavior is achieved, enabling timely and accurate identification of problems where elements at different levels within the system lose collaboration; Finally, by automatically generating targeted test cases when a deviation in collaborative relationships is detected, accurate testing of complex fault scenarios caused by the interaction of multi-dimensional factors is achieved, thereby effectively solving the technical problem that existing technologies struggle to cope with deep defects caused by the disconnection of elements within the system. Attached Figure Description
[0025] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0026] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0028] Figure 1 A flowchart illustrating an embodiment of a test case generation method provided in this application; Figure 2 A flowchart illustrating an embodiment of another test case generation method provided in this application; Figure 3 A block diagram illustrating an embodiment of a test case generation device provided in this application; Figure 4This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0030] The following disclosure provides numerous different embodiments or examples for implementing various structures of this application. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of this application. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.
[0031] To address the technical problem that existing technologies cannot effectively identify and respond to deep-seated defects caused by the loss of coordination and disconnection of different elements within a system during its development and evolution, this application provides a test case generation method that can effectively solve the technical problem that existing technologies struggle to address deep-seated defects caused by the disconnection of elements within a system.
[0032] Figure 1 This is a flowchart illustrating an embodiment of a test case generation method provided in this application. Figure 1 As shown, the method includes the following steps: Step 101: Obtain multi-dimensional state data of the system under test, including static structural information, dynamic operation information and external operation information.
[0033] System under test: refers to the software system that needs to be tested, especially complex distributed applications that adopt a microservice architecture or are deployed in a multi-cloud environment.
[0034] Multidimensional state data: refers to a collection of data obtained from different perspectives and sources to describe the overall state of a system.
[0035] Static structural information refers to the structural information contained in the system source code itself, such as classes, methods, function call relationships, and the resulting control flow graph.
[0036] Dynamic runtime information refers to the data generated by the system during runtime, specifically including Span logs obtained from the distributed tracing system, which record service call dependencies and timestamp sequences, as well as system monitoring metrics and service level target data.
[0037] External operation information: refers to a series of operation event logs triggered by users or clients outside the system, reflecting the actual user behavior patterns.
[0038] In this embodiment of the application, automated collection of multi-dimensional status data is achieved through the following methods: By integrating a version control system (such as Git), the source code repository can be parsed to obtain static structure information; By deploying log collection agents (such as Filebeat) and call chain tracing systems (such as SkyWalking and Zipkin), Span logs and performance monitoring metrics in production or testing environments can be collected to obtain dynamic operational information. By accessing user behavior analysis platforms (such as event tracking systems) or parsing API (Application Programming Interface) gateway access logs, user event logs can be extracted to obtain external operation information.
[0039] This data acquisition process ensures that test cases are generated based on a comprehensive understanding of the system as a whole (including code structure, runtime state, and usage scenarios).
[0040] Step 102: Based on the static structural information, the dynamic operation information, and the external operation information, generate a comprehensive state model to characterize the system under test.
[0041] The comprehensive state model is a unified computational model built by integrating features from multiple data sources. It aims to characterize the intrinsic relationship between code structure, runtime behavior, and user operations, as well as the overall state of the system.
[0042] In this embodiment, firstly, static structural information is parsed to generate an abstract syntax tree and further construct a control flow graph. Then, a graph convolutional network is used to process the control flow graph to extract structural features of code modules and information on high-risk branch nodes, forming control flow graph node features. Secondly, the Span logs in the dynamic runtime information are preprocessed to extract service call timing relationships. A time-series coding model (Time2Vec) is used to map this timing information into vectors, obtaining timing feature vectors to identify runtime patterns such as cascading failures. Next, an improved density-based noise-based spatial clustering algorithm is used to mine behavioral patterns from external operational information. The clustering radius parameter of this algorithm is dynamically calculated based on event frequency and business criticality weights, thereby outputting representative user behavior cluster features. Finally, a cross-modal attention fusion module aligns and weights the control flow graph node features, timing feature vectors, and user behavior cluster features to generate a comprehensive state model that can fully and deeply characterize the system state.
[0043] Step 103: Based on the comprehensive state model, detect the deviation of the collaborative relationship between any two pieces of information in the multi-dimensional state data.
[0044] Collaborative relationships refer to the matching, dependency, or consistency relationships that should exist between different dimensions of information (such as static structure, dynamic operation, and external operations) under normal system operation.
[0045] Deviation: refers to the imbalance, inconsistency or abnormal state that occurs in the above-mentioned collaborative relationship due to system evolution, code changes or abnormal events.
[0046] In this embodiment, based on the fusion features provided by the comprehensive state model, the collaborative state between different information dimensions is quantitatively analyzed. For example, a first deviation score can be calculated to assess the collaborative relationship between static structural information and external operational information: by combining the impact weight of code changes (whose calculation can consider the code call depth and service level target impact) and the coverage frequency of user behavior clusters, the risk level of newly added code not being covered by real user behavior can be quantified. Alternatively, by comparing the preset indicators of service level targets (such as latency thresholds) with the actual operational indicators in dynamic operational information (such as current latency), their fluctuation variance can be calculated to detect whether there is a deviation between static structural information and dynamic operational information. When any quantitative indicator exceeds its corresponding dynamic threshold, it is determined that the corresponding collaborative relationship has deviated in a way that requires attention.
[0047] Step 104: If a deviation in the collaborative relationship between any two pieces of information is detected, generate test cases to verify the collaborative relationship.
[0048] In this embodiment, highly targeted test cases are adaptively generated based on the specific type of collaborative relationship deviation detected in step 103. Specifically, this includes the following three typical cases: When a deviation is detected between static structural information and external operational information (i.e., the first deviation score exceeds the dynamic threshold), patch test cases are generated. The generation of these test cases combines symbolic execution techniques to derive boundary value inputs that trigger high-risk code branches, and injects chaotic engineering perturbations (such as simulating network latency, service failures, etc.) to strengthen verification and ensure that newly added or changed code can be effectively covered and tested.
[0049] When a deviation is detected between static structural information and dynamic operational information (such as service level target fluctuations exceeding a threshold), risk-weighted use cases are generated. These use cases are based on a service dependency chain fault propagation model, constructing specific fault injection scenarios to verify the system's fault tolerance and resilience, such as simulating downstream service timeouts or database access anomalies.
[0050] When a deviation is detected between dynamic runtime information and external operational information (i.e., the probability of a specific user behavior cluster triggering a runtime anomaly pattern exceeds a dynamic threshold, as identified by the association model), user scenario verification test cases are generated. These test cases reproduce specific user operation sequences identified as high-risk (e.g., "the user first performs a search operation, and then quickly clicks the favorite button before the results are fully loaded"), and transform them into automated test scripts to verify the system's robustness in the face of such real-world user scenarios, ensuring that the anomaly has been fixed or its recurrence has been prevented.
[0051] When API semantic mismatches or parameter differences are detected in a multi-cloud deployment environment, cross-cloud compatibility test cases are generated. The generation of these test cases is first achieved through semantic equivalence matching. Specifically, semantic models such as Sentence-BidirectionalEncoder Representations from Transformers are used to vectorize the multi-cloud API descriptions. Cosine similarity is calculated (the formula is: similarity = (vec_AWS·vec_Aliyun) / (|vec_AWS| × |vec_Aliyun|)): a similarity greater than 0.8 indicates an equivalent API, a similarity between 0.5 and 0.8 prompts for manual review, and a similarity less than 0.5 indicates an incompatible API. For APIs determined to be equivalent, parameter mapping is automatically generated. Mapping rules are established by deriving parameter alias relationships (e.g., mapping the "security_token" parameter of Amazon Simple Storage Service (AWS S3) to Alibaba Cloud Object Storage Service (Alibaba Cloud Object Storage Service). The system uses the "x-oss-security-token" parameter of OSS and fills in placeholder values for unique parameters by default. Finally, it constructs verification test cases based on the generated mapping rules, and completes cross-cloud compatibility verification by calling multiple cloud platform equivalent APIs at the same time and asserting the consistency of their returned results.
[0052] By introducing semantic-level automated alignment and parameter mapping technology, this method effectively solves the compatibility problem caused by API differences in multi-cloud environments, significantly reduces manual adaptation time, and improves test coverage for multi-cloud deployment scenarios by generating accurate compatibility verification test cases, thereby enhancing the reliability of the system in hybrid cloud environments.
[0053] The technical solution provided in this application firstly establishes a unified view that comprehensively reflects the collaborative relationships at all levels within the system by acquiring multi-dimensional state data of the system under test and generating a comprehensive state model. This overcomes the limitations of existing technologies that only construct test models from a single dimension, providing a foundation for identifying multi-dimensional collaborative imbalances. Secondly, by detecting deviations in the collaborative relationships between at least two pieces of information based on this comprehensive state model, proactive discovery of interaction imbalances between code structure, runtime state, and user behavior is achieved, enabling timely and accurate identification of issues where elements at different levels within the system lose collaboration. Finally, by automatically generating targeted test cases when a deviation in collaborative relationships is detected, precise testing of complex fault scenarios caused by the interaction of multi-dimensional factors is achieved, effectively solving the technical problem that existing technologies struggle to address deep-seated defects caused by the disconnection of elements within the system.
[0054] Figure 2 A flowchart illustrating an embodiment of another test case generation method provided in this application. Figure 2 The process shown is in Figure 1 Based on the illustrated process, the following steps are included: Step 201: Parse the static structure information to generate a control flow graph, and use a graph neural network to extract the structural features of each node in the control flow graph to obtain the control flow graph node features.
[0055] Control flow graph: A graphical model used to represent all possible execution paths of a program, where nodes represent basic code blocks and edges represent control flow transfers.
[0056] Graph Neural Networks (GNNs) are deep learning models specifically designed for processing graph-structured data. They learn feature representations of nodes in a graph by aggregating information from neighboring nodes.
[0057] Control flow graph node features: refers to numerical vectors learned through graph neural networks that can represent each node (i.e. code block) in the graph and its semantic information in the global context.
[0058] This step aims to extract structural features from the source code. Specifically, firstly, lexical and syntactic analysis are performed on the static structural information (i.e., the source code) to construct an Abstract Syntax Tree (AST), which then generates a control flow graph. Next, a graph neural network is used to learn the representation of the control flow graph. Through multi-layer message passing and feature aggregation, the deep structural semantics of each node in the graph and its association with neighboring nodes are captured. Finally, a feature vector corresponding to each node is output, which can identify complex patterns and potentially high-risk branches in the code.
[0059] Step 202: Perform time-series encoding on the service call sequence in the dynamic operation information to obtain a time-series feature vector.
[0060] Service call sequence: In a distributed system, a chain of cross-service calls triggered in chronological order during the processing of a single request is typically recorded by the Span log.
[0061] Time series coding: refers to the process of mapping time series data or a sequence of events with a chronological order into a fixed-dimensional numerical vector.
[0062] Temporal feature vector: refers to a numerical vector obtained through a temporal coding model that can characterize the temporal dependencies and dynamic behaviors in a service call sequence.
[0063] This step aims to extract temporal features from system runtime data. Specifically, it extracts the service call sequence and its precise timestamps from dynamic runtime information (such as Span logs); then, it encodes the sequence using a temporal coding model (such as Time2Vec) to map the temporal patterns such as the order and time intervals of service calls into a low-dimensional, dense feature vector; this temporal feature vector can effectively capture dynamic behavioral patterns such as the normal / abnormal rhythm of the service call chain, potential timeout retry storms, or cascading failures.
[0064] Step 203: Perform cluster analysis on the external operation information to obtain user behavior cluster features.
[0065] Clustering analysis: an unsupervised machine learning method that aims to group objects in a dataset such that objects within the same group (i.e., clusters) are similar to each other, while objects in different groups are dissimilar.
[0066] User behavior cluster features: These are numerical vectors obtained through cluster analysis that can characterize the typical operating habits and interaction patterns of different user groups.
[0067] In this embodiment of the application, step 203 may specifically include the following steps: based on the historical records of the external operation information, statistically analyze the event frequency of different operation events; based on predefined business rules, determine the business criticality weight of different operation events; calculate the radius parameter of cluster analysis according to the event frequency and the business criticality weight; perform clustering operation on the operation events in the external operation information based on the radius parameter to generate user behavior clusters; and extract the user behavior cluster features from the user behavior clusters.
[0068] Event frequency: The proportion of a specific type of user operation event occurring within a statistical period to the total number of operations, used to measure the prevalence of that operation pattern. Business criticality weight: An importance coefficient assigned to different operation events based on predefined business rules, used to characterize the degree of impact of the operation on core business processes. Clustering radius parameter: In density-based clustering algorithms, a core parameter used to define the neighborhood search range, directly determining the granularity of cluster formation. User behavior cluster: A set of user behaviors with similar operation patterns and characteristics obtained through clustering analysis.
[0069] This step is the core of achieving accurate user behavior pattern mining. First, statistical analysis is performed based on historical records of external operation information to calculate the frequency of different operation events. Simultaneously, according to predefined business rules (e.g., transaction-related operations have higher weight than browsing-related operations), the business criticality weight of each operation event is determined. Then, based on the event frequency and business criticality weight, the clustering radius parameter is dynamically calculated using the formula EPS = α × (1 / event frequency) + β × business criticality weight (where α = 0.6 and β = 0.4 are adjustable parameters). Based on this, an improved DBSCAN algorithm is used to perform clustering operations on the operation events using this dynamic radius parameter, generating user behavior clusters that reflect real user behavior patterns. Finally, numerical vectors representing typical operation sequences and common features within the generated user behavior clusters are extracted, i.e., user behavior cluster features.
[0070] This solution introduces a dynamic radius calculation mechanism based on event frequency and business weight, which enables fine-grained clustering of high-frequency critical paths and effective coverage of low-frequency important paths. It overcomes the clustering fragmentation or overgeneralization problems caused by traditional fixed threshold methods, thereby extracting representative behavioral pattern features from massive user behavior more comprehensively and accurately, providing a high-quality data foundation for subsequent detection of deviations in the collaborative relationship between user behavior and system state.
[0071] Step 204: Generate the comprehensive state model based on the control flow graph node features, the temporal feature vector, and the user behavior cluster features.
[0072] This step is crucial for achieving multi-source information fusion. Specifically, the control flow graph node features, temporal feature vectors, and user behavior cluster features obtained in the preceding steps are used as input and aligned and integrated through a cross-modal attention fusion module. This module can adaptively calculate the correlation weights between features from different sources to achieve information complementarity. For example, it can map timestamp information in Span logs to specific nodes in the AST control flow graph, or associate user behavior clusters with the code modules that trigger them most frequently. Ultimately, it generates a comprehensive state model that fully and deeply reflects the complex relationships between the system's static structure, dynamic operation, and external usage.
[0073] Figure 2 The process shown systematically completes the extraction of key features from multi-source heterogeneous data and the construction of a unified model, laying a solid foundation for subsequent accurate detection of deviations in the collaborative relationships between various dimensions within the system, thereby significantly improving the comprehensiveness of test coverage and the accuracy of risk identification.
[0074] Based on the multi-dimensional features fused by the integrated state model, this application achieves the detection of deviations in the collaborative relationship in step 103 in the following ways: detecting the deviation of the first collaborative relationship between the static structure information and the external operation information based on the control flow graph node features and user behavior cluster features in the integrated state model; or; detecting the deviation of the second collaborative relationship between the static structure information and the dynamic operation information based on the control flow graph node features and temporal feature vectors in the integrated state model; or; detecting the deviation of the third collaborative relationship between the dynamic operation information and the external operation information based on the temporal feature vectors and user behavior cluster features in the integrated state model.
[0075] In one specific implementation, detecting the deviation of the first collaborative relationship between the static structural information and the external operation information based on the control flow graph node features and user behavior cluster features in the integrated state model includes: calculating the code change impact weight and user behavior coverage frequency based on the control flow graph node features and the user behavior cluster features; calculating a first deviation score based on the code change impact weight and the user behavior coverage frequency; and determining that the first collaborative relationship has deviated if the first deviation score exceeds a first dynamic threshold.
[0076] Code Change Impact Weight: An indicator used to quantify the overall impact of code changes (such as adding or modifying modules) on the system. Its calculation comprehensively considers the impact of code call depth and service level targets. User Behavior Coverage Frequency: Refers to the actual execution frequency of code modules corresponding to the operation sequence of a specific user behavior cluster. The calculation formula is: Number of times the corresponding code module is executed when an event within the cluster is triggered / Total number of executions. First Deviation Score: A numerical indicator used to quantify the degree of deviation between the collaborative relationship between static structural information and external operational information.
[0077] This implementation specifically defines how to detect collaborative deviations between code and user behavior. First, based on control flow graph node characteristics (containing code structure risks) and user behavior cluster characteristics (reflecting user operation patterns), the impact weight of code changes is calculated (the formula is: 0.3 × call depth + 0.7 × SLO (Service Level Objective) impact) and the frequency of user behavior coverage. Then, according to the formula: DeviationScore = 1 - [Σ(ClusterFreq_i × ImpactWeight_j)] / TotalCoverage, a first deviation score is calculated. Finally, by comparing this score with a first dynamic threshold that adaptively adjusts based on fluctuations in the service level objective, it is determined whether a significant deviation in the first collaborative relationship has occurred.
[0078] This solution quantifies the match between the impact of code changes and the coverage of user behavior, enabling it to accurately identify high-risk paths that are not covered by real user behavior due to code changes. This proactively discovers "code blind spots" and effectively avoids online failures caused by the disconnect between code and user behavior.
[0079] In another embodiment, detecting the deviation of the second collaborative relationship between the static structural information and the dynamic operational information based on the control flow graph node features and time-series feature vectors in the integrated state model includes: comparing the preset indicators of the service level target with the actual operational indicators in the dynamic operational information based on the control flow graph node features and the time-series feature vectors; and determining that the second collaborative relationship has deviated if the fluctuation of the actual operational indicators relative to the preset indicators exceeds a second dynamic threshold.
[0080] Service level target preset indicators: These refer to the pre-set quality target values such as performance and availability for system services, such as the maximum allowable latency and minimum success rate thresholds. Actual operational indicators: These refer to the performance, availability, and other data actually measured by the system in a real operating environment. Second dynamic threshold: An adaptively adjustable boundary value used to determine whether fluctuations in actual operational indicators relative to preset indicators constitute a deviation from the synergy.
[0081] This implementation specifically defines how to detect the collaborative deviation between the code design expectations and the system's runtime performance. Its core lies in using control flow graph node features to identify key code modules and their expected service level targets (SLOs). Simultaneously, it uses time-series feature vectors to extract features reflecting the actual system operating state (such as latency patterns and error distributions) from dynamic runtime information (such as Span logs). By continuously comparing the preset indicators of the SLO targets (such as latency thresholds) with actual operating indicators (such as current average latency) and calculating their variance (e.g., slo_variance = (current latency - SLO threshold) / SLO threshold), when this variance exceeds a second dynamic threshold set based on historical baselines or system tolerance, a deviation in the second collaborative relationship is determined.
[0082] This mechanism enables continuous monitoring of the system's runtime performance and its alignment with code design expectations. It can promptly detect performance degradation caused by code implementation issues, resource contention, or environmental changes, providing precise trigger signals for verifying system stability and fault tolerance.
[0083] In another embodiment, the step of detecting the deviation of the third collaborative relationship between the dynamic operation information and the external operation information based on the temporal feature vector and user behavior cluster features in the integrated state model includes: establishing an association model between user behavior clusters and runtime abnormal modes based on the temporal feature vector and the user behavior cluster features; and determining that the third collaborative relationship has deviated when the probability of any user behavior cluster triggering an abnormal mode exceeds a third dynamic threshold.
[0084] Association Model: A mathematical model used to characterize the causal or strong correlation between user behavior clusters and specific runtime anomaly patterns (such as error rate spikes, latency spikes, cascading failures). Probability of Triggering an Anomaly Pattern: The estimated likelihood, calculated using the association model, that the execution of a particular user behavior cluster will lead to a specific runtime anomaly pattern. Third Dynamic Threshold: A critical value used to determine whether the risk of user behavior triggering a runtime anomaly reaches an alert level.
[0085] This implementation specifically defines how to detect the collaborative deviation between user actions and system operating state. By analyzing the temporal feature vectors (representing historical runtime anomaly patterns) and user behavior cluster features (representing typical user action sequences) in the comprehensive state model, a correlation model is trained using machine learning methods (such as logistic regression and random forest). This model can predict the probability of triggering various runtime anomaly patterns based on real-time or near-line user behavior cluster features. When the model predicts that the probability of any user behavior cluster triggering an anomaly pattern exceeds a preset third dynamic threshold, a deviation in the third collaborative relationship is determined.
[0086] This mechanism can proactively discover complex fault scenarios that are difficult to cover during the testing phase but will be exposed in real user use, especially cascading faults on the service call chain caused by specific user operation sequences. It significantly improves the ability to detect hidden runtime defects and enhances the system's adaptability to real user behavior.
[0087] Based on the deviation detection results of the multi-dimensional collaborative relationship by the comprehensive state model, this application generates test cases in step 104 in the following ways: when it is determined that the first collaborative relationship has deviated, patch test cases are generated to cover the deviation paths of code changes and user behavior; when it is determined that the second collaborative relationship has deviated, risk-weighted test cases are generated to verify the fault tolerance of the system; when it is determined that the third collaborative relationship has deviated, user scenario verification test cases are generated to verify whether a specific user operation causes system abnormalities.
[0088] The first coordination relationship refers to the matching relationship that should exist between static structural information (code and its control flow) and external operational information (user behavior events). Deviations in this relationship are manifested in code changes not being covered by existing user behavior patterns.
[0089] Patch test cases: These are test cases specifically designed to cover and verify new execution paths or high-risk branches resulting from code changes.
[0090] The second coordination relationship refers to the expected conformity between static structural information (code design expectations) and dynamic operational information (actual system operation indicators). Deviations in this relationship manifest as abnormal fluctuations in the service level target during system operation.
[0091] Risk-weighted test cases: These are test cases designed to test the system’s fault tolerance and stability under stress or failure scenarios, and typically involve simulating abnormal conditions.
[0092] The third coordination relationship refers to the coordination relationship that should exist between dynamic operation information (internal system operation status) and external operation information (user operation sequence). Deviation of this relationship is manifested in the fact that a specific user operation mode will cause system abnormalities.
[0093] User scenario verification test cases: These are test cases that reproduce a specific user operation sequence or behavior pattern to verify whether it will trigger abnormal system functions or performance degradation.
[0094] This step is the execution phase of test case generation. It precisely triggers and executes the corresponding test case generation mechanism based on different types of deviations in collaborative relationships. Specifically: when a deviation is determined in the first collaborative relationship, patch test cases are generated by deriving input boundary values that can reach new or high-risk code branches using symbolic execution techniques and injecting chaotic engineering perturbations (such as network latency and service interruptions); when a deviation is determined in the second collaborative relationship, risk-weighted test cases are generated by constructing targeted fault injection scenarios (such as dependent service timeouts and resource exhaustion) based on a service dependency chain-based fault propagation model; when a deviation is determined in the third collaborative relationship, user scenario verification test cases are generated by establishing a correlation model between user behavior clusters and runtime exception patterns, and reproducing specific user operation sequences that are prone to causing system anomalies (such as service call chain timeouts and cascading failures).
[0095] Through the aforementioned categorized and precise test case generation mechanism, this application can automatically and promptly generate highly relevant verification test cases for specific collaborative risks occurring in different dimensions within the system. This enables effective coverage of complex defects caused by code changes, runtime anomalies, and the interplay of user behaviors, significantly improving the relevance of testing and the ability to ensure software quality.
[0096] Figure 3 This is a block diagram illustrating an embodiment of a test case generation device provided in this application. Figure 3 As shown, the device includes: The acquisition module 31 is used to acquire multi-dimensional state data of the system under test, including static structure information, dynamic operation information and external operation information. The first generation module 32 is used to generate a comprehensive state model characterizing the system under test based on the static structural information, the dynamic operation information and the external operation information. Detection module 33 is used to detect deviations in the collaborative relationship between any two pieces of information in the multi-dimensional state data based on the comprehensive state model. The second generation module 34 is used to generate test cases to verify the collaborative relationship when a deviation in the collaborative relationship between any two pieces of information is detected.
[0097] In one possible implementation, the first generation module is specifically used for: The static structural information is parsed to generate a control flow graph, and the structural features of each node in the control flow graph are extracted using a graph neural network to obtain the control flow graph node features; The service call sequence in the dynamic operation information is time-series encoded to obtain a time-series feature vector; Cluster analysis is performed on the external operation information to obtain user behavior cluster features; The comprehensive state model is generated based on the control flow graph node features, the temporal feature vector, and the user behavior cluster features.
[0098] In one possible implementation, the detection module is specifically used for: Based on the control flow graph node features and user behavior cluster features in the integrated state model, the deviation of the first collaborative relationship between the static structure information and the external operation information is detected; or; Based on the control flow graph node features and temporal feature vectors in the integrated state model, the deviation of the second collaborative relationship between the static structure information and the dynamic operation information is detected; or; Based on the temporal feature vector and user behavior cluster features in the comprehensive state model, the deviation of the third collaborative relationship between the dynamic operation information and the external operation information is detected.
[0099] In one possible implementation, the detection module is further configured to: Based on the control flow graph node features and the user behavior cluster features, calculate the impact weight of code changes and the frequency of user behavior coverage; Calculate the first deviation score based on the weight of the impact of the code change and the frequency of user behavior coverage; If the first deviation score exceeds the first dynamic threshold, it is determined that the first collaborative relationship has deviated.
[0100] In one possible implementation, the detection module is further configured to: Based on the control flow graph node features and the time-series feature vector, the preset indicators of the service level target are compared with the actual operation indicators in the dynamic operation information; If the fluctuation of the actual operating indicator relative to the preset indicator exceeds the second dynamic threshold, it is determined that the second collaborative relationship has deviated.
[0101] In one possible implementation, the detection module is further configured to: Based on the time-series feature vector and the user behavior cluster features, a correlation model between user behavior clusters and runtime abnormal patterns is established. If the probability of triggering an abnormal mode in any user behavior cluster exceeds the third dynamic threshold, it is determined that the third collaborative relationship has deviated.
[0102] In one possible implementation, the second generation module is specifically used for: If a deviation is determined in the first collaboration relationship, a patch use case is generated to cover the path of code change and user behavior deviation; If a deviation is found in the second collaborative relationship, risk-weighted test cases are generated to verify the system's fault tolerance. If a deviation is found in the third collaborative relationship, user scenario verification test cases are generated to verify whether a specific user operation causes a system anomaly.
[0103] In one possible implementation, the first generation module is further configured to: Based on the historical records of the external operation information, the frequency of occurrence of different operation events is statistically analyzed; Based on predefined business rules, determine the business criticality weight of different operational events; Calculate the radius parameter for cluster analysis based on the frequency of occurrence of the events and the business criticality weights; Based on the radius parameter, clustering operations are performed on the operation events in the external operation information to generate user behavior clusters; Extract the user behavior cluster features from the user behavior cluster.
[0104] like Figure 4 As shown in the figure, this application provides a device including a processor 111, a communication interface 112, a memory 113, and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114. Memory 113 is used to store computer programs; In one embodiment of this application, when the processor 111 executes the program stored in the memory 113, it implements the test case generation method provided in any of the foregoing method embodiments, including: Acquire multi-dimensional state data of the system under test, including static structural information, dynamic operation information and external operation information; Based on the static structural information, the dynamic operational information, and the external operational information, a comprehensive state model is generated to characterize the system under test. Based on the comprehensive state model, the deviation of the collaborative relationship between any two pieces of information in the multi-dimensional state data is detected; If a deviation in the collaborative relationship between any two pieces of information is detected, test cases are generated to verify the collaborative relationship.
[0105] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the test case generation method provided in any of the foregoing method embodiments.
[0106] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0107] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0108] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “described” as used herein may also include the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.
[0109] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A test case generation method, characterized in that, The method includes: Acquire multi-dimensional state data of the system under test, including static structural information, dynamic operation information and external operation information; Based on the static structural information, the dynamic operational information, and the external operational information, a comprehensive state model is generated to characterize the system under test. Based on the comprehensive state model, the deviation of the collaborative relationship between any two pieces of information in the multi-dimensional state data is detected; If a deviation in the collaborative relationship between any two pieces of information is detected, test cases are generated to verify the collaborative relationship.
2. The method according to claim 1, characterized in that, The step of generating a comprehensive state model characterizing the system under test based on the static structural information, the dynamic operational information, and the external operational information includes: The static structural information is parsed to generate a control flow graph, and the structural features of each node in the control flow graph are extracted using a graph neural network to obtain the control flow graph node features; The service call sequence in the dynamic operation information is time-series encoded to obtain a time-series feature vector; Cluster analysis is performed on the external operation information to obtain user behavior cluster features; The comprehensive state model is generated based on the control flow graph node features, the temporal feature vector, and the user behavior cluster features.
3. The method according to claim 2, characterized in that, The step of detecting deviations in the collaborative relationship between any two pieces of information in the multi-dimensional state data based on the comprehensive state model includes: Based on the control flow graph node features and user behavior cluster features in the integrated state model, the deviation of the first collaborative relationship between the static structure information and the external operation information is detected; or; Based on the control flow graph node features and temporal feature vectors in the integrated state model, the deviation of the second collaborative relationship between the static structure information and the dynamic operation information is detected; or; Based on the temporal feature vector and user behavior cluster features in the comprehensive state model, the deviation of the third collaborative relationship between the dynamic operation information and the external operation information is detected.
4. The method according to claim 3, characterized in that, The step of detecting deviations in the first collaborative relationship between the static structural information and the external operational information based on the control flow graph node features and user behavior cluster features in the integrated state model includes: Based on the control flow graph node features and the user behavior cluster features, calculate the impact weight of code changes and the frequency of user behavior coverage; Calculate the first deviation score based on the weight of the impact of the code change and the frequency of user behavior coverage; If the first deviation score exceeds the first dynamic threshold, it is determined that the first collaborative relationship has deviated.
5. The method according to claim 3, characterized in that, The step of detecting the deviation of the second collaborative relationship between the static structural information and the dynamic operational information based on the control flow graph node features and temporal feature vectors in the integrated state model includes: Based on the control flow graph node features and the time-series feature vector, the preset indicators of the service level target are compared with the actual operation indicators in the dynamic operation information; If the fluctuation of the actual operating indicator relative to the preset indicator exceeds the second dynamic threshold, it is determined that the second collaborative relationship has deviated.
6. The method according to claim 3, characterized in that, The step of detecting the deviation of the third collaborative relationship between the dynamic operation information and the external operation information based on the temporal feature vector and user behavior cluster features in the comprehensive state model includes: Based on the time-series feature vector and the user behavior cluster features, a correlation model between user behavior clusters and runtime abnormal patterns is established. If the probability of triggering an abnormal mode in any user behavior cluster exceeds the third dynamic threshold, it is determined that the third collaborative relationship has deviated.
7. The method according to claim 3, characterized in that, The step of generating test cases to verify the collaborative relationship when a deviation is detected between any two pieces of information includes: If a deviation is determined in the first collaboration relationship, a patch use case is generated to cover the path of code change and user behavior deviation; If a deviation is found in the second collaborative relationship, risk-weighted test cases are generated to verify the system's fault tolerance. If a deviation is found in the third collaborative relationship, user scenario verification test cases are generated to verify whether a specific user operation causes a system anomaly.
8. The method according to claim 2, characterized in that, The clustering analysis of the external operation information to obtain user behavior cluster features includes: Based on the historical records of the external operation information, the frequency of occurrence of different operation events is statistically analyzed; Based on predefined business rules, determine the business criticality weight of different operational events; Calculate the radius parameter for cluster analysis based on the frequency of occurrence of the events and the business criticality weights; Based on the radius parameter, clustering operations are performed on the operation events in the external operation information to generate user behavior clusters; Extract the user behavior cluster features from the user behavior cluster.
9. A test case generation device, characterized in that, The device includes: The acquisition module is used to acquire multi-dimensional state data of the system under test, including static structure information, dynamic operation information and external operation information. The first generation module is used to generate a comprehensive state model characterizing the system under test based on the static structural information, the dynamic operation information and the external operation information. The detection module is used to detect deviations in the collaborative relationship between any two pieces of information in the multi-dimensional state data based on the comprehensive state model. The second generation module is used to generate test cases to verify the collaborative relationship when a deviation is detected between any two pieces of information.
10. An electronic device, characterized in that, include: A processor and a memory, the processor being configured to execute a test case generation program stored in the memory to implement the test case generation method according to any one of claims 1-8.
11. A storage medium, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the test case generation method according to any one of claims 1-8.
