Front-end code testing method and system, electronic equipment and storage medium
Through the code analysis system, the test cases are automatically generated using deep neural networks and heuristic search algorithms, solving the problem of front-end code testing relying on manual labor, and achieving efficient and accurate automated testing and repair.
Patent Information
- Application Number
- CN202510505951.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-22
- Publication Date
- 2025-07-25
AI Technical Summary
The existing front-end code testing methods rely on manual inspection, resulting in low testing efficiency and accuracy, making it difficult to exhaust all possible test paths, and easily miss critical branches or abnormal situations.
The code analysis system is adopted, and the target test cases are automatically generated using deep neural network models and heuristic search algorithms, and error detection is carried out in combination with code feature vectors to realize automated testing and repair.
Improves the efficiency and accuracy of front-end code testing, can efficiently capture defects and output accurate and reliable test results, and automatically fix code errors.
Smart Images

Figure CN120371710A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, system, electronic device, and storage medium for testing front-end code. Background Art
[0002] In the field of front-end development, the front-end interface undertakes important responsibilities such as user interaction, information display, and receiving user operation instructions. Therefore, in the process of creating the front-end interface, it is necessary to improve the quality of the front-end code. When errors occur in the front-end code, problems can be quickly discovered and fixed to ensure the reliability of the product.
[0003] However, the current testing methods for front-end code are generally unit testing or integration testing. Although these testing methods can detect errors in the front-end code to a certain extent, they highly rely on developers to manually check the code, resulting in low testing efficiency and testing accuracy of the front-end code. Summary of the Invention
[0004] To solve or partially solve the problems existing in the related art, this application provides a method, system, electronic device, and storage medium for testing front-end code, which can improve the testing efficiency and testing accuracy of the front-end code.
[0005] The first aspect of this application provides a method for testing front-end code, which is applied to a code analysis system and includes: Receiving a code testing task for the front-end code to be tested, where the code testing task includes use case constraint conditions and test target information of the front-end code to be tested; Extracting a code feature vector from the front-end code to be tested; Iteratively generating target test cases according to the use case constraint conditions and the test target information; Obtaining the test result of the front-end code to be tested by running the target test cases and error-detecting the code feature vector.
[0006] In one example, the obtaining the test result of the front-end code to be tested by running the target test cases and error-detecting the code feature vector includes: Running the target test cases to obtain running data; and, Performing error detection on the code feature vector and outputting prediction data; Fusing the running data and the prediction data to obtain the test result of the front-end code to be tested.
[0007] In one example, the running the target test cases to obtain running data includes: Obtaining the test environment information of the target test cases; Configure a simulation environment based on the test target information and the test environment information; Run the target test case in the simulation environment, collect the running logs and behavior data, and use the running logs and behavior data as the running data.
[0008] In one example, the prediction data includes one or more of first prediction data, second prediction data, and third prediction data. The error detection of the code feature vector and the output of the prediction data include: Perform static analysis and dynamic monitoring on the code feature vector, and output the first prediction data; Compare the code feature vector with a known error feature vector, and output the second prediction data; Perform a suspiciousness evaluation on the code feature vector, and output the third prediction data.
[0009] In one example, the data fusion of the running data and the prediction data to obtain the test result of the front-end code to be tested includes: Fuse the running data and the prediction data through a fully connected layer or an attention mechanism to obtain the test result of the front-end code to be tested; Wherein, the test result includes an error code segment, and the error type and error degree corresponding to the error code segment.
[0010] In one example, the iterative generation of the target test case according to the use case constraint condition and the test target information includes: Define a search space through the code feature vector and the test target information; Input the code feature vector into a preset test case generation model, and the test case generation model outputs a number of candidate test cases; In the search space, perform a quality evaluation on the candidate test cases according to the use case constraint condition to obtain a heuristic function value; Determine the candidate test cases with the heuristic function value less than a preset threshold as the target test cases.
[0011] In one example, the method further includes: If the test result is that the front-end code to be tested is incorrect, extract the error code segment from the test result, and the error type and error degree corresponding to the error code segment; Automatically repair the error code segment based on the error type and the error degree to generate a front-end code to be verified; Determine the front-end code to be verified that passes the verification as the repaired front-end code.
[0012] The second aspect of the present application provides a code analysis system, including: A test task receiving module, configured to receive a code test task for the front-end code to be tested, where the code test task includes use case constraint conditions and test target information of the front-end code to be tested; A feature vector extraction module, configured to extract a code feature vector from the front-end code to be tested; A test case generation module, configured to iteratively generate target test cases according to the use case constraint conditions and the test target information; A test module, configured to obtain a test result of the front-end code to be tested by running the target test cases and error-detecting the code feature vector.
[0013] The third aspect of the present application provides an electronic device, including: A processor; and A memory, on which executable code is stored, and when the executable code is executed by the processor, the processor is caused to execute the method as described above.
[0014] The fourth aspect of the present application provides a computer-readable storage medium, on which executable code is stored, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the method as described above.
[0015] The fifth aspect of the present application provides a computer program product, where the computer program product includes computer instructions, and when the computer instructions are executed by a processor, the method as described above is implemented.
[0016] The technical solution provided by the present application may include the following beneficial effects: In the embodiments of the present application, applied to a code analysis system, the method includes: receiving a code test task for the front-end code to be tested, where the code test task includes use case constraint conditions and test target information of the front-end code to be tested, extracting a code feature vector from the front-end code to be tested, iteratively generating target test cases according to the use case constraint conditions and the test target information, and obtaining a test result of the front-end code to be tested by running the target test cases and error-detecting the code feature vector.
[0017] In the present application, when the code analysis system receives a code test task, it automatically parses the use case constraint conditions and test target information of the front-end code to be tested, so as to iteratively generate target test cases with strong pertinence by combining the test target information and the use case constraint conditions. And, after extracting an effective code feature vector from the front-end code to be tested, by running the target test cases generated in real time and error-detecting the code feature vector, defects of the front-end code to be tested can be efficiently and comprehensively captured, so as to output accurate and reliable test results.
[0018] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and do not limit this application. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] By describing the exemplary embodiments of this application in more detail in conjunction with the accompanying drawings, the above and other objects, features, and advantages of this application will become more apparent. Among them, in the exemplary embodiments of this application, the same reference numerals generally represent the same components.
[0020] Figure 1 is a schematic flowchart of a method for testing front-end code shown in an embodiment of this application; Figure 2 is another schematic flowchart of a method for testing front-end code shown in an embodiment of this application; Figure 3 is a schematic structural diagram of a code analysis system shown in an embodiment of this application; Figure 4 is a schematic structural diagram of an electronic device shown in an embodiment of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0021] The embodiments of this application will be described in more detail below with reference to the accompanying drawings. Although the embodiments of this application are shown in the drawings, it should be understood that this application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to make this application more thorough and complete, and to fully convey the scope of this application to those skilled in the art.
[0022] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms "a", "the", and "said" used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0023] It should be understood that although the terms "first", "second", "third", etc. may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of this application, "a plurality" means two or more unless otherwise specifically defined.
[0024] In the field of front - end development, the front - end interface undertakes important responsibilities such as user interaction, information display, and receiving user operation instructions. Therefore, in the process of creating the front - end interface, it is necessary to improve the quality of front - end code. When errors occur in the front - end code, it is possible to quickly discover and fix problems to ensure the reliability of the product.
[0025] However, the current testing methods for front - end code are generally unit testing or integration testing. Although these testing methods can detect errors in front - end code to a certain extent, they rely on developers to manually check the code, resulting in low testing efficiency and accuracy of front - end code testing.
[0026] For example, in the traditional front - end code testing process, the writing and maintenance of test cases highly depend on manual completion by users. This testing process is not only cumbersome and time - consuming, but also easily affected by human omissions, resulting in low efficiency and unstable quality.
[0027] Moreover, in the face of complex front - end logic structures and diverse user interaction scenarios, traditional front - end code testing methods are difficult to exhaust all possible test paths, easily missing key branches or abnormal situations, resulting in insufficient test coverage.
[0028] In view of the above problems, the embodiments of the present application provide a testing method for front - end code, which can efficiently and comprehensively capture the defects of the front - end code to be tested and output accurate and reliable test results.
[0029] The following details the technical solutions of the embodiments of the present application with reference to the accompanying drawings.
[0030] Figure 1 is a schematic flowchart of a testing method for front - end code shown in the embodiments of the present application.
[0031] See Figure 1 , which is applied to a code analysis system. The method at least includes the following steps: In the present application, the code analysis system is an automatic testing and automatic repair system for front - end code. This system integrates a variety of deep neural network models and a variety of search algorithms, and can accurately identify potential errors and problems in front - end code and provide high - quality repair suggestions.
[0032] Step 101, receive a code testing task for the front - end code to be tested. The code testing task includes use - case constraint conditions and test target information of the front - end code to be tested.
[0033] In the embodiments of the present application, the code analysis system can receive a code testing task for the front - end code to be tested.
[0034] The front-end code to be tested refers to the front-end code that needs to be run on the client (such as a browser). This code may be part of the development, updated code, or existing code, usually including HTML (HyperTextMarkup Language, Hypertext Markup Language), CSS (Cascading Style Sheets, Cascading Style Sheets), JavaScript (JavaScript, programming language), etc., which is mainly used to build user interfaces, process user input, and present data.
[0035] A code testing task refers to a test request for the front-end code to be tested, which is used to trigger the code analysis system to start the test, and includes at least the use case constraints and test target information of the front-end code to be tested.
[0036] Use case constraints refer to specific restrictions that need to be met when generating test cases, which can ensure that the generated test cases meet the predetermined test objectives and test scenarios.
[0037] Test target information refers to the test target and test scope set for code testing. For example, test target information includes the function type, user interaction behavior, performance requirements, etc. of the front-end code to be tested.
[0038] Step 102: extracting a code feature vector from the front-end code to be tested.
[0039] In an embodiment of the present application, the code analysis system improves the efficiency of subsequent testing by extracting effective code feature vectors from the front-end code to be tested.
[0040] The code feature vector may be grammatical, semantic or structural information extracted from the code, or may be statistical information based on historical test data, which is used to represent the characteristics of the code or test data.
[0041] Step 103, iteratively generate target test cases according to the use case constraints and the test target information.
[0042] In an embodiment of the present application, after the code analysis system obtains the use case constraints and test target information from the code testing task, it can iteratively generate a target test case corresponding to the code feature vector based on the use case constraints and test target information.
[0043] Among them, the target test case refers to the test case used to verify whether the front-end code works as expected under specific test scenarios or conditions. In this application, the test cases are automatically generated and optimized by a heuristic search algorithm combined with a deep neural network model, covering multiple test strategies such as user interaction, boundary conditions, and exception handling.
[0044] Step 104: Obtain the test result of the front-end code to be tested by running the target test case and the error detection code feature vector.
[0045] In the embodiment of the present application, the process of the code analysis system testing the front-end code to be tested includes: running the target test case and the error detection code feature vector. Among them, by running the target test case, the running data of the front-end code to be tested can be obtained, and by the error detection code feature vector, the defects of the front-end code to be tested can be analyzed to generate prediction data. Finally, the test result of the front-end code to be tested is obtained by combining the data of running the target test case and the error detection code feature vector.
[0046] Among them, the test result refers to the comprehensive output obtained by running the target test case and the error detection code feature vector.
[0047] In the embodiment of the present application, when applied to the code analysis system, the method includes: receiving a code test task for the front-end code to be tested, where the code test task includes the use case constraint conditions and test target information of the front-end code to be tested, extracting the code feature vector from the front-end code to be tested, iteratively generating the target test case according to the use case constraint conditions and test target information, and obtaining the test result of the front-end code to be tested by running the target test case and the error detection code feature vector.
[0048] In the present application, when the code analysis system receives a code test task, it automatically parses the use case constraint conditions and test target information of the front-end code to be tested, so as to iteratively generate a highly targeted target test case by combining the test target information and the use case constraint conditions. And, after extracting the effective code feature vector from the front-end code to be tested, by running the target test case generated in real time and performing error detection on the code feature vector, the defects of the front-end code to be tested can be efficiently and comprehensively captured, thereby outputting accurate and reliable test results.
[0049] Figure 2 It is another schematic flowchart of a method for testing front-end code shown in the embodiment of the present application. Figure 2 Relative Figure 1 It describes the technical solution of the embodiment of the present application in more detail.
[0050] To facilitate the understanding of the method for testing front-end code in the embodiment of the present application, the code analysis system in the embodiment of the present application will be described in detail below.
[0051] In the present application, the code analysis system mainly consists of a test case generation model, a code quality prediction model (CodeQuality Prediction Model), a heuristic search algorithm (Heuristic Search Algorithm), and a code repair model.
[0052] Among them, the test case generation model, the code quality prediction model, and the code repair model are all models obtained after training based on a deep neural network (DNN). A deep neural network is a multi-layer neural network model that can process complex data relationships and learn features and patterns from a large amount of data by mimicking the connection method of human brain neurons.
[0053] In this application, the test case generation model is a model that automatically generates a set of candidate test cases according to the characteristics of the front-end code to be tested, the test target information, and the code context. This model uses a deep neural network to learn the mapping relationship from code features to test cases.
[0054] As an optional example of this application, the construction process of the test case generation model can be as follows: Input layer: The input layer receives the feature vectors extracted from the code. These features can include syntax structure, function call relationship, variable usage pattern, etc. The feature extraction process can be implemented through a static analysis tool or a custom script to represent the structure and behavior of the code as a numerical vector suitable for neural network processing.
[0055] Hidden layer: The hidden layer consists of multiple neurons and is used to process the input feature vectors to extract higher-level abstract features. The number of hidden layers and the number of neurons in each layer can be optimized and adjusted according to the complexity of the task and the amount of data.
[0056] Output layer: The output layer generates specific test cases or outputs the generation strategy of test cases, aiming to meet specific test targets. Depending on the test targets, the output layer can be designed to generate test cases covering specific code paths, detect potential errors, or verify the correctness of certain functions, etc.
[0057] During the model training process, a large number of historical code samples and corresponding test cases are used as training data to train the deep neural network model. By training the deep neural network model, the model can learn the complex mapping relationship between code features and test case generation strategies, and then automatically generate new test cases.
[0058] In this application, the code quality prediction model can predict potential errors and performance bottlenecks based on the code feature vector of the front-end code to be tested, so as to perform quality assessment and error prediction on the front-end code to be tested.
[0059] As an optional example of this application, the training process of the code quality prediction model includes selecting a suitable deep neural network architecture, such as Convolutional Neural Network (CNN), Long Short-Term Memory Network (LSTM), and making targeted adjustments to the deep neural network structure. The content of the targeted adjustments includes: 1) Feature extraction and representation Input layer design: According to the characteristics of the front-end code, design a suitable input layer structure, such as converting the code into a sequence of word vectors, an abstract syntax tree representation, or a combination of multiple feature representations.
[0060] Convolutional layer design: For local features in the code (such as function definitions, variable declarations, etc.), design convolutional kernels of different sizes and strides to capture these features.
[0061] Pooling layer design: Use methods such as max pooling or average pooling to downsample the output of the convolutional layer to reduce the computational amount and extract the main features.
[0062] 2) Data preprocessing and cleaning Code standardization: Remove comments, whitespace characters, and formatting differences in the code to make the code structure uniform.
[0063] Variable name normalization: Replace variable names with unified identifiers to eliminate the impact of variable names on model learning.
[0064] Removal of irrelevant information: Delete code parts that are irrelevant to error location and repair, such as third-party library references, global variable declarations, etc.
[0065] 3) Model training and optimization Loss function design: According to the requirements of the test task, design a suitable loss function, such as cross-entropy loss, mean squared error loss, etc.
[0066] Optimization algorithm selection: Select a suitable optimization algorithm, such as Adam (Adaptive Moment Estimation), SGD (Stochastic Gradient Descent), etc., and adjust parameters such as the learning rate and momentum.
[0067] Overfitting handling: Use methods such as data augmentation, dropout (neuron random dropout technique), regularization, etc. to prevent the model from overfitting.
[0068] Furthermore, in the model training and optimization stage, the historical code library and known error cases are used as training data to train the adjusted deep neural network, so as to obtain a code quality prediction model.
[0069] In this application, the code repair model can automatically generate repair code according to the defect type of the front-end code to be tested.
[0070] As an optional example of this application, the training process of the code repair model includes: 1) Data preparation and annotation Collect a large amount of historical data containing error codes and their repair suggestions.
[0071] Clean and preprocess the data to ensure the accuracy and integrity of the data.
[0072] Annotate the error codes to clarify the type and location of the errors.
[0073] 2) Model selection and construction Select a suitable deep learning model according to the task requirements, such as a convolutional neural network, a recurrent neural network, or a Seq2Seq model (Sequence to Sequence model), etc.
[0074] Build the corresponding network structure according to the characteristics of the model and set appropriate hyperparameters.
[0075] 3) Training and optimization Use the labeled dataset to train the model.
[0076] Iteratively optimize and adjust the model parameters to minimize the difference between the predicted output and the true output.
[0077] Use the validation set to evaluate the model and tune the model according to the evaluation results.
[0078] 4) Deployment and application Deploy the trained model to the actual application.
[0079] Collect feedback data in the actual application and use it to further optimize the model.
[0080] It can be understood that the deep neural network model in the code analysis system learns the features and rules of the code from a large amount of data. These features may include the syntax structure of the code, variable naming habits, common error patterns, etc. Therefore, when locating errors and proposing repair suggestions, the code analysis system can automatically detect errors in the front-end code and generate corresponding repair suggestions by analyzing the syntax structure, context dependencies, and dynamic behavior of the code.
[0081] In this application, the heuristic search algorithm is a search method based on heuristic information. It utilizes information related to the specific problem-solving to guide the search process, aiming to reduce the search scope and lower the problem complexity. It includes genetic algorithms, ant colony algorithms, simulated annealing, etc. The heuristic search algorithm can generate high-quality test cases under constraints, explore the optimal samples in the test case space, and guide the model to generate more comprehensive and boundary test content.
[0082] Generally speaking, the core design process of the heuristic search algorithm is first to clarify the problem and define the goal, identify the target node and the starting node of the search, and determine the search space, where the search space contains all possible states and paths. Then, design a heuristic function according to the problem characteristics to evaluate the distance or cost between the current state and the target state. The design of the heuristic function directly affects the efficiency and effect of the search. Estimation methods such as Manhattan distance and Euclidean distance can be used to evaluate test cases. The smaller the value of the heuristic function, the closer it is to the target node.
[0083] On this basis, the heuristic search algorithm will first create a search queue and add the starting node to the queue. The search queue usually uses a priority queue or other data structures to store the nodes to be expanded and sorts the nodes according to the evaluation value of the heuristic function. The heuristic search algorithm can select nodes from the queue for expansion, update the data structure of the expanded nodes by evaluating the heuristic value of each expanded node, and store it for subsequent comparison and selection.
[0084] The heuristic search algorithm usually selects nodes based on the heuristic value during the search, usually selects the node with the smallest value for expansion, and gradually approaches the target node. After each expansion, update the search state, mark the expanded nodes, and readjust the search queue. This process continues until the target node is found or the queue is empty. During the processing, some special situations need to be considered, such as infinite loops and duplicate nodes. By introducing pruning techniques and dynamically adjusting the heuristic function, the search efficiency can be optimized to ensure that the algorithm finds the target solution in a short time.
[0085] As an optional example of this application, in order to better apply the heuristic search algorithm to the testing of front-end code, the heuristic search algorithm has been specifically adjusted. The adjusted content includes: 1) Definition of the search space Code transformation operations: Define a series of possible code transformation operations, such as variable renaming, statement rearrangement, conditional statement modification, etc.
[0086] Representation of the search state: Use a suitable data structure to represent the search state, such as AST, code snippet, or feature vector.
[0087] 2) Design of the heuristic function Rule - based heuristics: Based on code syntax and semantic rules, design a heuristic function to evaluate the quality of the search state.
[0088] Learning - based heuristics: Use machine learning models (such as neural networks) to learn the heuristic function for more accurate evaluation of the search state.
[0089] 3) Search strategy selection Breadth - first search: Traverse the search space layer by layer until a solution that meets the conditions is found.
[0090] Depth - first search: Search deeply along a path until a solution is found or the search depth limit is reached.
[0091] A* search: Combine the heuristic function and the cost function to select the optimal path for search.
[0092] 4) Search termination conditions Finding a solution: When a solution that meets the conditions is found, terminate the search.
[0093] Reaching the search limit: When the search reaches the preset time, number of iterations, or memory limit, terminate the search.
[0094] 5) Evaluation and verification Syntax checking: Ensure that the generated code conforms to the syntax rules.
[0095] Semantic checking: Verify whether the generated code meets the functional requirements through static analysis or dynamic monitoring.
[0096] Performance evaluation: Evaluate the running performance of the generated code, such as execution time, memory occupancy, etc.
[0097] As an example, the genetic algorithm is selected as the heuristic search algorithm. Its design process can be as follows: Encode the test case parameters (such as input values, operation sequences) as chromosomes, using real - number or binary encoding. Design a fitness function based on code feature vectors (such as branch coverage rate, boundary condition trigger rate), and preferentially select test cases with high coverage. Generate new individuals through selection (roulette wheel, tournament), crossover (single - point / multi - point), and mutation (random perturbation), and gradually optimize the test case set. Set the maximum number of iterations or the fitness convergence threshold, stop the search, and output the optimal solution.
[0098] This application designs a test case generation model, a code quality prediction model, a heuristic search algorithm, and a code repair model suitable for front - end code testing, enabling the code analysis system to have the ability to perform preliminary quality assessment and error prediction on front - end code using a deep neural network model, automatically explore using a deep neural network model and a heuristic search algorithm, and apply effective repair strategies for automated repair.
[0099] In addition, the code analysis system is also integrated with front-end development tools and the testing workflow respectively.
[0100] Among them, the front-end development tools include IDE (Integrated Development Environment) plugins and front-end build tools.
[0101] The IDE plugins can provide functions such as generating test cases with one click, automatically executing tests, and displaying test results, enabling users to conduct tests while writing code. They include development plugins such as Visual Studio Code and WebStorm, directly embedding the functions of the code analysis system into the IDE.
[0102] The front-end build tools include the integration of build tools such as Webpack and Gulp. Integrating the code analysis system with the front-end build tools enables the code analysis system to automatically execute tests during the build process, ensuring that the code built each time has been fully tested. Moreover, by configuring the build script, the execution timing and scope of the tests can be flexibly controlled.
[0103] Among them, the testing workflow includes the CI / CD process (Continuous Integration / Continuous Deployment process) and the version control system.
[0104] By integrating the code analysis system into the CI / CD process, the code analysis system can be automatically triggered to perform tests when code is committed, merged, or released. Also, by configuring the build tasks in CI / CD tools such as Jenkins, GitLab CI / CD (Continuous Integration / Continuous Delivery), and Travis CI (cloud-based continuous integration service), test cases can be automatically executed and test reports can be generated to assist users in quickly understanding the code quality.
[0105] By integrating the code analysis system with version control systems such as Git (distributed version control system), the code analysis system can track the change history of the code and automatically trigger tests each time code is committed, thus ensuring that each code change has been fully tested and reducing the risk of introducing new problems.
[0106] In addition, in order to enable users to more intuitively know the test content of the front-end code, the code analysis system provides convenient operation interfaces and visual interfaces to improve the user experience.
[0107] As an example, the code analysis system provides a graphical user interface and a command-line interface.
[0108] The graphical user interface enables users to simply click and drag operations to configure and execute tests, and presents rich chart and report functions to users, helping them intuitively understand test results and code quality.
[0109] The command-line interface facilitates users to execute tests through command-line tools, presents rich parameters and options to users, supports flexible configuration of test execution parameters and options, and meets user requirements.
[0110] Through the foregoing training process and design process, a code analysis system for front-end code testing can be obtained. Before being officially used for front-end code testing, this application further verifies the code analysis system and uses the verified code analysis system in actual tests.
[0111] As an example, the verification process first collects test data from multiple projects and different versions of front-end code. To ensure the diversity and representativeness of the data, the selected projects cover different scales, complexities, and business domains. After data collection is completed, preprocessing is performed on the original code data, including cleaning irrelevant information, removing noise interference, and annotating potential error locations to ensure the accuracy and availability of the data.
[0112] Subsequently, a comparative experiment is designed to conduct a comparative analysis of the test and repair processes of this system and traditional methods, focusing on evaluating the performance of this system in key indicators such as test case coverage rate, error location accuracy rate, recall rate, and code stability after repair.
[0113] Finally, the experimental data is analyzed through methods such as statistical significance testing to ensure that the results are credible and statistically significant, thereby verifying the effectiveness and advantages of the system in actual applications.
[0114] The following elaborates in detail the data processing process of the code analysis system in actual tests in combination with the foregoing relevant content.
[0115] Step 201: Receive a code test task for the front-end code to be tested. The code test task includes use case constraint conditions and test target information of the front-end code to be tested.
[0116] In the embodiment of this application, when a user submits the front-end code to be tested in the user interface provided by the code analysis system, the code analysis system automatically generates a code test task for the front-end code to be tested and obtains the use case constraint conditions and test target information of the front-end code to be tested.
[0117] In this application, use case constraints can be a series of pre-set boundary, termination, structure, performance, and business logic rules, aiming to limit the scope, quality, and quantity of generated test cases, ensuring that the generated test cases not only meet the test objectives but also do not produce invalid or redundant data. For example, use case constraints include the termination conditions of heuristic search algorithms, test boundary conditions, and business logic.
[0118] The test target information is information related to the testing of the front-end code to be tested. For example, the test target information includes the function type, user interaction behavior, performance requirements, etc. of the front-end code to be tested.
[0119] As an example, the user uploads the front-end code to be tested in a certain front-end project to the user interface. At this time, the code analysis system automatically triggers a code testing task and obtains pre-configured use case constraints such as "search time consumption" and "number of traversed nodes", as well as test target information such as "whether the correct event or response is triggered after the user clicks a certain button" and "whether the page loading time is within a reasonable range".
[0120] Step 202: Extract code feature vectors from the front-end code to be tested.
[0121] In the embodiments of this application, the code analysis system uses different code parsing methods for different code files in the front-end project, but essentially extracts key features such as page structure, style rules, and function definitions from the front-end code to be tested, and constructs code feature vectors using the key features.
[0122] As an example, HTML files can be used to extract structured information through a DOM (Document Object Model) parser or XPat (XML Path Language). Among them, commonly used tools include BeautifulSoup, which is suitable for web crawlers and DOM operations, and can efficiently and accurately extract HTML elements and their attributes, facilitating tasks such as page content scraping, data extraction, and page structure analysis.
[0123] CSS files can be used to analyze style rules through a CSS parser or an abstract syntax tree tool. Among them, commonly used tools include PostCSS, which is suitable for the refactoring and processing of style code, and can perform operations such as static analysis, code optimization, and automated conversion on styles.
[0124] JavaScript files can be used to extract code structure and logic through an AST parser or a dynamic analysis tool to achieve static analysis and code conversion. For example, Esprima, Puppeteer, etc.
[0125] As another example, after extracting the key features from the front-end code to be tested, converting the key features into code feature vectors helps the code analysis system to process them.
[0126] For HTML files, parse the DOM tree and count the tag types (such as 、 ), structural information such as hierarchical depth and parent-child relationships, and convert them into code feature vectors. For example, {"div_count": 5, "span_count": 3, "max_depth": 4}.
[0127] For CSS files, analyze the style rules in the style sheet, such as colors and fonts, and identify selector types, such as class selectors and ID selectors, and convert them into code feature vectors. For example, {"color_rules": 10, "class_selectors": 5, "id_selectors": 1}.
[0128] For JavaScript files, extract function definitions, variable declarations, and control flow structures (such as if and for), and convert them into code feature vectors. For example, {"function_count": 8, "loop_count": 3, "async_usage": True}.
[0129] This application converts the source code of the front-end project into structured and analyzable feature vector data through step 202, which is convenient for subsequent model use and significantly improves the efficiency of front-end code testing.
[0130] Step 203, iteratively generate target test cases according to the use case constraint conditions and test target information.
[0131] In the embodiment of this application, the process of iteratively generating target test cases according to the use case constraint conditions and test target information includes: defining a search space through the code feature vectors and test target information, inputting the code feature vectors into a preset test case generation model, and the test case generation model outputs several candidate test cases. In the search space, the quality of the candidate test cases is evaluated according to the use case constraint conditions to obtain a heuristic function value, and the candidate test cases with a heuristic function value less than the preset threshold are determined as the target test cases.
[0132] As an optional example of this application, in the process of generating target test cases, the code analysis system can use static analysis tools or custom scripts to extract code feature vectors such as code snippets, syntax structures, function call patterns, and variable usage, and then combine the extracted code feature vectors with test target information such as functional requirements, performance requirements, and user interaction expectations of the test to obtain a search space. For example, the defined search space is: "Select the code path related to the rendering of the navigation bar and the click of menu items", "Enter a legal email and a strong password, click Submit, and verify whether it successfully jumps to the operation page", etc.
[0133] Then, input the code feature vector into a preset test case generation model. The test case generation model evaluates the similarity or difference of different test cases based on the code feature vector, discovers potential test scenarios or boundary conditions, and then outputs several valid candidate test cases.
[0134] In the scenario of test case generation, the use case constraint conditions also include the heuristic information of the heuristic search algorithm, and the heuristic information may include data such as code coverage rate, error detection rate, and test execution time.
[0135] Furthermore, the code analysis system scores and ranks each candidate test case by using the heuristic function of the heuristic search algorithm and the use case constraint conditions, so as to quantify the adaptation degree of each candidate test case to the code feature vector.
[0136] Finally, after calculating the heuristic function value of each candidate test case, the code analysis system compares the heuristic function value with a preset threshold. When the heuristic function value is lower than the preset threshold, it indicates that the candidate test case has high adaptability and test value under the current use case constraint conditions and can more effectively detect potential defects in the front-end code to be tested. At the same time, it also means that redundant test cases and inefficient test cases are effectively filtered out, and only test cases with stronger coverage ability and error-triggering potential are retained.
[0137] As an example, the user inputs the front-end code or front-end code library to be tested, as well as test target information and use case constraint conditions. The code analysis system extracts key features by using a static analysis tool or a custom script and represents them as code feature vectors. Subsequently, the code feature vectors are input into a trained deep neural network model, and the deep neural network model outputs a set of test case generation strategies or specific candidate test cases.
[0138] It is worth noting that the candidate test cases cover a variety of test scenarios, including various test strategies such as user interaction, boundary conditions, and exception handling.
[0139] Among them, user interaction testing: By designing test cases to simulate user input and output, verify the response and processing capabilities of the front-end code under different input data. This process can use an automated test tool or manual testing to simulate user interaction.
[0140] Boundary condition testing: Determine the boundary conditions in the code, such as the maximum / minimum index of an array, the start and end conditions of a loop, etc. Design corresponding test cases to specifically check whether the front-end code can execute correctly under boundary conditions and avoid overflow, error, or exception situations.
[0141] Exception Handling Test: For possible exceptions such as division by zero error or null pointer exception, design test cases to verify whether the front-end code can correctly handle error situations and provide reasonable error messages or recovery measures.
[0142] Feature Vector Test: Based on the code feature vectors in the front-end code, such as the type and dimension of input data, design test cases to verify whether the front-end code can run properly and output correct results under different input feature vectors. This process can use randomly generated data sets or specific test cases to test the effectiveness of feature vectors.
[0143] Comprehensive Test: Combine the above-mentioned multiple test cases to build complex test scenarios and comprehensively evaluate the stability of the front-end code.
[0144] After obtaining the candidate test cases, the code analysis system designs a suitable heuristic function in combination with the test target information as the guiding basis for the search direction. The heuristic function is used to estimate the distance or cost from the current node to the target node. The smaller the value of the heuristic function, the closer it is to the target node. At the same time, define the search space according to the code features and test requirements to ensure the effectiveness and efficiency of the search process.
[0145] Next, select a suitable heuristic search algorithm according to the specific problem, such as genetic algorithm, simulated annealing algorithm, ant colony algorithm, etc. In the search space, use the heuristic search algorithm to continuously generate, screen and improve test cases through iterative optimization. During this period, the code analysis system can evaluate the quality or similarity of test cases using the distance or similarity between feature vectors.
[0146] Taking the genetic algorithm as an example, the process of generating and optimizing test cases by combining the heuristic search algorithm and the code feature vector includes: randomly generating a set of candidate test cases using the trained deep neural network model as the initial population. Each candidate test case represents its structural and behavioral characteristics through the corresponding feature vector, constituting an individual of the population. Execute each candidate test case, and evaluate the effectiveness or fitness of each candidate test case based on the output result or by analyzing the feature vector. The fitness can be comprehensively scored based on multi-dimensional criteria such as test coverage, error-triggering ability, and similarity to the target test features. According to the fitness score, use methods such as roulette wheel selection and tournament selection to select the test cases with higher fitness from the current population as the parents. The parents generate new generations of test case individuals through crossover operations (such as swapping code segments, recombining input parameters, etc.). To maintain the diversity of the population, the system introduces a small probability of random mutation to the newly generated test cases, such as randomly modifying an input value, adjusting parameter boundaries, or introducing interference operations, etc., so as to enhance the exploration ability. Finally, use the new generation of individuals to replace some of the old individuals with lower fitness to form a new population. The above process is continuously iterated until the set maximum number of iterations is reached, or the population converges after several generations and meets the expected test goals, and then output the target test cases.
[0147] In this application, step 203 optimizes the process of generating and selecting test cases by using the method of "test case generation model + heuristic search algorithm", which not only improves the diversity of test cases, thereby increasing the test coverage, but also realizes the improvement of test efficiency and enhances the automation degree and accuracy of front-end code testing under the condition of limited resources and time.
[0148] Step 204, run the target test case to obtain the running data.
[0149] In the embodiment of this application, the process of running the target test case to obtain the running data at least includes: obtaining the test environment information of the target test case, configuring the simulation environment based on the test target information and the test environment information, running the target test case in the simulation environment, collecting the running log and behavioral data, and using the running log and behavioral data as the running data.
[0150] Since there are differences in the running conditions relied on by different test cases, during the process of running the target test case, it is necessary to obtain the test environment information required for the test case to run, determine the test target based on the test target information, and determine the test method based on the test environment information, so as to ensure that the target test case can run in an environment that meets the expected conditions and obtain effective and reliable running data.
[0151] Among them, the test environment information includes the hardware environment and the software environment. For example, hardware environment information such as the operating system version, memory, processor, etc., and software environment information such as the database type, interface version, network configuration, etc.
[0152] After obtaining the test environment information, reasonably configure the simulation environment by combining the test target information and the test environment information, so that the simulation environment can simulate abnormal situations such as network timeouts and resource shortages, while ensuring that the testing process does not affect the actual system operation.
[0153] After completing the configuration of the simulation environment, run the target test cases in this simulation environment, synchronously collect log files such as error and warning information, and behavior data such as function calls, data changes, and interface responses. The log files and behavior data collected from the simulation environment are used as "operation data".
[0154] In addition to the log and behavior data, it is also possible to further observe the actual execution results of the code and the page rendering effect to assist in verifying whether the front-end code works as expected. For example, functional correctness: the code executes as expected and the page display meets the requirements, such as when the user enters correct data and jumps to the target page. Boundary condition triggering: when the limit values are input, such as the maximum value, empty string, the code processing logic takes effect, such as prompting "input out of range". Exception handling verification: when an exception is triggered, such as division by zero, null pointer, the page pops up an error prompt or jumps to an error page, such as "system exception, please try again later". User interaction feedback: when simulating user operations, such as clicking a button, filling out a form, the page response conforms to the design, such as a pop-up window is triggered after the button is clicked. Performance performance: under high-concurrency testing, the page loading speed and resource occupancy meet the expectations, such as no lag or crash.
[0155] Through the above multi-dimensional observation and data collection, the running state of the front-end code under the target test cases can be comprehensively evaluated, providing data support for subsequent error location and automatic repair.
[0156] Moreover, after the execution of the target test cases, the code analysis system can collect feedback data and adjust the parameters of the deep neural network model and the heuristic search algorithm according to the feedback data to improve the quality and efficiency of subsequent test case generation.
[0157] For example, for the deep neural network model, analyze the performance metrics in the feedback data, such as accuracy, recall, etc. If the accuracy is low, it means that the model complexity is insufficient. At this time, the number of neurons or the number of network layers can be appropriately increased. If overfitting occurs, the regularization parameter needs to be adjusted and the weight decay coefficient increased to suppress overfitting. If the convergence speed is slow, then the initial learning rate can be tried to be increased to accelerate convergence, and the learning rate decay strategy can be adopted subsequently.
[0158] For heuristic search algorithms, check the metrics related to search efficiency in the tests, such as search time consumption and the number of traversed nodes. If the search time consumption is too long, it may be that the heuristic function is poorly designed and fails to effectively guide the search direction. In this case, it is necessary to redesign or adjust the weights of the heuristic function to make it more suitable for the characteristics of the problem. If the search gets stuck in a local optimal solution, the randomness parameter can be increased, such as the temperature parameter in the simulated annealing algorithm, to increase the probability of the algorithm jumping out of the local optimum. Additionally, if the search space is too large resulting in low efficiency, the search step size can be adjusted or the search range can be restricted to narrow the search space and improve the efficiency.
[0159] The code analysis system of this application can adjust the parameters of the deep neural network model and the heuristic search algorithm in a targeted manner by continuously monitoring various metrics in the feedback data, gradually optimizing the test case generation process, and improving the generation quality and efficiency.
[0160] Step 205: Perform error detection on the code feature vector and output prediction data.
[0161] In the embodiment of this application, the process of performing error detection on the code feature vector and outputting prediction data at least includes: the code analysis system performs static analysis and dynamic monitoring on the code feature vector using the code quality prediction model, outputs the first prediction data, compares the code feature vector with the known error feature vectors, outputs the second prediction data, and evaluates the suspiciousness of the code feature vector to output the third prediction data.
[0162] Among them, the prediction data includes one or more of the first prediction data, the second prediction data, and the third prediction data, and multi-level verification and cross-verification are achieved through different combination methods to identify potential defects in the front-end code to be tested.
[0163] The first prediction data is derived from the static analysis and dynamic monitoring processes. Through static analysis, the code analysis system can identify information such as the syntax structure, variable types, and function call relationships in the front-end code to be tested, and determine whether there are static errors such as type mismatches and abnormal calls. At the same time, the code analysis system dynamically monitors the code execution process in a simulated or actual running environment, records key data such as the memory usage status, variable value change trajectories, and function return results, which are used to assist in identifying logical errors or runtime exceptions. Therefore, the first prediction data can be data such as the syntax structure, variable types, function calls, etc. in the front-end code to be tested, as well as data such as memory usage and variable value changes.
[0164] The second prediction data is based on the similarity matching of error feature vectors. The code analysis system can extract a large number of representative error samples from historical projects or code libraries to construct an error feature library. The current code feature vector is matched with the known error feature vectors in the error feature library. If the similarity is higher than the set threshold, it can be determined that it may contain a certain type of known error, and the corresponding error pattern is output as the second prediction data. Therefore, the second prediction data can be the error pattern of the front-end code to be tested.
[0165] The third prediction data is based on the suspiciousness evaluation of potential errors. The code analysis system can apply machine learning methods including enhanced radial basis function neural network, gene expression programming, etc. to model and score each statement in the front-end code to be tested. The model evaluates the suspiciousness of each statement according to factors such as context semantics, historical error distribution, variable dependency relationship, etc., and outputs the prediction result of "suspicious statement - suspiciousness value". The higher the suspiciousness, the more likely the statement is the root cause of the error, which helps to prioritize error localization. Therefore, the third prediction data can be the suspicious statements and the suspicious values of the suspicious statements in the front-end code to be tested.
[0166] Step 206: Perform data fusion on the running data and the prediction data to obtain the test result of the front-end code to be tested.
[0167] In the embodiment of the present application, the code analysis system can fuse the running data and the prediction data through a fully connected layer or an attention mechanism to obtain the test result of the front-end code to be tested. Among them, the test result includes the error code segment, as well as the error type and error degree corresponding to the error code segment.
[0168] As an example, the code analysis system initially locates the code area where an error may occur by combining the running data of the test cases generated by the genetic algorithm, and then combines the code quality prediction model to predict the possible error types and their locations in the front-end code to be tested, accurately determining which functions or which lines of code have errors. This way of fusion localization not only utilizes the ability of the genetic algorithm to generate diverse test cases, but also gives play to the advantages of the deep neural network model in code error prediction, thus efficiently locating the error code segment.
[0169] In the present application, the test result includes the error code segment, as well as the error type and error degree corresponding to the error code segment.
[0170] Among them, the error types include but are not limited to syntax errors, logical errors, runtime errors, boundary condition errors, and security vulnerabilities.
[0171] Syntax errors refer to violations of programming language rules, such as spelling mistakes and missing semicolons. For example, pritn("Hello") (should be print).
[0172] Logic errors mean that the program runs without errors, but the results do not meet expectations. For example, incorrect loop conditions leading to infinite loops, or incorrect calculation logic (such as miswriting a + b×c as (a + b)×c).
[0173] Runtime errors refer to exceptions triggered during program execution, such as division by zero and null pointers. For example, x / 0 or obj.method() (obj is None).
[0174] Boundary condition errors refer to incorrect handling of input boundary values (such as array out - of - bounds and numerical overflow. For example, list
[10] (index exceeds length).
[0175] Security vulnerabilities refer to potential security risks in the code (such as SQL injection and XSS attacks). For example, directly concatenating user input into SQL queries.
[0176] As an example, the test result is an error in the front - end code to be tested. The error code snippet ① is {aabb}, the error type is a syntax error, the error severity is high, the error code snippet ② is {ccdd}, the error type is an undefined variable error, the error severity is medium, and the error code snippet ③ is {eeff}, the error type is a type error, and the error severity is low.
[0177] Step 207, automatically repair the front - end code to be tested according to the test results.
[0178] In the embodiments of the present application, according to the error type and error severity in the test results, corresponding repair suggestions are generated, and the effectiveness of the repair suggestions is verified in the verification environment to ensure that the function of the repaired code is normal and no new errors are introduced.
[0179] In the present application, if the test result is an error in the front - end code to be tested, the error code snippets, as well as the corresponding error types and error severities of the error code snippets, are extracted from the test results. The error code snippets are automatically repaired based on the error types and error severities to generate the front - end code to be verified. Finally, the front - end code to be verified that passes the verification is determined as the repaired front - end code.
[0180] As an example, the ways in which the code analysis system uses the code repair model to automatically repair the front - end code to be tested and generate the front - end code to be verified include: 1) Error classification and repair strategy matching Based on the type and characteristics of the error, the model classifies it into common error types, such as syntax errors, logical errors, type errors, etc. For different types of errors, the model matches corresponding repair strategies. For example, for syntax errors, the model may suggest adding missing semicolons or parentheses, and for logical errors, the model may suggest adjusting conditional statements or loop structures.
[0181] 2) Sequence-to-Sequence Model The Seq2Seq model predicts errors in the code and generates corresponding repair suggestions by learning the error patterns of the input code and the pairs of repaired code. The model takes the error code as input and outputs the corresponding repaired code. By learning the dataset of "error code - correct code" pairs, the model can infer possible repair methods.
[0182] 3) Semantics-based Repair Generation The deep learning model can not only repair syntax errors but also perform higher-level logical error repairs by analyzing the semantics of the code. By combining the abstract syntax tree or code context, more accurate repair suggestions are generated.
[0183] In this application, in order to ensure that the repaired front-end code is valid, it is often necessary to verify the front-end code to be verified.
[0184] As an example, the simplest way is to directly re-run the repaired code. If no error is triggered, it can indicate that the repair is effective. In actual use, in order to improve the verification accuracy, other verification methods can also be used: Regression Testing: By re-running the complete set of test cases before the repair, ensure that the repaired code does not break the original functions. For example, after repairing the login function, re-verify the related functions such as registration and password retrieval.
[0185] Boundary Condition Testing: Perform extreme value testing on the input range near the repair point to verify whether the repaired code can correctly handle boundary conditions. Common boundary conditions include extreme inputs such as maximum / minimum values and null values, ensuring that the code performs stably in these situations.
[0186] Code Review: Manually check the repair logic to ensure that the code follows the standard coding specifications and evaluate whether there are potential risks or logical errors.
[0187] Fuzz Testing: Robustness test the repaired code by randomly generating or mutating input data. For example, randomly perturb the input, such as generating random strings, numbers, or testing the performance of the application in irregular scenarios.
[0188] In addition, the code analysis system of the present application can collect user feedback and test results, and continuously optimize the deep neural network model and the heuristic search algorithm. Through techniques such as incremental learning and transfer learning, the system can continuously adapt to new code structures and error types, improving the overall performance and accuracy.
[0189] It should be noted that the embodiments of the present application include but are not limited to the above examples. It can be understood that under the guidance of the idea of the embodiments of the present application, those skilled in the art can set according to the actual situation, and the present application does not make any restrictions on this.
[0190] In the embodiment of the present application, when applied to a code analysis system, the method includes: receiving a code test task for the front-end code to be tested, where the code test task includes use case constraint conditions and test target information of the front-end code to be tested, extracting a code feature vector from the front-end code to be tested, iteratively generating target test cases according to the use case constraint conditions and test target information, running the target test cases to obtain running data, and performing error detection on the code feature vector to output prediction data, and fusing the running data and the prediction data to obtain the test result of the front-end code to be tested. And it can also automatically repair the front-end code to be tested according to the test result.
[0191] The technical solution of the present application has at least the following advantages compared with the related art: First, it can receive the feature vector of the front-end code as input and output an evaluation of the code quality and a prediction of potential errors. Through training with a large number of front-end code samples, the model has an in-depth understanding of the code structure and function, so as to accurately identify potential problems in the code. Second, a heuristic search algorithm is introduced to automatically generate diverse test cases. This algorithm intelligently selects test scenarios and test strategies according to the code feature vector and the prediction result of the deep neural network model, ensuring that the test cases can comprehensively cover the critical paths and potential errors in the code. Third, an efficient front-end code feature extraction and parsing method is proposed, which can automatically parse the source code of the front-end project, extract features such as key elements, components, and event handling functions, and construct code feature vectors. These feature vectors are the basic inputs of the deep neural network model and the heuristic search algorithm, ensuring the accuracy and reliability of the system. Fourth, combining the prediction ability of the deep neural network model and the test case results generated by the heuristic search algorithm, automatically generate repair suggestions. These suggestions have been strictly tested by the verification mechanism to ensure that they can accurately repair the errors in the code while avoiding introducing new problems. Fifth, a continuous learning and optimization mechanism is designed, which can collect user feedback and test results, and continuously optimize the deep neural network model and the heuristic search algorithm. Through techniques such as incremental learning and transfer learning, the system can continuously adapt to new code structures and error types, improving the overall performance and accuracy.
[0192] Corresponding to the foregoing embodiments of the application function implementation method, the present application further provides a code analysis system, an electronic device, and corresponding embodiments.
[0193] Figure 3 It is a schematic structural diagram of a code analysis system shown in the embodiments of the present application. Refer to Figure 3 This system at least includes the following modules: A test task receiving module 301, configured to receive a code test task for the front-end code to be tested, where the code test task includes use case constraint conditions and test target information of the front-end code to be tested; A feature vector extraction module 302, configured to extract a code feature vector from the front-end code to be tested; A test case generation module 303, configured to iteratively generate target test cases according to the use case constraint conditions and test target information; A test module 304, configured to obtain a test result of the front-end code to be tested by running the target test cases and error detection code feature vectors.
[0194] As an optional example of the present application, the test module 304 includes: A use case running sub-module, configured to run the target test cases to obtain running data; and, An error detection sub-module, configured to perform error detection on the code feature vectors and output prediction data; A data fusion sub-module, configured to perform data fusion on the running data and the prediction data to obtain a test result of the front-end code to be tested.
[0195] As an optional example of the present application, the use case running sub-module is configured to: Obtain test environment information of the target test cases; Configure a simulation environment based on the test target information and the test environment information; Run the target test cases in the simulation environment, collect running logs and behavior data, and use the running logs and behavior data as the running data.
[0196] As an optional example of the present application, the prediction data includes one or more of first prediction data, second prediction data, and third prediction data, and the error detection sub-module is configured to: Perform static analysis and dynamic monitoring on the code feature vectors and output the first prediction data; Compare the code feature vectors with known error feature vectors and output the second prediction data; Perform a suspiciousness evaluation on the code feature vectors and output the third prediction data.
[0197] As an optional example of the present application, the data fusion sub-module is configured to: Fuse the running data and the prediction data through a fully connected layer or an attention mechanism to obtain the test result of the front-end code to be tested; Among them, the test result includes error code segments, as well as the error types and error degrees corresponding to the error code segments.
[0198] As an optional example of the present application, the test case generation module 303 is used for: Define the search space through the code feature vector and the test target information; Input the code feature vector into a preset test case generation model, and the test case generation model outputs a number of candidate test cases; In the search space, evaluate the quality of the candidate test cases according to the use case constraint conditions to obtain the heuristic function value; Determine the candidate test cases with the heuristic function value less than the preset threshold as the target test cases.
[0199] As an optional example of the present application, the system further includes: A code repair module, which is used to, if the test result is that the front-end code to be tested is incorrect, extract the error code segment from the test result, as well as the error type and error degree corresponding to the error code segment; automatically repair the error code segment based on the error type and error degree to generate the front-end code to be verified; determine the front-end code to be verified that passes the verification as the repaired front-end code.
[0200] Regarding the system in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated here.
[0201] Figure 4 It is a schematic structural diagram of an electronic device shown in the embodiments of the present application.
[0202] See Figure 4 , the electronic device 400 includes a memory 410 and a processor 420.
[0203] The processor 420 can be a Central Processing Unit (CPU), or can also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The memory 410 can include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, the ROM can store static data or instructions required by the processor 420 or other modules of the computer. The permanent storage device can be a read-write storage device. The permanent storage device can be a non-volatile storage device that does not lose the stored instructions and data even when the computer is powered off. In some embodiments, the permanent storage device uses a mass storage device (such as a magnetic or optical disk, flash memory) as the permanent storage device. In some other embodiments, the permanent storage device can be a removable storage device (such as a floppy disk, optical drive). The system memory can be a read-write storage device or a volatile read-write storage device, such as dynamic random access memory. The system memory can store some or all of the instructions and data required by the processor during operation. In addition, the memory 410 can include any combination of computer-readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and magnetic disks and / or optical disks can also be used. In some embodiments, the memory 410 can include a removable storage device that can be read and / or written, such as a compact disc (CD), read-only digital versatile disc (such as DVD-ROM, dual-layer DVD-ROM), read-only Blu-ray disc, super density disc, flash memory card (such as SD card, min SD card, Micro-SD card, etc.), magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and instantaneous electronic signals transmitted wirelessly or by wire.
[0204] Executable code is stored on the memory 410, and when the executable code is processed by the processor 420, it can cause the processor 420 to execute some or all of the methods described above.
[0205] In addition, the method according to the present application can also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above-mentioned method of the present application.
[0206] Alternatively, the present application can also be implemented as a computer-readable storage medium (or a non-transitory machine-readable storage medium or a machine-readable storage medium), on which executable code (or a computer program or computer instruction code) is stored. When executed by a processor of an electronic device (or a server, etc.), the processor is caused to execute some or all of the steps of the above-mentioned method according to the present application.
[0207] The present application also provides a computer program product, which includes computer instructions that, when executed by a processor, implement the method as described above.
[0208] The embodiments of the present application have been described above. The above description is exemplary and not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations are obvious to those of ordinary skill in the art in the technical field without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technologies in the market, or to enable other ordinary skill in the art in the technical field to understand the embodiments disclosed herein.
Claims
1. A method for testing front-end code, characterized in that Applied to a code analysis system, including: Receiving a code test task for the front-end code to be tested, where the code test task includes use case constraint conditions and test target information of the front-end code to be tested; Extracting a code feature vector from the front-end code to be tested; Iteratively generating target test cases according to the use case constraint conditions and the test target information; Obtaining the test result of the front-end code to be tested by running the target test cases and error-detecting the code feature vector.
2. The method according to claim 1, characterized in that The obtaining the test result of the front-end code to be tested by running the target test cases and error-detecting the code feature vector includes: Running the target test cases to obtain running data; and, Performing error detection on the code feature vector and outputting prediction data; Fusing the running data and the prediction data to obtain the test result of the front-end code to be tested.
3. The method according to claim 2, wherein The running the target test cases to obtain running data includes: Obtaining the test environment information of the target test cases; Configuring a simulation environment based on the test target information and the test environment information; Running the target test cases in the simulation environment, collecting running logs and behavior data, and using the running logs and behavior data as the running data.
4. The method according to claim 2, characterized in that, The prediction data includes one or more of first prediction data, second prediction data, and third prediction data. The performing error detection on the code feature vector and outputting prediction data includes: Performing static analysis and dynamic monitoring on the code feature vector and outputting the first prediction data; Comparing the code feature vector with known error feature vectors and outputting the second prediction data; Evaluating the suspiciousness of the code feature vector and outputting the third prediction data.
5. The method according to claim 2, wherein The fusing the running data and the prediction data to obtain the test result of the front-end code to be tested includes: Fusing the running data and the prediction data through a fully connected layer or an attention mechanism to obtain the test result of the front-end code to be tested; Wherein, the test result includes error code segments, and the error types and error degrees corresponding to the error code segments.
6. The method according to claim 1, characterized in that, The iteratively generating target test cases according to the use case constraint conditions and the test target information includes: Defining a search space through the code feature vector and the test target information; Inputting the code feature vector into a preset test case generation model, and the test case generation model outputs a number of candidate test cases; In the search space, performing quality evaluation on the candidate test cases according to the use case constraint conditions to obtain heuristic function values; Determining the candidate test cases with heuristic function values less than a preset threshold as the target test cases.
7. The method according to claim 1, wherein The method further includes: If the test result is that the front-end code to be tested is in error, extracting the error code segments from the test result, and the error types and error degrees corresponding to the error code segments; Automatically repairing the error code segments based on the error types and the error degrees to generate front-end code to be verified; Determine the to-be-verified front-end code that passes the verification as the repaired front-end code.
8. A code analysis system, comprising: A test task receiving module, configured to receive a code test task for the to-be-tested front-end code, where the code test task includes use case constraint conditions and test target information of the to-be-tested front-end code; A feature vector extraction module, configured to extract a code feature vector from the to-be-tested front-end code; A test case generation module, configured to iteratively generate target test cases according to the use case constraint conditions and the test target information; A test module, configured to obtain a test result of the to-be-tested front-end code by running the target test cases and error-detecting the code feature vector.
9. An electronic device, characterized in that, Comprising: A processor; And A memory, storing executable code thereon, and when the executable code is executed by the processor, causing the processor to execute the method according to any one of claims 1-7.
10. A computer-readable storage medium, storing executable code thereon, and when the executable code is executed by a processor of an electronic device, causing the processor to execute the method according to any one of claims 1-7.
Citation Information
Cited By
Computer software automatic test analysis method and test platform
CN120743784A
Test case recommendation method, system and equipment
CN121658388A
Adaptive frontend performance diagnosis and remediation
US12699546B1