Intelligent test system and automatic generation method of code test case
By decoupling and refactoring the Continue service into an independent context analysis service, its integration problem in the intelligent testing system is solved, enabling high-precision automated test case generation and improving the accuracy and effectiveness of test cases.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING SHANGYIN MICRO CORE TECH CO LTD
- Filing Date
- 2026-01-27
- Publication Date
- 2026-05-08
AI Technical Summary
The existing code analysis capabilities of the Continue service are difficult to integrate effectively into intelligent testing systems, and cannot meet the needs for high-precision, automated test case generation.
By decoupling the core functionality of the Continue service and transforming it into a service that can be deployed and invoked independently, the API call module is used to realize the mapping and transformation from high-level business requests to low-level code resources. Furthermore, by bridging external systems through standardized service calls, it is refactored into an independent context analysis service, enabling it to be invoked by the Web platform in an IDE-less environment.
It improves the accuracy and effectiveness of automatically generated test cases, and significantly enhances the semantic consistency, coverage completeness and logical correctness of LLM-generated test cases.
Smart Images

Figure CN121996560A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to an intelligent testing system and a method for automatically generating code test cases. Background Technology
[0002] Currently, AI programming assistant frameworks based on Large Language Models (LLMs), such as Continue, provide developers with powerful localized programming assistance features. As a modular, configurable, cross-platform open-source framework, Continue aims to enable developers to quickly integrate and use custom LLM programming assistance tools in local or cloud environments. By supporting plugins for mainstream IDEs such as VS Code and JetBrains, and combining its powerful context awareness and code editing capabilities, it achieves a complete workflow from conversational collaboration and intelligent code completion to automated code modification, significantly improving development efficiency.
[0003] However, in the core business scenario of AI-driven automated test case generation, the existing architecture and feature release of the Continue framework are entirely designed around the IDE plugin ecosystem. All its core capabilities, including deep code indexing, intelligent context extraction and management, and semantic code analysis, are tightly coupled to desktop integrated development environments such as VSCode and JetBrains. This strong binding prevents Continue from being invoked as an independent service, making it difficult to effectively integrate its advanced code analysis capabilities into web-based systems such as intelligent testing systems, thus failing to meet the actual needs for high-precision, automated test case generation. Summary of the Invention
[0004] Based on the above problems, this application provides an intelligent testing system and an automatic generation method for code test cases. The purpose is to solve the technical problem that the existing code analysis capabilities of Continue service are difficult to effectively integrate into the intelligent testing system, so as to meet the actual needs of high-precision and automated test case generation.
[0005] The embodiments of this application disclose the following technical solutions: In a first aspect, this application provides an intelligent testing system, the system comprising: a receiving module, an interface calling module, a Continue service module, and a test case generation module; The receiving module is used to receive a test case generation request initiated by the user and send the test case generation request to the interface calling module; the test case generation request includes prompt words required to generate test cases for the target code corresponding to the code under test, and the interface name of the code library where the code under test is located; The interface invocation module is used to receive the test case generation request and obtain the interface path of the code library based on the interface name in the test case generation request; the interface invocation module is also used to send the interface path and the test case generation request to the Continue service module by invoking the target interface of the Continue context service. The Continue service module is used to receive the interface path and the test case generation request, and obtain the context code related to the code under test from the code library based on the interface path; the Continue service module is also used to perform context analysis on the context code and the test case generation request, generate target prompt words, and send the target prompt words to the test case generation module. The test case generation module is used to receive the target prompt words and generate target code test cases based on the target prompt words using a large language model.
[0006] In an optional implementation, the Continue service module includes: The code snippet acquisition unit is used to parse the interface path, obtain the index identifier of the code library, and obtain the context code related to the code to be tested from the code library according to the index identifier; The prompt word generation unit is used to parse the test case generation request, generate a test case generation instruction, and integrate the test case generation instruction, the context code, and the prompt word into the target prompt word.
[0007] In an optional implementation, the intelligent testing system further includes: The code index creation module is used to, in response to the index database construction instruction, obtain all code fragments in the corresponding code repository based on the code repository address before obtaining the context code related to the code under test from the code repository based on the interface path, and parse all the code fragments to convert each code fragment into a code vector sequence respectively; The code index creation module is also used to construct the code library based on all the code vector sequences, and to set a corresponding index identifier for the code library.
[0008] In an optional implementation, the target interface is an API interface.
[0009] In an optional implementation, the intelligent testing system further includes: The display module is used to receive the target code test cases sent by the Continue service module and display the target code test cases on the target page.
[0010] A second aspect of this application provides a method for automatically generating code test cases, applied to an intelligent testing system according to any one of the above-mentioned optional implementations, the method comprising: Receive a test case generation request initiated by a user; the test case generation request includes prompt words required to generate test cases for the target code corresponding to the code under test, and the interface name of the code library where the code under test is located; The interface path of the code repository is obtained based on the interface name in the request generated by the test case; By calling the target interface of the Continue context service, the interface path and the test case generation request are sent to the Continue context service; Using the Continue context service, context code related to the code under test is obtained from the code repository based on the interface path, and context analysis is performed on the context code and the test case generation request to generate target prompt words; The target code test cases are generated based on the target prompt words using a large language model.
[0011] In an optional implementation, the step of retrieving context code related to the code under test from the code repository based on the interface path, and performing context analysis on the context code and the test case generation request to generate target prompt words includes: The interface path is parsed to obtain the index identifier of the code library, and the context code related to the code under test is obtained from the code library based on the index identifier; The test case generation request is parsed to generate a test case generation instruction, and the test case generation instruction, the context code, and the prompt words are integrated into the target prompt words.
[0012] In an optional implementation, before retrieving the context code related to the code under test from the code repository based on the interface path, the automatic generation method for code test cases further includes: In response to the index database construction instruction, all code fragments in the corresponding code repository are obtained based on the code repository address, and all the code fragments are parsed to convert each code fragment into a code vector sequence; The code library is constructed based on all the code vector sequences, and a corresponding index identifier is set for the code library.
[0013] In a third aspect, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for automatically generating code test cases.
[0014] In a fourth aspect, this application provides a processor for running a computer program, wherein the computer program executes the above-described method for automatically generating test cases.
[0015] Compared with the prior art, this application has the following beneficial effects: In this application's technical solution, the intelligent testing system includes a receiving module, an interface calling module, a Continue service module, and a test case generation module. The receiving module receives user-initiated test case generation requests and sends them to the interface calling module. The test case generation request includes prompts for generating test cases for the target code corresponding to the code under test, as well as the interface name of the codebase containing the code under test. This lays the foundation for accurate extraction of code context and avoids context loss or noise interference caused by a lack of code location information. The interface calling module receives the test case generation request and obtains the interface path of the codebase based on the interface name in the request. The interface calling module also sends the interface path and test case generation request to the Continue service module by calling the target interface of the Continue context service. This achieves a mapping transformation from high-level business requests to low-level code resources. Furthermore, it bridges external systems with Continue's code analysis capabilities through standardized service calls (such as HTTP / HTTPS), transforming the context acquisition logic, which was originally only triggered within the IDE, into a service call driven by external parameters. This solves the problem that Continue cannot run independently of the IDE, allowing its code understanding capabilities to be invoked on demand by the Web platform. The Continue service module receives the interface path and test case generation request, and retrieves the context code related to the code under test from the code repository based on the interface path. The Continue service module also performs context analysis on the context code and test case generation request, generates target hints, and sends the target hints to the test case generation module. This achieves this by separating and refactoring the context extraction, indexing, and semantic analysis logic from the original IDE plugin into an independent service. This allows the service to autonomously load the code repository, resolve dependencies, identify context information (such as related functions / classes / variables), and generate high-fidelity, structure-aware enhanced hints (i.e., target hints) based on the input interface path in an IDE-free environment. It then integrates user hints to generate high-fidelity, structure-aware enhanced hints (i.e., target hints), significantly improving the semantic consistency, coverage completeness, and logical correctness of subsequent LLM-generated test cases. The test case generation module receives the target hints and uses a large language model to generate high-precision target code test cases based on them. This application refactors the Continue code analysis capabilities, which were originally limited to the IDE plugin ecosystem, to the Web-based intelligent testing system through architectural decoupling, service encapsulation, and context adaptation mechanisms. This solves the problem that the existing Continue service's code analysis capabilities are difficult to effectively integrate into the intelligent testing system, thereby improving the accuracy and effectiveness of automatically generated test cases. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of the structure of an intelligent testing system provided in an embodiment of this application; Figure 2 This is a schematic diagram of another intelligent testing system provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of another intelligent testing system provided in the embodiments of this application; Figure 4 This is a schematic diagram of a conventional Continue structure provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a Continue service module provided in an embodiment of this application; Figure 6 This is a schematic diagram of another Continue service module provided in an embodiment of this application; Figure 7 A flowchart illustrating an automatic code test case generation method provided in this application embodiment. Detailed Implementation
[0018] As described earlier, AI programming assistant frameworks based on Large Language Models (LLMs), such as Continue, provide developers with powerful localized programming assistance features. As a modular, configurable, cross-platform open-source framework, Continue aims to enable developers to quickly integrate and use custom LLM programming assistance tools in local or cloud environments. By supporting plugins for mainstream IDEs such as VS Code and JetBrains, and combining its powerful context awareness and code editing capabilities, it achieves a complete workflow from conversational collaboration and intelligent code completion to automated code modification, significantly improving development efficiency.
[0019] However, in the core business scenario of AI-driven automated test case generation, the existing architecture and feature release of the Continue framework are entirely designed around the IDE plugin ecosystem. All its core capabilities, including deep code indexing, intelligent context extraction and management, and semantic code analysis, are tightly coupled to desktop integrated development environments such as VSCode and JetBrains. This strong binding prevents Continue from being invoked as an independent service, making it difficult to effectively integrate its advanced code analysis capabilities into web-based systems such as intelligent testing systems, thus failing to meet the actual needs for high-precision, automated test case generation.
[0020] The inventors have proposed an intelligent testing system and a method for automatically generating code test cases. The core functionality of `continue` is decoupled from the IDE plugin and transformed into an independently deployable and invokeable service, allowing the intelligent testing platform to integrate via APIs. This enables the intelligent testing platform to directly call the modified `Continue` code analysis and context service, providing high-quality code context for large AI models, thereby improving the accuracy and effectiveness of automatically generated test cases.
[0021] In this solution, the intelligent testing system includes a receiving module, an interface call module, a Continue service module, and a test case generation module. The receiving module receives user-initiated test case generation requests and sends them to the interface call module. The test case generation request includes prompts for generating test cases for the target code corresponding to the code under test, as well as the interface name of the codebase containing the code under test. This lays the foundation for accurate code context extraction and avoids context loss or noise interference caused by a lack of code location information. The interface call module receives the test case generation request and obtains the interface path of the codebase based on the interface name in the request. The interface call module also sends the interface path and test case generation request to the Continue service module by calling the target interface of the Continue context service. This achieves a mapping transformation from high-level business requests to low-level code resources. Furthermore, it bridges external systems with Continue's code analysis capabilities through standardized service calls (such as HTTP / HTTPS), transforming the context retrieval logic, which was originally only triggered within the IDE, into a service call driven by external parameters. This solves the problem that Continue cannot run independently of the IDE, allowing its code understanding capabilities to be invoked on demand by the Web platform. The Continue service module receives the interface path and test case generation request, and retrieves the context code related to the code under test from the code repository based on the interface path. The Continue service module also performs context analysis on the context code and test case generation request, generates target hints, and sends the target hints to the test case generation module. This achieves this by separating and refactoring the context extraction, indexing, and semantic analysis logic from the original IDE plugin into an independent service. This allows the service to autonomously load the code repository, resolve dependencies, identify context information (such as related functions / classes / variables), and generate high-fidelity, structure-aware enhanced hints (i.e., target hints) based on the input interface path in an IDE-free environment. It then integrates user hints to generate high-fidelity, structure-aware enhanced hints (i.e., target hints), significantly improving the semantic consistency, coverage completeness, and logical correctness of subsequent LLM-generated test cases. The test case generation module receives the target hints and uses a large language model to generate high-precision target code test cases based on them. This application refactors the Continue code analysis capabilities, which were originally limited to the IDE plugin ecosystem, to the Web-based intelligent testing system through architectural decoupling, service encapsulation, and context adaptation mechanisms. This solves the problem that the existing Continue service's code analysis capabilities are difficult to effectively integrate into the intelligent testing system, thereby improving the accuracy and effectiveness of automatically generated test cases.
[0022] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0023] System Implementation Examples
[0024] This application provides an intelligent testing system, wherein... Figure 1 This is a schematic diagram of the structure of an intelligent testing system provided in an embodiment of this application, as shown below. Figure 1 As shown, the device includes: a receiving module 11, an interface call module 12, a Continue service module 13, and a test case generation module 14. From Figure 1 You can see the connections between several modules.
[0025] The receiving module 11 is used to receive the test case generation request initiated by the user and send the test case generation request to the interface calling module.
[0026] In the embodiments of this application, such as Figure 2 As shown, the test case generation request can include the prompt words needed to generate test cases for the target code corresponding to the code under test, as well as the interface name of the code repository where the code under test is located (such as / biz / v3 / bills / _search). After logging into the intelligent testing platform, the user can submit a test case generation request (i.e., a test case generation request) on the intelligent testing platform. This request can include all necessary information, such as prompt words and interface names. Then, the system's receiving module 11 can receive the test case generation request initiated by the user and send the test case generation request to the interface calling module 12, laying the foundation for accurate extraction of code context in the future and avoiding the problem of missing context or noise interference caused by a lack of code location basis.
[0027] Interface call module 12 is used to receive test case generation requests and obtain the interface path of the code library based on the interface name in the test case generation request.
[0028] The interface call module 12 is also used to send the interface path and test case generation request to the Continue service module by calling the target interface of the Continue context service.
[0029] like Figure 4As shown, the existing continue service includes an IDE extension layer, a communication protocol layer, a core layer, and an external service layer. In the IDE extension layer, JetBrains extensions (i.e., extensions / intellij) or VSCode extensions (i.e., extensions / vscode) can be activated by the user. This extension encapsulates the current file, cursor position, project index, and other contexts through the "IDE protocol" and calls ToCoreProtocol to send a request to Core. If compatibility with older versions is required, TolderProtocol is also supported.
[0030] In the communication protocol layer, ToCoreProtocol serializes the request (i.e., JSON-RPC / custom TLV) and sends it to the local Core process via stdin / NamedPipe / LSP channels; when the Core returns, it also follows the same protocol, and the extension layer receives it and parses it into standard objects such as CompletionList, InlayHint, and Diagnostic that can be recognized by the IDE.
[0031] In the core layer, ConfigHandler first validates the global / project-level config.json to determine which Provider chains to enable. After receiving a "complete" event, the autocomplete controller (i.e., the LLM control disk) can call the CompletionProvider. The context control disk (i.e., ContextProviders) injects the current file, import relationships, syntax tree, and exception stack into the Prompt. If the Codicksetindoorer (i.e., code exception extension) detects a runtime error, it adds an extra traceback as a negative sample. The Core class uniformly schedules the asynchronous aggregation of all Contexts, generates the final Prompt, and calls external LLM services.
[0032] In the external service layer, Core sends the Prompt to LLM services such as OpenAI and Ollama via HTTP / HTTPS or local gRPC; it can also connect to a self-hosted Continuell server for caching, A / B testing, or private model inference. After the LLM returns candidate code snippets, the CompletionProvider performs post-processing (such as syntax validation, security filtering, and ranking). The results are then fed back along the original path (i.e., Core → ToCoreProtocol → IDE extension → rendered as a completion list / inline suggestions / document overlay), completing a closed-loop interaction. In other words, Continuell's core functionality is tightly coupled to its IDE (such as VSCode) plugin, and its capabilities are invoked through IDE-specific APIs and protocols. This prevents its powerful capabilities from being directly integrated and invoked by the web client, creating a capability silo and hindering the automatic generation of test cases.
[0033] To address the aforementioned issues, in this embodiment of the application, the interface calling module 12 can receive a test case generation request and obtain the interface path of the code repository (e.g., based on the interface name in the test case generation request) Figure 2 As shown in / api / v1 / context / code), the target interface of the Continue context service is called, and the interface path and test case generation request are sent to the Continue service module 13. This realizes the mapping and transformation from high-level business requests to low-level code resources. By bridging external systems with Continue's capabilities through standardized service calls (such as HTTP / HTTPS), the context acquisition logic that could only be triggered inside the IDE is transformed into a service call that can be driven by external parameters. This solves the problem that Continue cannot run without the IDE, and enables its code understanding capabilities to be called on demand by the Web platform.
[0034] Among them, such as Figure 5 As shown, the Continue service module 13 may include a Web presentation layer, an API call layer, a core layer (Core), and an external service layer. Specifically, in the Web presentation layer: When a user opens a WebIDE or documentation site in their browser, the frontend first loads two JS / TS modules: ContextProvider and Codebaseindex. When the user opens a file, moves the cursor, or triggers autocomplete by typing, the frontend collects the current file, project index, and cursor coordinates, and encapsulates these into a JSON request body. In the API call layer, the request simultaneously hits three APIs via HTTP / gRPC: (1) POST / configapi: Get global / project-level configuration (such as model name, temperature, maximum token, etc.).
[0035] (2) POST / contextproviderapi: Allows the server to further complete cross-references, syntax trees, and comments.
[0036] (3) POST / codebaseindexapi: Incrementally synchronize project index to ensure that subsequent semantic retrieval is up-to-date.
[0037] All three API requests are forwarded to the Core layer. After a 200 response is returned, the frontend merges the response and enters a waiting state for completion. In the Core layer, the ConfigHandler first validates and merges the default configuration, then generates the final Config object and injects it into the Core class. The Core class then dispatches the request to the following components: (1) Automatic completion controller (i.e. LLM control panel), responsible for generating candidate code.
[0038] (2) Context control disk (i.e. ContextProviders) is used to aggregate syntax trees, import graphs, and type definitions.
[0039] (3) Code exception extension (i.e., Codicksetindoorer): If the file contains error lines, a traceback will be automatically attached as a negative sample.
[0040] (4) The CompletionProvider assembles the configuration, context, and exception prompts according to the Prompt template, and asynchronously calls the external LLM service.
[0041] In the external service layer, HTTP requests are sent to OpenAI / Ollama or a self-hosted Continuell server; Continuell can handle caching, private model inference, and usage statistics. After the LLM returns candidate code, the CompletionProvider performs post-processing: syntax validation (ASTparse), security filtering (hard-coded blacklist), and candidate ranking (similarity / probability weighting). The final result is returned along the original API, where / configapi returns the completion list and the model parameters used; / contextproviderapi returns the sidebar documentation / explanation; and / codebaseindexapi returns the current index update status. The web presentation layer receives the data and displays it.
[0042] It's worth noting that by transforming the traditional private IDE communication protocol of Continue into a standardized web protocol based on HTTP / HTTPS, third-party platforms can directly call the underlying functions via APIs, expanding the project's use cases. By encapsulating Continue's underlying functions such as index creation, updating, and context retrieval into a clear set of RESTful API interfaces, it can be invoked over the network and integrated into intelligent testing platforms. For example, POST / api / context is used to submit code repositories and create indexes, while GET / api / context / {index_id}?query=xxx is used to query related code. By encapsulating core functionalities (such as index creation, updating, and context retrieval) into independently deployable, monitorable, and scalable background daemons or containerized microservices, the issue of Continue's inability to run independently of an IDE is resolved, allowing its code understanding capabilities to be invoked on demand by web platforms. By converting returned data to JSON, the output of the processed service ensures that the data is platform-independent structured data, rather than a display format dependent on IDE rendering.
[0043] Optionally, the target interface is an API interface (such as a RESTful API interface).
[0044] Continue service module 13 is used to receive interface paths and test case generation requests, and to obtain context code related to the code under test from the code repository based on the interface paths.
[0045] The Continue service module 13 is also used to perform context analysis on the context code and test case generation request, generate target prompts, and send the target prompts to the test case generation module.
[0046] In this embodiment of the application, the Continue service module 13 can receive an interface path and a test case generation request, and obtain context code (such as...) related to the code under test from the code repository based on the interface path. Figure 2The code shows the Controller, Service, and DAO layers. Then, the Continue service module 13 can perform context analysis on the context code and test case generation request, generate target prompts, and send the target prompts to the test case generation module 14. This achieves the goal of separating and reconstructing the context extraction, indexing, and semantic analysis logic in the original IDE plugin into an independent service. This enables the system to autonomously load the code library, resolve dependencies, and identify context information (such as related functions / classes / variables) based on the input interface path in an IDE-free environment. It also integrates user prompts to generate high-fidelity, structure-aware enhanced prompts (i.e., target prompts), thereby significantly improving the semantic consistency, coverage completeness, and logical correctness of subsequent LLM-generated test cases.
[0047] In one alternative implementation, such as Figure 3 As shown, the Continue service module includes the following functions: (1) Index creation is one of the core functions of Continue. It is mainly used to build a searchable index of the code library so that the relevant code information used by the test case generation interface can be quickly retrieved in the code block.
[0048] (2) Context management, used to provide relevant information to large language models so that they can generate more accurate answers, includes the following types of context: CodebaseContextProvider, FileContextProvider, CurrentFileContextProvider and TerminalContextProvider; CodebaseContextProvider is used to retrieve relevant content from the codebase index; FileContextProvider is used to provide the content of a specific file; CurrentFileContextProvider is used to provide the content of the currently open file; TerminalContextProvider is used to provide terminal output, etc., to retrieve relevant content from the code repository index.
[0049] (3) Configuration Management, which is responsible for loading, validating and managing all configuration options of Continue. The configuration types it supports include the following: Model Configuration, which defines the available AI models and their parameters; Context Provider Configuration, which specifies which context providers to enable; and Tool Configuration, which defines the list of available tools.
[0050] Optionally, such as Figure 6As shown, the Continue service module 13 specifically includes: a code snippet acquisition unit 131 and a prompt word generation unit 132.
[0051] The code snippet acquisition unit 131 is used to parse the interface path, obtain the index identifier of the code library, and obtain the context code related to the code to be tested from the code library according to the index identifier.
[0052] In this embodiment of the application, the code snippet acquisition unit 131 can parse the interface path, obtain the index identifier of the code library, and query the function name, code path, etc. from the code library according to the index identifier to obtain the context code related to the code to be tested, and return it in a structured data (such as JSON) format, rather than a format for IDE rendering.
[0053] The prompt word generation unit 132 is used to parse the test case generation request, generate test case generation instructions, and integrate the test case generation instructions, context code, and prompt words into a target prompt word.
[0054] In this embodiment of the application, the prompt word generation unit 132 can parse the test case generation request, generate a test case generation instruction, and merge the user prompt word, the interface source code (i.e., the context code) and the test case generation instruction to generate the target prompt word.
[0055] In one feasible implementation, the intelligent testing system further includes a code index creation module 15.
[0056] The code index creation module 15 is used to, in response to the index database construction instruction, obtain all code fragments in the corresponding code repository based on the code repository address before obtaining the context code related to the code to be tested from the code repository based on the interface path, and parse all code fragments to convert each code fragment into a code vector sequence.
[0057] The code index creation module 15 is also used to build a code library based on all code vector sequences and set corresponding index identifiers for the code library.
[0058] It should be noted that by separating the index creation process, accepting code repository URLs or code snippets as input, and returning queryable index identifiers, efficient, reusable, and asynchronous code repository analysis and querying can be achieved, significantly improving system performance, scalability, and user experience.
[0059] The test case generation module 14 is used to receive target prompt words and generate target code test cases based on the target prompt words using a large language model.
[0060] In this embodiment, the test case generation module 14 can receive target prompt words and generate high-precision target code test cases based on the target prompt words using a large language model. Specifically, as shown... Figure 3 As shown, the test case generation module 14 can utilize the code analysis function of the large language model, combine the target prompt words with the test case template, URI information and method call chain in the PROMPT module, generate PROMPT prompt words, and generate high-precision target code test cases based on the PROMPT prompt words.
[0061] Optionally, a test case template (i.e., a template used to ensure that the test cases generated from the large model conform to a predefined format (such as Given-When-Then, Step-Expected Result, etc.)) facilitates subsequent automated parsing and execution. The template guides the large model to generate test cases containing key test elements, such as preconditions, test data, operation steps, expected results, and priorities. Dedicated templates are designed for different test types (functional, performance, security) to improve the relevance of the generated test cases. A test case template can be shown in the following example:
[0062] Optionally, in API testing scenarios, the URI represents the path and resource location of the interface under test (e.g., / biz / v3 / bills / _search). The path and query parameters in the URI can prompt the large model to generate targeted test data (e.g., boundary values, abnormal parameters). Combined with the corresponding API documentation (e.g., OpenAPI / Swagger), this helps the large model understand the interface's business scenarios and constraints, ensuring that the generated test cases cover the normal flow, abnormal scenarios, and security checks (e.g., injection attack testing) of a specific interface. The URI can be illustrated as follows:
[0063] Optionally, the method call chain is used to describe the order in which multiple methods / interfaces are called in the business logic (e.g., user login → add product → pay order). It can also prompt large models to generate test cases involving state passing (e.g., the response data of the previous interface serving as the input of the next interface), and fault-tolerant scenarios simulating failures at a point in the call chain (e.g., network timeout, data validation failure), thereby generating test cases for complex business processes, not just single-interface verification. A method call chain can be illustrated as follows:
[0064] Optionally, the intelligent testing system also includes a display module 16, which receives target code test cases sent by the Continue service module and displays the target code test cases on the target page.
[0065] In the embodiments of this application, such as Figure 2 As shown, after the test case generation module 14 generates target code test cases based on target prompt words using the large language model, the large language model can send the target code test cases back to the intelligent testing platform in JSON / text format. The intelligent testing platform can parse the returned results (i.e., target code test cases) and persistently save the test cases to the database. The display module 16 can render the saved target code test cases on the page, and users can directly view, edit, execute, or export them on the platform.
[0066] The intelligent testing system provided in this application migrates the Continue code analysis capabilities, originally limited to the IDE plugin ecosystem, to a web-based intelligent testing system. This solves the problem of effectively integrating the existing Continue service's code analysis capabilities into an intelligent testing system, thereby improving the accuracy and effectiveness of automatically generated test cases. By sending interface paths and test case generation requests to the Continue service module, a mapping transformation from high-level business requests to low-level code resources is achieved. Furthermore, standardized service calls (such as HTTP / HTTPS) bridge the gap between external systems and Continue's code analysis capabilities. The context retrieval logic, originally triggered only within the IDE, is transformed into service calls driven by external parameters. This solves the problem that Continue cannot run independently of the IDE, allowing its code understanding capabilities to be invoked on demand by the web platform. The Continue service module retrieves context code related to the code under test from the code repository based on the interface path, and performs context analysis on the context code and test case generation request to generate target prompt words. This achieves the goal of separating and reconstructing the context extraction, indexing and semantic analysis logic in the original IDE plugin into an independent service. This enables the service to autonomously load the code repository, resolve dependencies, and identify context information (such as related functions / classes / variables) based on the input interface path in an IDE-free environment. It also integrates user prompt words to generate high-fidelity, structure-aware enhanced prompts (i.e., target prompt words), thereby significantly improving the semantic consistency, coverage completeness and logical correctness of subsequent LLM-generated test cases. The test case generation module receives the target prompt words and uses a large language model to generate high-precision target code test cases based on the target prompt words.
[0067] Method Implementation Examples
[0068] This application provides an embodiment of a method for automatically generating code test cases, which is applied to an intelligent testing system described in any of the above system embodiments. It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the flowcharts show a logical order, in some cases the steps shown or described may be executed in a different order than that shown here.
[0069] See Figure 7 The figure is a flowchart of a method for automatically generating code test cases provided in an embodiment of this application. Figure 7 As shown, the method includes the following steps: Step S701: Receive a test case generation request initiated by the user.
[0070] In step S701, the test case generation request includes the prompt words required to generate the target code test cases corresponding to the code under test, as well as the interface name of the code library where the code under test is located.
[0071] Step S702: Obtain the interface path of the code library based on the interface name in the test case generation request.
[0072] Step S703: By calling the target interface of the Continue context service, the interface path and test case generation request are sent to the Continue context service.
[0073] Step S704: Using the Continue context service, retrieve the context code related to the code under test from the code repository based on the interface path, and perform context analysis on the context code and test case generation request to generate target prompt words.
[0074] In this embodiment of the application, the system can parse the interface path to obtain the index identifier of the code library, and retrieve the context code related to the code to be tested from the code library according to the index identifier; then the system can parse the test case generation request, generate a test case generation instruction, and integrate the test case generation instruction, context code and prompt words into a target prompt word.
[0075] Step S705: Use the large language model to generate target code test cases based on the target prompt words.
[0076] In one feasible implementation, before retrieving the context code related to the code under test from the code repository based on the interface path, the system may, in response to the index database construction instruction, retrieve all code fragments in the corresponding code repository based on the code repository address, and parse all code fragments to convert each code fragment into a code vector sequence; then the system may construct a code repository based on all code vector sequences and set corresponding index identifiers for the code repository.
[0077] Optionally, the target interface is an API interface.
[0078] In one feasible implementation, after generating target code test cases based on target prompt words using a large language model, the system can also receive target code test cases sent by the Continue service module through the display module and display the target code test cases on the target page.
[0079] Storage Media Examples
[0080] This application provides a computer-readable storage medium storing a program, wherein when executed by a processor, the program implements some or all of the steps in the automatic generation method for code test cases described in the foregoing method embodiments of this application. The storage medium can be any medium capable of storing program code, such as a USB flash drive, external hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0081] Processor Implementation
[0082] This application provides a processor for running a program, wherein, during program execution, some or all of the steps in the automatic generation method for code test cases described in the foregoing method embodiments are executed.
[0083] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the method embodiments are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The method embodiments described above are merely illustrative, and some or all of the methods can be selected to achieve the purpose of this embodiment solution according to actual needs. Those skilled in the art can understand and implement them without creative effort.
[0084] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. An intelligent testing system, characterized in that, The system includes: a receiving module, an interface call module, a Continue service module, and a test case generation module; The receiving module is used to receive a test case generation request initiated by the user and send the test case generation request to the interface calling module; the test case generation request includes prompt words required to generate test cases for the target code corresponding to the code under test, and the interface name of the code library where the code under test is located; The interface invocation module is used to receive the test case generation request and obtain the interface path of the code library based on the interface name in the test case generation request; the interface invocation module is also used to send the interface path and the test case generation request to the Continue service module by invoking the target interface of the Continue context service. The Continue service module is used to receive the interface path and the test case generation request, and obtain the context code related to the code under test from the code library based on the interface path; the Continue service module is also used to perform context analysis on the context code and the test case generation request, generate target prompt words, and send the target prompt words to the test case generation module. The test case generation module is used to receive the target prompt words and generate target code test cases based on the target prompt words using a large language model.
2. The system according to claim 1, characterized in that, The Continue service module includes: The code snippet acquisition unit is used to parse the interface path, obtain the index identifier of the code library, and obtain the context code related to the code to be tested from the code library according to the index identifier; The prompt word generation unit is used to parse the test case generation request, generate a test case generation instruction, and integrate the test case generation instruction, the context code, and the prompt word into the target prompt word.
3. The system according to claim 1, characterized in that, The intelligent testing system also includes: The code index creation module is used to, in response to the index database construction instruction, obtain all code fragments in the corresponding code repository based on the code repository address before obtaining the context code related to the code under test from the code repository based on the interface path, and parse all the code fragments to convert each code fragment into a code vector sequence respectively; The code index creation module is also used to construct the code library based on all the code vector sequences, and to set a corresponding index identifier for the code library.
4. The system according to claim 1, characterized in that, The target interface is an API interface.
5. The system according to claim 1, characterized in that, The system also includes: The display module is used to receive the target code test cases sent by the Continue service module and display the target code test cases on the target page.
6. A method for automatically generating code test cases, characterized in that, The method, applied to the intelligent testing system according to any one of claims 1-5, comprises: Receive a test case generation request initiated by a user; the test case generation request includes prompt words required to generate test cases for the target code corresponding to the code under test, and the interface name of the code library where the code under test is located; The interface path of the code repository is obtained based on the interface name in the request generated by the test case; By calling the target interface of the Continue context service, the interface path and the test case generation request are sent to the Continue context service; Using the Continue context service, context code related to the code under test is obtained from the code repository based on the interface path, and context analysis is performed on the context code and the test case generation request to generate target prompt words; The target code test cases are generated based on the target prompt words using a large language model.
7. The method according to claim 6, characterized in that, The process involves retrieving context code related to the code under test from the code repository based on the interface path, performing context analysis on the context code and the test case generation request, and generating target prompt words, including: The interface path is parsed to obtain the index identifier of the code library, and the context code related to the code under test is obtained from the code library based on the index identifier; The test case generation request is parsed to generate a test case generation instruction, and the test case generation instruction, the context code, and the prompt words are integrated into the target prompt words.
8. The method according to claim 6, characterized in that, Before retrieving the context code related to the code under test from the code repository based on the interface path, the method further includes: In response to the index database construction instruction, all code fragments in the corresponding code repository are obtained based on the code repository address, and all the code fragments are parsed to convert each code fragment into a code vector sequence; The code library is constructed based on all the code vector sequences, and a corresponding index identifier is set for the code library.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method for automatically generating code test cases as described in any one of claims 6-8.
10. A processor, characterized in that, Used to run a computer program, which, when running, executes the automatic generation method for code test cases as described in any one of claims 6-8.