A JavaScript Context-Aware Test Generation Method and System Based on a Large Model
By adopting a JavaScript context-aware test generation method based on a large model, this paper addresses the shortcomings of existing technologies in function identification, third-party dependency interface processing, and test generation techniques. It improves the semantic accuracy and engineering adaptability of test generation, and is applicable to various JavaScript projects and mainstream Node.js application scenarios.
Patent Information
- Application Number
- CN202511368729.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-24
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2045-09-24
AI Technical Summary
Existing JavaScript unit test generation technologies have shortcomings in function identification and modeling capabilities, third-party dependency interface handling, function call relationship modeling, and type reasoning, resulting in incomplete, inconsistent, and poorly executable test generation.
A large-model-based approach is adopted, which constructs function recognition graph, call graph and data flow graph through AST analysis, parses third-party dependency interfaces, generates a structured prompt word graph and inputs it into the large language model, outputs test code and performs post-processing.
It significantly improves the semantic accuracy and engineering adaptability of test generation, can accurately identify test functions, generate executable unit test cases, is suitable for a variety of complex application scenarios, and has good scalability and versatility.
Smart Images

Figure CN120872845B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and system for generating JavaScript context-aware tests based on a large model. Background Technology
[0002] JavaScript is currently the core language widely used in web front-end and Node.js server-side development. Its flexible syntax, rich asynchronous model, and heavy reliance on third-party libraries in engineering practices determine the high complexity and practical challenges of automated testing in the software development process. Unit testing, as a key means of ensuring the quality, stability, and maintainability of JavaScript programs, directly impacts development efficiency and test completeness through its automated generation capabilities. However, research and analysis have revealed significant shortcomings in existing technologies across several key dimensions, primarily in the following aspects:
[0003] (1) Existing technologies have accuracy deficiencies in function identification and modeling capabilities. JavaScript supports various function definition methods and module export semantics, including named functions, anonymous functions, arrow functions, higher-order functions, object methods, class methods, etc. These structures can be combined through chained calls, wrapper functions, or dynamic property assignment, resulting in a high degree of uncertainty in the binding relationship and scope boundary of functions in the source code. Existing methods identify functions based on static text features, which cannot fully parse complex export structures, resulting in incomplete identification of test targets and affecting the coverage and targeting of tests.
[0004] (2) Existing technologies lack adaptability in handling third-party dependency interfaces. The npm library is widely used in JavaScript engineering practice, but existing test generation solutions lack a systematic third-party interface parsing mechanism. This makes it impossible to extract parameter signatures, return types, and usage scenarios of library functions, easily leading to problems such as incorrect API call method judgment, confusion between class functions and instance functions, and omission of default parameters, resulting in inconsistent generated test behavior. Furthermore, existing technologies cannot dynamically adapt to third-party libraries with incomplete interface documentation or frequent version updates, posing a reliability risk.
[0005] (3) Existing technologies generally adopt a single-function perspective for test generation, lacking the ability to model the call relationships between functions. JavaScript projects often have patterns such as paired export of synchronous and asynchronous functions, collaboration between caller and callback functions, and forwarding of wrapper functions. These functions have related behaviors and semantic consistency requirements. Existing technologies do not introduce call graph analysis or function clustering mechanisms, resulting in generated tests that only cover the logic of the function itself and cannot verify its consistency with the behavior of related functions in the real context, thus limiting the test effectiveness.
[0006] (4) JavaScript uses a dynamic typing mechanism, and the types of function parameters and return values need to be inferred from the context. However, existing methods do not have a unified type annotation or inference mechanism, which can easily lead to problems such as parameter type mismatch, illegal assignment, and type conversion failure during the test generation process, reducing the executability and semantic correctness of the test code.
[0007] In summary, existing JavaScript unit test automatic generation technologies still have shortcomings in the following key technical areas: first, they lack a function identification mechanism for dynamically exported structures; second, they lack semantic modeling capabilities for third-party dependency interfaces; third, they lack strategies for analyzing and jointly modeling function call topologies; and fourth, they lack a unified type reasoning and annotation mechanism. These technical problems directly affect the completeness, effectiveness, and maintainability of generated tests in actual engineering projects. Therefore, there is an urgent need for a test generation method with context-aware capabilities and structured semantic extraction capabilities to address these issues. Summary of the Invention
[0008] This invention provides a JavaScript context-aware test generation method and system based on a large model, which solves the technical problems of existing test generation methods such as weak semantic understanding ability, insufficient context modeling ability, poor executableness of generated code, and lack of semantic modeling ability for third-party dependency interfaces, thereby improving the semantic accuracy and engineering adaptability of test generation.
[0009] This invention provides a JavaScript context-aware test generation method based on a large model, comprising:
[0010] The target JavaScript data is parsed to obtain a set of test functions. ;
[0011] The test function set was analyzed using AST. All functions in the set have structured dependencies, represented as follows: Simultaneously, record function metadata information as follows: ;
[0012] Construct function recognition graph ;
[0013] The test function set is obtained through AST analysis. The call graph and data flow graph of the testable functions;
[0014] Based on the call graph, the call relationships between target functions are extracted to form function call edges, which are then added to the set of valid call edges. ;
[0015] Based on the data flow graph, the parameter flow and dependencies between functions are analyzed, and parameter data nodes in the functions are extracted to form a context entity set. ;
[0016] Extract semantic information from the function code to obtain the semantic labels of the dependency edges. ;
[0017] Constructing the function context dependency graph ;
[0018] Parse the dependencies in the target JavaScript data to obtain a set of third-party exported functions. ;
[0019] Identify the actual call path and call parameters of the external interface in the target JavaScript data and mark them as follows. ;
[0020] For the aforementioned set of third-party exported functions Analyze the exported functions in the code, extract the function signature, parameter structure, return value type, and typical call examples, and mark this information as... ;
[0021] Constructing a semantic graph of third-party interfaces ;
[0022] Constructing a prompt word graph ;in, For a set of nodes, For a set of dependency edges, A collection of attribute mappings;
[0023] The prompt word image The information in the code forms formatted prompt words, which are input into a large language model and output test code.
[0024] Post-processing operations are performed on the test code to obtain the test file.
[0025] Specifically, the third-party exported function set The derived functions in the code are analyzed, including:
[0026] For the aforementioned set of third-party exported functions Static analysis or document parsing is performed on the exported functions in the document.
[0027] Specifically, it also includes:
[0028] By employing a multi-source strategy, testable functions Predict the input and output types and generate structured type annotation information for each testable function;
[0029] Embedding the type annotation information back into the function code yields a testable function with type information. ;
[0030] The .
[0031] Specifically, the multi-source strategy includes: based on variable usage paths, function signature propagation, default value annotations, and third-party documentation reasoning.
[0032] Specifically, the post-processing operation on the test code to obtain the test file includes:
[0033] The test code is subjected to syntax validation, assertion extraction, dependency adaptation, and path coverage analysis to obtain the test file.
[0034] This invention also provides a JavaScript context-aware test generation system based on a large model, comprising:
[0035] The data parsing module is used to parse the target JavaScript data to obtain a set of test functions. ;
[0036] The data analysis module is used to analyze the test function set through AST. All functions in the set have structured dependencies, represented as follows: Simultaneously, record function metadata information as follows: ;
[0037] The function recognition graph construction module is used to construct function recognition graphs. ;
[0038] The module for obtaining the call graph and data flow graph is used to obtain the set of test functions through AST analysis. The call graph and data flow graph of the testable functions;
[0039] The call relationship acquisition module is used to extract the call relationships between target functions based on the call graph, form function call edges, and add them to the set of valid call edges. ;
[0040] The parameter data node acquisition module is used to analyze the parameter flow and dependencies between functions based on the data flow graph, extract parameter data nodes from the functions, and form a context entity set. ;
[0041] The semantic information extraction module is used to extract semantic information from function code and obtain semantic labels for dependency edges. ;
[0042] The function context dependency graph building module is used to construct function context dependency graphs. ;
[0043] The dependency resolution module is used to parse the dependencies in the target JavaScript data to obtain a set of third-party exported functions. ;
[0044] The parameter recognition module is used to identify the actual call path and call parameters of the external interface in the target JavaScript data, and mark them as... ;
[0045] The third-party exported function analysis module is used to analyze the set of third-party exported functions. Analyze the exported functions in the code, extract the function signature, parameter structure, return value type, and typical call examples, and mark this information as... ;
[0046] The third-party interface semantic graph construction module is used to construct the semantic graph of third-party interfaces. ;
[0047] The prompt word graph construction module is used to build prompt word graphs. ;in, For a set of nodes, For a set of dependency edges, A collection of attribute mappings;
[0048] The test code output module is used to output the prompt word image. The information in the code forms formatted prompt words, which are input into a large language model and output test code.
[0049] The test file generation module is used to perform post-processing operations on the test code to obtain the test file.
[0050] Specifically, the third-party exported function analysis module is used to analyze the set of third-party exported functions. Static analysis or document parsing is performed on the exported functions in the document to extract function signatures, parameter structures, return value types, and typical call examples. This information is then marked as... .
[0051] Specifically, it also includes:
[0052] The structured type annotation information generation module is used to generate annotations for testable functions using a multi-source strategy. Predict the input and output types and generate structured type annotation information for each testable function;
[0053] A testable function generation module with type information is used to embed the type annotation information back into the function code to obtain a testable function with type information. ;
[0054] The prompt word graph construction module is specifically used to construct the prompt word graph. ;in, For a set of nodes, For a set of dependency edges, This is a collection of attribute mappings.
[0055] Specifically, the multi-source strategy includes: based on variable usage paths, function signature propagation, default value annotations, and third-party documentation reasoning.
[0056] Specifically, the test file generation module is used to perform syntax verification, assertion extraction, dependency adaptation, and path coverage analysis on the test code to obtain the test file.
[0057] One or more technical solutions provided in this invention have at least the following technical effects or advantages:
[0058] Using a JavaScript project to be analyzed as input, and relying on static analysis techniques, this invention constructs a function identification graph, a function context dependency graph, and a third-party interface semantic graph. It systematically models information such as function definition locations, module structures, call relationships, parameter types, and external dependencies. Based on this structured modeling result, it further constructs unified-format prompts to guide the large language model in generating unit test cases with semantic consistency and executability. After generating test code, it supports syntax validation, assertion recognition, and dependency completion, automatically generating test files that conform to the project structure. This invention significantly improves the accuracy of test case generation, path coverage, and project adaptability. It is applicable to various JavaScript projects and mainstream Node.js application scenarios, possessing good scalability and versatility. Attached Figure Description
[0059] Figure 1 A flowchart of a JavaScript context-aware test generation method based on a large model provided in an embodiment of the present invention. Detailed Implementation
[0060] This invention provides a JavaScript context-aware test generation method and system based on a large model, which solves the technical problems of existing test generation methods, such as weak semantic understanding ability, insufficient context modeling ability, poor executableness of generated code, and lack of semantic modeling ability for third-party dependency interfaces, thereby improving the semantic accuracy and engineering adaptability of test generation. Detailed Implementation
[0062] This invention provides a JavaScript context-aware test generation method and system based on a large model, which solves the technical problems of existing test generation methods, such as weak semantic understanding ability, insufficient context modeling ability, poor executableness of generated code, and lack of semantic modeling ability for third-party dependency interfaces, thereby improving the semantic accuracy and engineering adaptability of test generation.
[0063] like Figure 1 As shown, the JavaScript context-aware test generation method based on a large model provided in this embodiment of the invention includes:
[0064] Step S110: Parse the target JavaScript data to obtain the test function set. ;
[0065] This step will be explained in detail: the target JavaScript data will be parsed to obtain a set of test functions. ,include:
[0066] Using the JavaScript project to be analyzed as input, the source code is parsed using syntax parsers such as Babel, module binding, and scope analysis to extract a set of functions with testable value. In this embodiment, three types of functions are primarily extracted: functions with export behaviors such as `export / module.exports`, functions with callbacks bound through mechanisms such as `addEventListener`, `setTimeout`, and framework hooks, and "implicitly reachable" functions indirectly called by other modules. The final set of testable functions is denoted as […]. .
[0067] Step S120: Analyze the test function set using AST. All functions in the dataset are used to obtain structured dependencies, including exports, bindings, and redirects, which are represented as follows: Simultaneously, it records function metadata information such as function name, definition location, and whether it is an asynchronous function. ;
[0068] Step S130: Construct a function recognition graph Its construction process uses AST traversal combined with module dependency graph for filtering and annotation, thereby effectively eliminating meaningless private encapsulation functions and anonymous inner functions.
[0069] In this embodiment, the function identification graph is used to filter representative target functions, exclude anonymous functions, closure functions, and other code blocks that have no independent testing significance, and provide a basic entry point for subsequent test generation.
[0070] Step S210: Obtain the test function set through AST analysis The call graph and data flow graph of the testable functions;
[0071] In this embodiment, the call graph is a crucial foundation for function aggregation and context-aware test generation. The call graph structure obtained through static analysis reveals direct or indirect call paths between functions, synchronous and asynchronous dependencies, etc., thus helping to identify which functions should be merged into tests and which call behaviors need consistency verification, effectively avoiding test silos. Data flow graphs are used to analyze the propagation paths, scope, and type evolution of variables within functions. Especially when facing complex scenarios such as nested scopes, closures, and default parameters, data flow graphs can help model the real data interactions between symbols, thereby assisting the model in better understanding function logic and generating test cases covering more semantic paths.
[0072] Step S220: Based on the call graph, extract the call relationships between the target functions, form function call edges, and add them to the set of valid call edges. ;
[0073] Step S230: Based on the data flow graph, analyze the parameter flow and dependencies between functions, extract parameter data nodes in the functions, including function input parameters, return values, and intermediate data passed between functions, to form a context entity set. ;
[0074] Step S240: Extract semantic information from the function code to obtain the semantic labels of the dependency edges. ;
[0075] This step will be explained in detail, extracting semantic information from the function code to obtain the semantic labels of the dependency edges. ,include:
[0076] Extract semantic information such as keyword naming and comments from function code to obtain semantic labels for dependency edges. Examples include "call chain", "shared parameters", and "defined in the same module".
[0077] Step S250: Construct the function context dependency graph ;
[0078] In this embodiment, the function context dependency graph is used to enhance the contextual integrity in the construction of prompt words, enabling the large language model to combine the actual use and boundary behavior of functions in the project when generating test cases, thereby improving the consistency and accuracy of test semantics.
[0079] Step S310: Parse the dependencies in the target JavaScript data to obtain the set of third-party exported functions. ;
[0080] Step S320: Identify the actual call path and call parameters to the external interface in the target JavaScript data, and mark them as... ;
[0081] Step S330: Export the third-party function set Analyze the exported functions in the code, extract the function signature, parameter structure, return value type, and typical call examples, and mark this information as... ;
[0082] Specifically, for the third-party exported function set The derived functions in the code are analyzed, including:
[0083] Third-party exported function collection Static analysis or document parsing is performed on the exported functions in the document.
[0084] Step S340: Construct the semantic graph of third-party interfaces This is used to model the semantics of how the objective function uses the interface of the external npm library;
[0085] Step S410: Construct a prompt word graph ;in, For a set of nodes, For a set of dependency edges, A collection of attribute mappings;
[0086] In this embodiment, the prompt word graph serves as an intermediate representation for generating the input of a large language model. It integrates key information extracted from the function recognition graph, function context dependency graph, and third-party interface semantic graph, unifying them into a structured prompt word input structure. This encodes complex code structures and contextual relationships into clear prompt information, significantly improving the executability, semantic relevance, and boundary coverage of generated test cases. Specifically, the nodes of the prompt word graph include elements such as function prototypes, type annotations, contextual semantics, and third-party interface calls. Edges represent semantic relationships between information, such as "belongs to a module," "depends on an interface," and "was called by a function."
[0087] To further improve the modeling accuracy of function parameters and return value types, the following is also included:
[0088] By employing a multi-source strategy, testable functions The input and output types are predicted, and structured type annotation information is generated for each testable function. It should be noted that the inference process supports merging of type propagation paths across functions and modules.
[0089] In this embodiment, the multi-source strategy includes: based on variable usage paths, function signature propagation, default value annotations, and third-party documentation reasoning, etc.
[0090] Embedding type annotation information back into the function code results in a testable function with type information. This facilitates the expression of type constraints and expected behavior during the generation of large models;
[0091] in this case, .
[0092] Step S510: Display the prompt word image The information in the code forms formatted prompt words, which are input into a large language model and output test code.
[0093] Step S610: Perform post-processing operations on the test code to obtain the test file.
[0094] This step provides a detailed explanation, performing post-processing operations on the test code to obtain the test file, including:
[0095] The test code undergoes syntax validation, assertion extraction, dependency adaptation, and path coverage analysis to obtain unit test files that are executable and semantically consistent, thus completing the end-to-end test generation process.
[0096] This invention also provides a JavaScript context-aware test generation system based on a large model, comprising:
[0097] The data parsing module is used to parse the target JavaScript data to obtain a set of test functions. ;
[0098] Specifically, the data parsing module takes the JavaScript project to be analyzed as input and uses parsers such as Babel, module binding, and scope analysis to perform AST parsing on the source code, extracting a set of functions with testable value. In this embodiment, three types of functions are extracted: functions with export behavior such as export / module.exports, functions with callbacks bound through mechanisms such as addEventListener, setTimeout, and framework hooks, and "implicitly reachable" functions indirectly called by other modules. The final set of testable functions is denoted as... .
[0099] The data analysis module is used to analyze the test function set through AST. All functions in the dataset are used to obtain structured dependencies, including exports, bindings, and redirects, which are represented as follows: Simultaneously, it records function metadata information such as function name, definition location, and whether it is an asynchronous function. ;
[0100] The function recognition graph construction module is used to construct function recognition graphs. Its construction process uses AST traversal combined with module dependency graph for filtering and annotation, thereby effectively eliminating meaningless private encapsulation functions and anonymous inner functions.
[0101] In this embodiment, the function identification graph is used to filter representative target functions, exclude anonymous functions, closure functions, and other code blocks that have no independent testing significance, and provide a basic entry point for subsequent test generation.
[0102] The module for obtaining call graphs and data flow graphs is used to obtain the test function set through AST analysis. The call graph and data flow graph of the testable functions;
[0103] In this embodiment, the call graph is a crucial foundation for function aggregation and context-aware test generation. The call graph structure obtained through static analysis reveals direct or indirect call paths between functions, synchronous and asynchronous dependencies, etc., thus helping to identify which functions should be merged into tests and which call behaviors need consistency verification, effectively avoiding test silos. Data flow graphs are used to analyze the propagation paths, scope, and type evolution of variables within functions. Especially when facing complex scenarios such as nested scopes, closures, and default parameters, data flow graphs can help model the real data interactions between symbols, thereby assisting the model in better understanding function logic and generating test cases covering more semantic paths.
[0104] The call relationship acquisition module is used to extract the call relationships between target functions based on the call graph, form function call edges, and add them to the set of valid call edges. ;
[0105] The parameter data node acquisition module is used to analyze parameter flow and dependencies between functions based on the data flow graph, and extract parameter data nodes from the functions, including the function's input parameters, return values, and intermediate data passed between functions, forming a context entity set. ;
[0106] The semantic information extraction module is used to extract semantic information from function code and obtain the semantic labels of dependency edges. ;
[0107] Specifically, the semantic information extraction module is used to extract semantic information such as keyword naming and comments in function code to obtain the semantic labels of dependency edges. Examples include "call chain", "shared parameters", and "defined in the same module".
[0108] The function context dependency graph building module is used to construct function context dependency graphs. ;
[0109] In this embodiment, the function context dependency graph is used to enhance the contextual integrity in the construction of prompt words, enabling the large language model to combine the actual use and boundary behavior of functions in the project when generating test cases, thereby improving the consistency and accuracy of test semantics.
[0110] The dependency resolution module is used to parse the dependencies in the target JavaScript data and obtain the set of third-party exported functions. ;
[0111] The parameter recognition module is used to identify the actual call path and call parameters to external interfaces in the target JavaScript data and mark them as... ;
[0112] The third-party exported function analysis module is used to analyze the collection of third-party exported functions. Analyze the exported functions in the code, extract the function signature, parameter structure, return value type, and typical call examples, and mark this information as... ;
[0113] Specifically, the third-party exported function analysis module is used to analyze the collection of third-party exported functions. Static analysis or document parsing is performed on the exported functions in the document to extract function signatures, parameter structures, return value types, and typical call examples. This information is then marked as... .
[0114] The third-party interface semantic graph construction module is used to construct the semantic graph of third-party interfaces. This is used to model the semantics of how the objective function uses the interface of the external npm library;
[0115] The prompt word graph construction module is used to build prompt word graphs. ;in, For a set of nodes, For a set of dependency edges, A collection of attribute mappings;
[0116] In this embodiment, the prompt word graph serves as an intermediate representation for generating the input of a large language model. It integrates key information extracted from the function recognition graph, function context dependency graph, and third-party interface semantic graph, unifying them into a structured prompt word input structure. This encodes complex code structures and contextual relationships into clear prompt information, significantly improving the executability, semantic relevance, and boundary coverage of generated test cases. Specifically, the nodes of the prompt word graph include elements such as function prototypes, type annotations, contextual semantics, and third-party interface calls. Edges represent semantic relationships between information, such as "belongs to a module," "depends on an interface," and "was called by a function."
[0117] To further improve the modeling accuracy of function parameters and return value types, the following is also included:
[0118] The structured type annotation information generation module is used to generate annotations for testable functions using a multi-source strategy. The input and output types are predicted, and structured type annotation information is generated for each testable function. It should be noted that the inference process supports merging of type propagation paths across functions and modules.
[0119] In this embodiment, the multi-source strategy includes: based on variable usage paths, function signature propagation, default value annotations, and third-party documentation reasoning, etc.
[0120] A module for generating testable functions with type information is used to embed type annotation information back into function code, resulting in testable functions with type information. This facilitates the expression of type constraints and expected behavior during the generation of large models;
[0121] In this context, the prompt word graph construction module is specifically used to construct the prompt word graph. ;in, For a set of nodes, For a set of dependency edges, This is a collection of attribute mappings.
[0122] The test code output module is used to output the prompt word image. The information in the code forms formatted prompt words, which are input into a large language model and output test code.
[0123] The test file generation module is used to perform post-processing operations on the test code to obtain the test files.
[0124] Specifically, the test file generation module is used to perform syntax verification, assertion extraction, dependency adaptation, and path coverage analysis on the test code to obtain unit test files that are executable and semantically consistent, thus completing the end-to-end test generation process.
[0125] In summary, this invention fully utilizes static analysis techniques and semantic enhancement mechanisms, combined with the language model's generation capabilities, to automatically generate test cases for complex JavaScript functions. Specifically, taking the JavaScript project to be analyzed as input, it constructs structured prompts through static analysis and context modeling, thereby driving a large language model to automatically generate unit test code with executable and testable value. The overall solution follows the design philosophy of "static analysis-driven, context-aware enhancement, structured prompt construction, and test generation implementation," balancing analysis accuracy and model generalization ability.
[0126] In summary, the embodiments of this invention possess the following significant technical advantages: They can accurately identify target functions with test value in JavaScript projects, and are compatible with various complex export methods and asynchronous call structures; they can automatically construct the context relationships and call topology between functions, providing complete behavioral clues and boundary information for test generation; they can combine function semantics with the calling behavior of third-party libraries to generate test cases with executableness and semantic consistency; while improving test pass rate and path coverage, they can effectively reduce the probability of erroneous calls and semantic deviations. Furthermore, the embodiments of this invention also have good scalability and are applicable to various JavaScript projects and mainstream Node.js development frameworks.
[0127] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0128] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0129] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0130] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0131] Any aspects of this invention not described in detail in the embodiments are well-known techniques to those skilled in the art. Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this invention and not to limit it. Although this invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this invention without departing from the spirit and scope of this invention, and all such modifications and substitutions should be covered within the scope of the claims of this invention.
Claims
1. A JavaScript context-aware test generation method based on a large model, characterized in that, include: The target JavaScript data is parsed to obtain a set of test functions. ; The test function set was analyzed using AST. All functions in the dataset are used to obtain structured dependencies, which are represented as follows: Simultaneously, record function metadata information as follows: ; Construct function recognition graph ; The test function set is obtained through AST analysis. The call graph and data flow graph of the testable functions; Based on the call graph, the call relationships between target functions are extracted to form function call edges, which are then added to the set of valid call edges. ; Based on the data flow graph, the parameter flow and dependencies between functions are analyzed, and parameter data nodes in the functions are extracted to form a context entity set. ; Extract semantic information from the function code to obtain the semantic labels of the dependency edges. ; Constructing the function context dependency graph ; Parse the dependencies in the target JavaScript data to obtain a set of third-party exported functions. ; Identify the actual call path and call parameters of the external interface in the target JavaScript data and mark them as follows. ; For the aforementioned set of third-party exported functions Analyze the exported functions in the code, extract the function signature, parameter structure, return value type, and typical call examples, and mark this information as... ; Constructing a semantic graph of third-party interfaces ; Constructing a prompt word graph ;in, For a set of nodes, For a set of dependency edges, A collection of attribute mappings; The prompt word image The information in the code forms formatted prompt words, which are input into a large language model and output test code. Post-processing operations are performed on the test code to obtain the test file.
2. The JavaScript context-aware test generation method based on a large model as described in claim 1, characterized in that, The third-party exported function set The derived functions in the code are analyzed, including: For the aforementioned set of third-party exported functions Static analysis or document parsing is performed on the exported functions in the document.
3. The JavaScript context-aware test generation method based on a large model as described in claim 1, characterized in that, Also includes: By employing a multi-source strategy, testable functions Predict the input and output types and generate structured type annotation information for each testable function; Embedding the type annotation information back into the function code yields a testable function with type information. ; The .
4. The JavaScript context-aware test generation method based on a large model as described in claim 3, characterized in that, The multi-source strategy includes: based on variable usage paths, function signature propagation, default value annotations, and third-party documentation reasoning.
5. The JavaScript context-aware test generation method based on a large model as described in any one of claims 1-4, characterized in that, The post-processing operation on the test code to obtain the test file includes: The test code is subjected to syntax validation, assertion extraction, dependency adaptation, and path coverage analysis to obtain the test file.
6. A JavaScript context-aware test generation system based on a large model, characterized in that, include: The data parsing module is used to parse the target JavaScript data to obtain a set of test functions. ; The data analysis module is used to analyze the test function set through AST. All functions in the dataset are used to obtain structured dependencies, which are represented as follows: Simultaneously, record function metadata information as follows: ; The function recognition graph construction module is used to construct function recognition graphs. ; The module for obtaining the call graph and data flow graph is used to obtain the set of test functions through AST analysis. The call graph and data flow graph of the testable functions; The call relationship acquisition module is used to extract the call relationships between target functions based on the call graph, form function call edges, and add them to the set of valid call edges. ; The parameter data node acquisition module is used to analyze the parameter flow and dependencies between functions based on the data flow graph, extract parameter data nodes from the functions, and form a context entity set. ; The semantic information extraction module is used to extract semantic information from function code and obtain semantic labels for dependency edges. ; The function context dependency graph building module is used to construct function context dependency graphs. ; The dependency resolution module is used to parse the dependencies in the target JavaScript data to obtain a set of third-party exported functions. ; The parameter recognition module is used to identify the actual call path and call parameters of the external interface in the target JavaScript data and mark them as follows. ; The third-party exported function analysis module is used to analyze the set of third-party exported functions. Analyze the exported functions in the code, extract the function signature, parameter structure, return value type, and typical call examples, and mark this information as... ; The third-party interface semantic graph construction module is used to construct the semantic graph of third-party interfaces. ; The prompt word graph construction module is used to build prompt word graphs. ;in, For a set of nodes, For a set of dependency edges, A collection of attribute mappings; The test code output module is used to output the prompt word image. The information in the code forms formatted prompt words, which are input into a large language model and output test code. The test file generation module is used to perform post-processing operations on the test code to obtain the test file.
7. The JavaScript context-aware test generation system based on a large model as described in claim 6, characterized in that, The third-party exported function analysis module is specifically used for analyzing the set of third-party exported functions. Static analysis or document parsing is performed on the exported functions in the document.
8. The JavaScript context-aware test generation system based on a large model as described in claim 6, characterized in that, Also includes: The structured type annotation information generation module is used to generate annotations for testable functions using a multi-source strategy. Predict the input and output types and generate structured type annotation information for each testable function; A testable function generation module with type information is used to embed the type annotation information back into the function code to obtain a testable function with type information. .
9. The JavaScript context-aware test generation system based on a large model as described in claim 8, characterized in that, The multi-source strategy includes: based on variable usage paths, function signature propagation, default value annotations, and third-party documentation reasoning.
10. The JavaScript context-aware test generation system based on a large model as described in any one of claims 6-9, characterized in that, The test file generation module is specifically used to perform syntax verification, assertion extraction, dependency adaptation, and path coverage analysis on the test code to obtain the test file.
Citation Information
Patent Citations
JavaScript engine fuzz testing method for AST generation model based on structure perception
CN118626385A
Unit test case generation system based on large language model
CN119105965A