Test code generation method and related device
By using an adaptive domain recognition and code generation model in the code development platform, cross-domain test code generation is achieved, which solves the problem of limited generalization ability in existing technologies, improves the quality and adaptability of test code, and adapts to changes in the requirements of different programming languages, application types, and business domains.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
- Filing Date
- 2025-04-18
- Publication Date
- 2026-07-09
AI Technical Summary
Existing test code generation methods based on Large Language Models (LLM) have limited generalization ability when applied across domains, making it difficult to adapt to various special situations and changes in requirements. This results in inflexible generated test code, limiting its application in software development.
This method utilizes adaptive domain recognition on a code development platform, leveraging domain labels and mapping relationships, combined with a code generation model, to achieve cross-domain test code generation. It determines the source and target domains through adaptive domain recognition, understands and analyzes the testing requirements of different domains using a code generation model, generates test code for the source domain, and then maps it to the feature space of the target domain. This supports test code generation across different programming languages, application types, business domains, and technology stacks.
It enables efficient cross-domain test code generation, reduces the number of model training iterations, lowers costs, improves software test coverage and adaptability, generates more comprehensive test cases, adapts to various special situations and requirement changes, and enhances the quality and flexibility of generated test code.
Smart Images

Figure CN2025089890_09072026_PF_FP_ABST
Abstract
Description
A test code generation method and related device
[0001] The present application claims priority to the Chinese patent application No. 202411691096.0, filed on November 22, 2024, and entitled "A test code generation method and related device", the whole content of which is incorporated herein by reference. TECHNICAL FIELD
[0002] The present application relates to the technical field of testing, and in particular to a test code generation method, a code development platform, a computing device cluster, a computer readable storage medium, and a computer program product. BACKGROUND
[0003] Software testing is an indispensable part of the software development life cycle. The purpose of software testing is to ensure that the software system (or simply software) can meet the predetermined functional and performance requirements before release. With the development of software development technology, software systems have become increasingly complex, involving more functions and modules. Highly integrated software systems require more comprehensive and in-depth testing to ensure that the software system works properly under various conditions. Considering the efficiency and cost of manually developing test code, test code automatic generation has gradually become a research direction of focus.
[0004] Due to the excellent performance of large language models (LLMs) in the field of code generation, the industry has proposed test code generation methods based on LLMs. The key steps of the test generation method based on LLMs include obtaining the interface definition of the interface to be tested, at least one test case for testing the interface to be tested, and test code generation requirements, generating a guide word, such as a prompt, based on the interface definition, the test case, and the test code generation requirements, and then inputting the guide word into the LLM to obtain the test code generation result.
[0005] The above-mentioned test code generation method based on LLMs often performs well on specific types of programming tasks, such as single-domain programming tasks, but may not perform well on more extensive programming tasks, with limited generalization ability. Automatically generated test code may not be flexible enough to adapt to various special situations or requirement changes, thereby limiting the application of the test generation method based on LLMs in actual software development. SUMMARY
[0006] This application provides a test code generation method that supports cross-domain test code generation, can adapt to various special situations or changes in requirements, and has strong generalization ability and high usability. This application also provides a code development platform, computing device cluster, computer-readable storage medium, and computer program product corresponding to the above method.
[0007] Firstly, this application provides a test code generation method. This method can be executed by a code development platform. The code development platform is a platform used to develop test code, such as a testing platform. The code development platform can be software, which can be standalone software with test code generation capabilities, or integrated into other software as plugins, components, mini-programs, functional modules, etc. The aforementioned software can be provided to customers as a software package for self-deployment, or provided to users as a cloud service. After subscribing to the cloud service, users can invoke the cloud service to execute the test code generation method of this application. In some possible implementations, the code development platform can also be a hardware platform, such as a cluster of computing devices with test code generation capabilities. When the computing device cluster is running, it executes the test code generation method of this application.
[0008] Specifically, the code development platform can receive test code generation requests. These requests generate test code for a specific test object. Based on the request, the platform determines the source domain's domain label and domain mapping relationship. The source domain label indicates the domain to which the test object's source code belongs. The domain mapping relationship includes a mapping between the source and target domains, where the target domain is the domain to which the generated test code belongs. The platform can then assemble code generation hints based on the source domain's domain label and the code generation request. These hints guide the code generation model to generate test code for the test object in the source domain. The code generation model is trained on a language model. The platform inputs the hints into the code generation model to obtain the test code for the test object in the source domain. Based on the domain mapping relationship, the platform maps this source domain code to the feature space of the target domain, thus obtaining the test code for the test object in the target domain.
[0009] This method identifies the source and target domains through adaptive domain recognition, and uses a code generation model to understand and analyze the testing requirements of different domains, generating test code for the source domain. Then, based on domain mapping relationships, it maps the source domain test code to the feature space of the target domain, thereby achieving efficient generation of cross-domain test code. In this way, it can efficiently generate test code for different programming languages, application types, business domains, technology stacks, or data characteristics, solving the problem that related methods may perform poorly on broader programming tasks and have limited generalization ability. It can flexibly generate test code for different domains, adapt to various special cases or changes in requirements, and has high availability.
[0010] Moreover, this method reuses the architecture of the source domain, mapping the source domain's test code to the feature space of the target domain. This enables efficient generation of cross-domain test code without the need to train code generation models for different domains, reducing the number of model training iterations and costs. It can adapt to cross-domain software testing needs and improve the performance of cross-domain tasks. Furthermore, by automating the generation of cross-domain test code, it can generate more comprehensive test cases, improving software test coverage. This solves the problems of insufficient test coverage in related technologies and the need for lengthy manual analysis and isolation of discovered defects.
[0011] In some possible implementations, the code development platform can retrieve code generation databases based on the domain tags of the source domain and the test code generation request, obtain the retrieval results, and then assemble code generation suggestions based on the domain tags of the source domain, the test code generation request, and the retrieval results.
[0012] This method supports retrieving code generation databases based on source domain tags and assembling the search results into code generation suggestions. This can enrich the information content of code generation suggestions and improve their quality, thus achieving Retrieval-Augmented Generation (RAG) and improving the quality of generated test code.
[0013] In some possible implementations, the code development platform can obtain a code generation suggestion template based on the domain tags of the source domain, the test code generation request, and the search results, and then assemble the code generation suggestion according to the test code generation request and the search results.
[0014] This method can request a code generation suggestion template corresponding to the test code generation request based on the domain tags and search results of the source domain. It can assemble suggestions based on the matching code generation suggestion template, which can further improve the quality of code generation suggestions. This can accelerate the generation of subsequent test code and improve the quality of the generated test code.
[0015] In some possible implementations, the code development platform can also evaluate the test code of the test object in the target domain, obtain the evaluation results, and then update the domain recognition optimization strategy, code generation model parameters, mapping parameters, domain recognition parameters, model training corpus, or code generation prompt templates based on the evaluation results.
[0016] The evaluation result can be the execution result of the test code. The code development platform can adjust the domain identification optimization strategy in real time based on the execution result of the test code, and adjust and optimize the parameters of components such as the domain adaptive identification component, code generation model, feature selection and mapper, guiding the formulation of new data collection and processing strategies. This method forms a complete test code generation scheme through closed-loop feedback, overcoming the problem that related technologies perform well on specific types of tasks but poorly on broader programming tasks, prioritizing generalization ability. Furthermore, the real-time test code feedback and optimization mechanism helps to discover more potential problems and improve software quality.
[0017] In some possible implementations, the code development platform can assemble domain recognition hints based on test code generation requests, input these hints into a domain recognition model, and obtain domain labels for the source and target domains. The domain recognition model is generated by training a pre-trained model.
[0018] This method also supports generating request assembly domain identification prompts based on test code, and identifying the source and target domains based on the domain identification prompts through a domain identification model, thus ensuring the accuracy of domain identification.
[0019] In some possible implementations, the domain recognition model is trained as follows: a feature selector and mapper, an instance weighter, and an adversarial trainer are initialized, wherein the feature selector and mapper includes a feature selection matrix and a feature mapping matrix, and the adversarial trainer includes a feature extractor, a domain classifier, and a domain discriminator; and the parameters of the pre-trained model, the feature selection matrix, the feature mapping matrix, the feature extractor, the domain classifier, and the domain discriminator are updated according to a joint loss function.
[0020] This method combines feature selection with the loss function (or objective function) of the mapper, instance weighter, and adversarial trainer for joint optimization, thereby achieving precise optimization and improving the accuracy of the domain recognition model.
[0021] In some possible implementations, the domain label includes at least one of a business domain label or a technical domain label. The business domain label may include one or more of a business type label (e.g., finance, healthcare), a user behavior label, and a data feature label. The technical domain label may include one or more of an application type label, a programming language label, a framework label, and a technology stack label. The application type label indicates whether the application is a desktop application, a mobile application, or a web application. The data feature label may indicate data characteristics, such as whether the data dimension is high-dimensional or low-dimensional. High-dimensional data includes, but is not limited to, images, and low-dimensional data includes, but is not limited to, text.
[0022] This method can understand and analyze testing requirements in different domains and efficiently generate cross-domain test code. It is applicable to multiple domains, including but not limited to different programming languages, different application types, different business domains, different technology stacks, and different data characteristics, and has high availability.
[0023] Secondly, this application provides a code development platform. The code development platform includes:
[0024] A test agent is used to receive a test code generation request, which is used to generate test code for a test object; and to determine the domain label of the source domain and the domain mapping relationship based on the test code generation request. The domain label of the source domain is used to indicate the domain to which the source code of the test object belongs, and the domain mapping relationship includes the mapping relationship between the source domain and the target domain, wherein the target domain is the domain to which the test code belongs.
[0025] The testing agent is further configured to assemble a code generation prompt based on the domain label of the source domain and the test code generation request. The code generation prompt is used to guide the code generation model to generate test code for the test object in the source domain. The code generation model is generated by training a language model. The code generation prompt is input into the code generation model to obtain the test code for the test object in the source domain. Based on the domain mapping relationship, the test code for the test object in the source domain is mapped to the feature space of the target domain to obtain the test code for the test object in the target domain.
[0026] In some possible implementations, the code development platform further includes a knowledge repository, which includes a code generation database;
[0027] The test agent is specifically used for:
[0028] Based on the domain tags of the source domain and the test code generation request, the code generation database is retrieved to obtain the retrieval results;
[0029] Based on the domain tags of the source domain, the test code generation request, and the search results, code generation suggestions are assembled.
[0030] In some possible implementations, the test agent is specifically used for:
[0031] Based on the domain tags of the source domain, the test code generation request, and the search results, obtain the code generation prompt template;
[0032] Based on the test code generation request and the search results, code generation prompts are assembled according to the code generation prompt template to obtain code generation prompts.
[0033] In some possible implementations, the test agent is specifically used for:
[0034] The test code of the test object in the target domain is evaluated to obtain the evaluation result;
[0035] Update the domain identification optimization strategy, the parameters of the code generation model, the mapping parameters, the domain identification parameters, the model training corpus, or the code generation prompt template based on the evaluation results.
[0036] In some possible implementations, the test agent is specifically used for:
[0037] Based on the test code generation request, a domain identification prompt is assembled;
[0038] The domain identification prompts are input into the domain identification model to obtain the domain labels of the source domain and the target domain. The domain identification model is generated by training a pre-trained model.
[0039] In some possible implementations, the code development platform also includes:
[0040] The artificial intelligence center is used to initialize a feature selector and mapper, an instance weighter, and an adversarial trainer. The feature selector and mapper includes a feature selection matrix and a feature mapping matrix. The adversarial trainer includes a feature extractor, a domain classifier, and a domain discriminator. Based on the joint loss function, the parameters of the pre-trained model, the feature selection matrix, the feature mapping matrix, the feature extractor, the domain classifier, and the domain discriminator are updated.
[0041] In some possible implementations, the domain label includes at least one of a business domain label or a technology domain label.
[0042] Thirdly, this application provides a computing device cluster. The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is used to execute instructions stored in the at least one memory to cause the computing device or the computing device cluster to perform the test code generation method as described in the first aspect or any implementation thereof.
[0043] Fourthly, this application provides a computer-readable storage medium storing instructions that instruct a computing device or a cluster of computing devices to execute the test code generation method described in the first aspect or any implementation thereof.
[0044] Fifthly, this application provides a computer program product containing instructions that, when run on a computing device or a cluster of computing devices, causes the computing device or cluster of computing devices to execute the test code generation method described in the first aspect or any implementation thereof.
[0045] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0046] To more clearly illustrate the technical methods of this application, the accompanying drawings used will be briefly described below.
[0047] Figure 1 is a schematic diagram of the architecture of a code development platform provided in this application;
[0048] Figure 2 is a flowchart illustrating the inter-module process in a code development platform provided in this application;
[0049] Figure 3 is a flowchart of a test code generation method provided in this application;
[0050] Figure 4 is a schematic diagram of the training process of a domain recognition model provided in this application;
[0051] Figure 5 is a schematic diagram of the structure of a computing device provided in this application;
[0052] Figure 6 is a schematic diagram of the structure of a computing device cluster provided in this application;
[0053] Figure 7 is a schematic diagram of another computing device cluster provided in this application;
[0054] Figure 8 is a schematic diagram of another computing device cluster provided in this application. Detailed Implementation
[0055] The terms "first" and "second" used in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first" and "second" may explicitly or implicitly include one or more of that feature.
[0056] First, some technical terms involved in the embodiments of this application will be introduced.
[0057] Test code refers to code used to test a test object. The test object can be one or more functional modules of software, or one or more interfaces of software. Functional modules can include, but are not limited to, methods or functions that implement corresponding functions, and interfaces can be application programming interfaces (APIs) for methods or functions. In some examples, test code can be executable code corresponding to test cases (TCs). It should be noted that test code can be software test code or hardware test code, such as chip test code; this application does not impose any restrictions on this.
[0058] A test case is a description of a test task performed on a specific piece of software, reflecting the test plan, methods, techniques, and strategies. Specifically, a test case is a set of test inputs, execution conditions, and expected results compiled for a specific objective to verify whether a particular software requirement is met.
[0059] Test code generation technologies mainly include model-based code generation, rule-based code generation, and automated unit testing tools. The model can be a language model (LM), represented by LLM (Language Modeling). Due to the groundbreaking progress and outstanding performance of LLM in code generation, more and more developers are using LLM to assist in generating test code.
[0060] This example illustrates the generation of test code for an interface to be tested. In this example, the testing tool first obtains the interface definition, at least one test case for testing the interface, and test code generation requirements. Then, based on the interface definition, test cases, and test code generation requirements, it generates a prompt, such as a hint. The prompt is then input into the LLM (Linux Virtual Machine) to obtain the generated test code. The generated test code may include automatically generated test code.
[0061] The LLM-based test code generation methods described above perform well on specific types of programming tasks, such as single-domain programming tasks, and are applicable to specific programming languages and frameworks. However, these methods may perform poorly on broader programming tasks, exhibiting limited generalization ability. Specifically, the test code automatically generated by these methods may lack flexibility and struggle to adapt to various special cases or changing requirements, thus limiting the application of LLM-based test generation methods in practical software development.
[0062] In view of this, this application provides a test code generation method. This method can be executed by a code development platform. A code development platform is a platform used to develop test code, and in some cases, it can also be called a test platform. The code development platform can be software, which can be standalone software with test code generation capabilities, or integrated into other software as a plugin, component, app, or functional module. For example, the code development platform can be an Integrated Development Environment (IDE) plugin, which, when triggered, can collaborate with the IDE to generate test code. The aforementioned software can be provided to customers as a software package for self-deployment, or provided to users as a cloud service. After subscribing to the cloud service, users can invoke the cloud service to execute the test code generation method of this application. In some possible implementations, the code development platform can also be a hardware platform, such as a cluster of computing devices with test code generation capabilities. When the computing device cluster is running, it executes the test code generation method of this application.
[0063] Specifically, the code development platform can receive test code generation requests. These requests generate test code for a specific test object. Based on the request, the platform determines the source domain's domain label and domain mapping relationship. The source domain label indicates the domain to which the test object's source code belongs. The domain mapping relationship includes a mapping between the source and target domains, where the target domain is the domain to which the generated test code belongs. The platform can then assemble code generation hints based on the source domain's domain label and the code generation request. These hints guide the code generation model to generate test code for the test object in the source domain. The code generation model is generated by training a language model; for example, the code generation module could be a large code model trained on a base model for a test code generation task. The platform inputs the code generation hints into the code generation model to obtain the test code for the test object in the source domain. Based on the domain mapping relationship, the platform maps the test code for the test object in the source domain to the feature space of the target domain, thus obtaining the test code for the test object in the target domain.
[0064] This method identifies the source and target domains through adaptive domain recognition, and uses a code generation model to understand and analyze the testing requirements of different domains, generating test code for the source domain. Then, based on domain mapping relationships, it maps the source domain test code to the feature space of the target domain, thereby achieving efficient generation of cross-domain test code and reducing manual coding time. This method efficiently generates test code for different programming languages, application types, business domains, technology stacks, or data characteristics, solving the problem that related methods may perform poorly on broader programming tasks and have limited generalization ability. It can flexibly generate test code for different domains, adapt to various special cases or changes in requirements, and has high availability.
[0065] To make the technical solution of this application clearer and easier to understand, the system architecture of the code development platform of this application is described below with reference to the accompanying drawings.
[0066] Referring to Figure 1, which shows a schematic diagram of the architecture of a code development platform, the code development platform 10 includes a test agent 101. Furthermore, the code development platform 10 may also include an artificial intelligence center 103, a data center 105, a knowledge repository 106, a hint center 107, an engine 108, and an inference center 109.
[0067] The test agent 101 is the core of the code development platform 10, used to generate test code in response to test code generation requests. Specifically, the test agent 101 may include a domain adaptive recognition component, a prompt assembly component, a model inference component, and a cross-domain feature mapping component.
[0068] The domain adaptive identification component receives test code generation requests, which generate test code for the test object. Based on these requests, it determines the source domain label and the domain mapping relationship. The source domain label indicates the domain to which the test object's source code belongs. The domain mapping relationship includes a mapping between the source domain and the target domain, where the target domain is the domain to which the test code belongs. Domain labels can include at least one of business domain labels or technical domain labels. These labels can be coarse-grained or fine-grained. For example, business domain labels can include one or more of business type labels (e.g., finance, healthcare), user behavior labels, and data feature labels. Technical domain labels can include one or more of application type labels, programming language labels, framework labels, and technology stack labels. Application type labels indicate whether the application is a desktop application, mobile application, or web application. Data feature labels can indicate data characteristics, such as whether the data dimension is high-dimensional or low-dimensional. High-dimensional data includes, but is not limited to, images, and low-dimensional data includes, but is not limited to, text.
[0069] The suggestion assembly component is used to assemble code generation suggestions based on the source domain's domain tags and the code generation request. These suggestions guide the code generation model to generate test code for the test object within the source domain. The code generation model is trained on a language model.
[0070] The model inference component is used to generate a code model from the input of code generation prompts, obtaining the test code of the test object in the source domain. The cross-domain feature mapping component is used to map the test code of the test object in the source domain to the feature space of the target domain according to the domain mapping relationship, obtaining the test code of the test object in the target domain.
[0071] Furthermore, the test agent 101 may also include a preprocessing component, a retrieval and re-ranking component, a verification and evaluation component, and a feedback component. The preprocessing component preprocesses the context obtained from the test code generation request based on domain labels. The domain labels can be domain labels of the source domain identified by the domain adaptive recognition component, and preprocessing may include noise removal, duplicate removal, and / or removal of useless data. In this example, useless data refers to data unrelated to generating test code. The retrieval and re-ranking component retrieves the code generation database based on the domain labels of the source domain and the code generation request, obtaining retrieval results. The code generation database can be a database related to code generation in the knowledge repository 106. The verification and evaluation component evaluates the test code of the test object in the target domain, obtaining evaluation results. The feedback component receives feedback information regarding the evaluation results, facilitating updates to the domain recognition optimization strategy, code generation model parameters, mapping parameters, domain recognition parameters, model training corpus, database, or code generation prompt template based on the feedback information. As shown in Figure 1, the feedback component can feed back feedback information to the domain adaptive recognition component, artificial intelligence center 103, data center 105, knowledge repository 106, or prompt center 107 in the test agent 101. The domain adaptive recognition component can update its domain recognition optimization strategy based on the feedback information. This optimization strategy can be a strategy that optimizes the domain labels or domain mapping relationships output by the domain adaptive recognition. The artificial intelligence center 103 can optimize the parameters of the code generation model based on the feedback information. The data center 105 can optimize the model training corpus based on the feedback information. The knowledge repository 106 can optimize the code generation database based on the feedback information. The prompt center 107 can optimize prompt templates based on the feedback information, such as optimizing code generation prompt templates.
[0072] Artificial Intelligence Center 103, also known as the AI Hub, is primarily used for model training, evaluation, and optimization. Specifically, the AI Hub can be used to train, evaluate, or optimize code generation models. These models are generated by training a language model. In some examples, the code generation model can be a large code generation model fine-tuned from a general LLM. In some possible implementations, the AI Hub is also used to train, evaluate, or optimize domain recognition models. These models can be large domain recognition models.
[0073] Data center 105, also known as the data center, provides datasets for model training. This dataset may include a training set for training code generation models, and further, a training set for training domain recognition models. It should be noted that the dataset may also include validation and test sets. Models, such as code generation and domain recognition models, can be fitted with parameters on the training set. The fitted model is then used to make predictions on the validation set, and the prediction results can be used to adjust the model's hyperparameters. Hyperparameters may include, but are not limited to, the number of neurons in the hidden layers of the model's network structure. Data center 105 also provides corpora related to code generation and / or domain recognition. Data center 105 can perform corpus cleaning on the code generation and / or domain recognition corpora. Furthermore, data center 105 can perform corpus checks and quality assessments on the aforementioned corpora. Data center 105 can then store corpora that pass the checks or whose quality assessment results meet the requirements into knowledge warehouse 106.
[0074] Knowledge repository 106, also known as the knowledge repository, is primarily used to provide knowledge related to code generation and / or domain identification. In some possible implementations, knowledge repository 106 includes at least one of a code generation database or a domain identification database. The code generation database, also known as a code generation corpus, includes code generation-related corpus and knowledge; the domain identification database, also known as a domain identification resource repository or domain identification corpus, includes domain identification-related corpus and knowledge.
[0075] The prompt center 107, also known as the prompt center, is primarily used to provide at least one of the following: domain-aware prompt templates or code generation prompt templates. Furthermore, the prompt center 107 can also perform intent optimization to obtain high-quality prompts.
[0076] Engine 108, also known as the engine, is primarily used for authentication, configuration management, and agent registration. Agent registration involves recording the identifier (ID) and description information of test agent 101 in Engine 108. The ID of test agent 101 uniquely identifies the agent, while the description describes its functionality or attributes. Thus, when Engine 108 receives a test code generation request, it can dispatch the request or the context obtained from the request to test agent 101. Furthermore, Engine 108 can authenticate the test code generation request. If authentication is successful, it dispatches the request or the context obtained from the request to test agent 101. The context may include at least one of the following: the source code of the test object, its dependencies, and its import information.
[0077] The Inference Center 109, also known as the Infer Hub, is primarily used for inference through a code generation model to generate test code. Specifically, the Inference Center 109 provides an API for the code generation model, which the model inference component of the test agent 101 can call to drive the model to perform inference and generate test code. Furthermore, the Inference Center 109 can also perform inference through a domain recognition model to obtain domain labels for both the source and target domains. In this case, the Inference Center 109 provides an API for the domain recognition model, which the domain adaptive recognition component can call to drive the model to perform inference and obtain domain labels for both the source and target domains.
[0078] The components or modules shown in Figure 1 are tightly interconnected through data flow and control flow, forming a closed-loop automated processing flow. As shown in Figure 2, the data management module (e.g., the module in data center 105 used for data management) collects, organizes, cleans, and stores the corpus for domain identification and code generation. The domain adaptive identification module (e.g., the domain adaptive identification component in test agent 101) uses a pre-trained domain identification model to automatically identify the domain to which the test object (e.g., software) belongs, obtaining the domain label of the source domain. Furthermore, the domain adaptive identification module can also obtain the domain label of the target domain. The target domain is the domain to which the test code belongs. The domain adaptive identification module can obtain the mapping relationship between the source domain and the target domain based on the domain labels of the source domain and the target domain. The preprocessing module (e.g., the preprocessing component in test agent 101) removes noise, duplicates, or useless data from the context based on the domain label of the source domain. The model processing module (e.g., the retrieval reordering component, prompt assembly component, and model inference component in test agent 101) retrieves the code generation database based on the domain tags of the source domain and the code generation request, obtains the retrieval results, assembles code generation prompts based on the domain tags of the source domain, the code generation request, and the retrieval results, and inputs the code generation prompts into the code generation model to obtain the test code for the test object in the source domain. Specifically, when assembling the prompts, the model processing module can obtain a code generation prompt template based on the domain tags of the source domain, the code generation request, and the retrieval results, and assemble the code generation prompts according to the code generation request and the retrieval results.
[0079] Cross-domain feature mapping modules (such as the cross-domain feature mapping component in Test Agent 101) map the test code of the test object in the source domain obtained by the model processing module to the feature space of the target domain, thereby obtaining the test code of the test object in the target domain, thus achieving seamless switching of test code between different domains.
[0080] The verification and evaluation module (such as the verification and evaluation component in Test Agent 101) is used to evaluate the test code of the test object in the target domain and obtain evaluation results. Evaluation dimensions can include quality evaluation metrics such as accuracy, recall, and pass rate (e.g., execution pass rate). The evaluation results can include the quality of the test code, which can be represented by the metric values. The verification and evaluation module can also output the evaluation results in the form of a test report.
[0081] The feedback module (such as the feedback component in the test agent 101) can obtain feedback information on the evaluation results of the test code and feed the feedback information back to the domain adaptive recognition module, the artificial intelligence center 103, the data center 105, the knowledge warehouse 106, or the prompt center 107 for optimization. This allows the model processing module to generate test code based on the optimized strategy (such as the updated domain recognition optimization strategy), the optimized parameters (such as the updated parameters of the code generation model, the updated mapping parameters, and the updated domain recognition parameters), the optimized model training corpus (such as the updated model training corpus), or the optimized prompt template (such as the updated code generation prompt template).
[0082] Based on the code development platform 10 shown in Figure 1, this application also provides a test code generation method. The test code generation method of this application will be described in detail below with reference to the accompanying drawings.
[0083] Referring to Figure 3, an interactive flowchart of a test code generation method is shown. This method is applied to a code development platform 10, which includes a test agent 101. Further, the code development platform 10 may also include an artificial intelligence center 103, a data center 105, a knowledge repository 106, a hint center 107, and an inference center 109. The method specifically includes the following steps:
[0084] S302, Test agent 101 receives the test code generation request.
[0085] A test code generation request is used to generate test code for a test object. In some examples, a test code generation request may be an online inference request, used to generate test code for the test object through online inference. A test object is the object that is tested using the test code. A test object can be software, such as one or more functional modules of the software, or one or more APIs of the software. In some examples, a test object can also be hardware, such as a chip. Accordingly, the test code can be software test code or hardware test code. Software test code is code that tests software, and hardware test code is code that tests hardware (such as a chip). Test code can be executable code corresponding to a test case (TC).
[0086] In some possible implementations, the test code generation request includes the source code of the test object or the location information of the source code of the test object. The location information may include the start and end line numbers of the test object within the code file. The location information may also include the path to the test file containing the source code of the test object. Furthermore, the test code generation request may also include the domain of the test code to be generated. This domain can be a technical field or a business domain. The technical field may include at least one of a programming language, framework, or technology stack, while the business domain may include at least one of a business type, user behavior, or data characteristics.
[0087] Test agent 101 can provide a code generation request API to users (e.g., user applications). Users can call the code generation request API, passing in the source code of the test object or the location information of the source code through the API interface to form a test code generation request. Test agent 101 can receive the test code generation requests generated by users calling the code generation request API.
[0088] S304. Test agent 101 retrieves the domain identification database in knowledge repository 106 based on the test code generation request.
[0089] Specifically, test agent 101 can generate a request based on the test code to obtain context. This context may include the source code of the test object, import information, and dependency information. Import information may include identifiers of files imported by import statements, and dependency information may include identifiers of files the test object depends on. Test agent 101 can then search the domain identification database in knowledge repository 106 based on the context to obtain search results.
[0090] The search results include the retrieved domain identification results and similarity scores. Domain identification results can be domain labels determined by the retrieved domain identification database. Domain labels can include at least one of the domain labels of the source domain or the target domain. The source domain domain label indicates the domain to which the source code of the test object belongs, and the target domain is the domain to which the test code to be generated belongs. For example, if a user intends to migrate a function from the financial domain to the medical domain, the source domain can be the financial domain, and the target domain can be the medical domain. The test domain code generation method of this application can achieve cross-domain generation of test code for the medical domain, and the execution of this test code can be evaluated before generating the test code for the target domain. Furthermore, the search results can also include domain mapping relationships, which include mapping relationships between the source domain and the target domain. For example, after retrieving the domain labels of the source domain and the target domain, the test agent 101 can generate a mapping relationship between the source domain and the target domain.
[0091] Similarity can be calculated as the similarity between a context vector (obtained by vectorizing the context) and a knowledge vector in a domain identification database. This similarity can be used to indicate the credibility of the retrieved domain identification results. Generally, a higher similarity indicates a higher credibility of the retrieved domain identification results, while a lower similarity indicates a lower credibility.
[0092] S306. Test agent 101 receives the search results returned by the domain recognition database. The search results include the domain recognition results and similarity.
[0093] S308. Test agent 101 compares the similarity of the domain recognition results with a threshold. If the similarity is greater than or equal to the threshold, execute S310; if the similarity is less than the threshold, execute S312.
[0094] A threshold is a measure of the similarity level. The threshold can be set empirically. Specifically, the test agent 101 can calculate the difference between the similarity of the domain identification result and the threshold, or calculate the quotient between the similarity of the domain identification result and the threshold, and compare the similarity of the domain identification result and the threshold based on the difference or quotient. When the similarity is greater than or equal to the threshold, it indicates that the similarity of the retrieved domain identification result has high confidence and can be used as the final domain identification result. When the similarity is less than the threshold, it indicates that the similarity of the retrieved domain identification result has low confidence, and S312 can be executed to request the domain identification model to perform identification.
[0095] S310, Test agent 101 returns the domain recognition result.
[0096] Specifically, test agent 101 can return domain identification results to the user through the domain identification results API.
[0097] It should be noted that the test code generation method of this application may also omit S310. For example, the test agent 101 may generate test code for the source domain based on the domain identification results in the background or backend, and generate test code for the target domain through cross-domain feature mapping.
[0098] S312, Test agent 101 requests the domain recognition prompt template corresponding to the test code generation request from prompt center 107.
[0099] In specific implementation, the test agent 101 can send context to the prompt center 107, so that the prompt center 107 can determine the domain identification prompt template corresponding to the test code generation request from at least one domain identification prompt template based on the context. The domain identification prompt template may include placeholders for at least one type of information, used to indicate where to fill or replace the corresponding type of information at the placeholder's location.
[0100] S314. Test agent 101 receives the domain recognition prompt template corresponding to the test code generation request returned by prompt center 107.
[0101] S316. Test agent 101 generates domain recognition prompts according to the domain recognition prompt template based on the test code generation request.
[0102] Specifically, the test agent 101 can fill or replace the placeholders in the domain recognition prompt template with the context of the request generated according to the test code to assemble the prompts and obtain the domain recognition prompts.
[0103] S318, Test agent 101 sends a domain recognition prompt to the domain recognition model in inference center 109.
[0104] Domain recognition models are used for domain-adaptive recognition. These models can be large and are typically trained from pre-trained models. Training methods can include, but are not limited to, fine-tuning. For example, when training its domain recognition model, AI HUB can fine-tune the pre-trained model using a small number of samples to obtain the desired model.
[0105] The inference center 109 can provide an API for the domain recognition model, and the test agent 101 can pass domain recognition hints to the domain recognition model through the API. Specifically, the inference center 109 can configure the interface parameters of the domain recognition model's API as domain recognition hints, generate an API call request based on the API configured with domain recognition hints, and send the API call request to the domain recognition model, thereby realizing the sending of domain recognition hints to the domain recognition model.
[0106] S320, Test agent 101 receives the domain recognition results returned by inference center 109.
[0107] The domain identification results returned by the inference center 109 include those generated by the domain identification model. These results may include domain labels for the source and target domains. Furthermore, the domain identification results may also include domain mapping relationships, such as a mapping between the source and target domains.
[0108] Furthermore, the test agent 101 can also receive the credibility of the domain identification result returned by the inference center 109. The credibility can be determined based on the probability of obtaining the domain identification result through inference. For example, the test agent 101 can receive the domain labels of the source domain and the target domain, along with the credibility of each domain label, returned by the inference center 109, so that the user can determine the domain labels of the source domain and the target domain based on the credibility.
[0109] S322, Test agent 101 returns the domain recognition result.
[0110] Specifically, test agent 101 can return the domain identification result to the user. In this way, the user can generate a test code generation request carrying the domain label of the source domain based on the domain identification result.
[0111] It should be noted that the test code generation method of this application may also omit the above-described S322. For example, the test agent 101 may generate a test code generation request carrying the domain label of the source domain based on the domain identification result.
[0112] The above-described S304 to S322 are specific implementations of determining the domain label and domain mapping relationship of the source domain according to the test code generation request in this application embodiment. In other possible implementations of this application embodiment, the test agent 101 can also achieve adaptive domain recognition in other ways. Specifically, S312 to S318 are specific implementations of assembling domain recognition prompts according to the test code generation request, inputting the domain recognition prompts into the domain recognition model, and obtaining the domain label of the source domain and the domain label of the target domain. In practical applications, the assembly of domain recognition prompts and domain label inference can also be performed in other ways.
[0113] S324. Test agent 101 receives a test code generation request carrying the domain label of the source domain.
[0114] When the test agent 101 generates a test code generation request carrying the domain label of the source domain based on the domain identification result and the test code generation request, the above-described S324 may not be executed. Alternatively, the test agent 101 may not generate or receive a test code generation request carrying the domain label of the source domain, but instead use the domain label of the source domain and the test code generation request independently for retrieval, request prompt templates, or prompt assembly.
[0115] S326, Test agent 101 retrieves the code generation database in knowledge repository 106 based on the test code generation request carrying the domain label of the source domain.
[0116] Specifically, test agent 101 can parse the test code generation request carrying the domain label of the source domain to obtain the context and the domain label of the source domain. Test agent 101 can then retrieve the code generation database based on the context and the domain label of the source domain. The code generation database includes knowledge vectors related to code generation. Test agent 101 can construct a fusion vector based on the context vector and the domain label vector of the source domain, and retrieve the code generation database based on the distance between the fusion vector and the knowledge vectors in the code generation database.
[0117] S328. Test agent 101 receives the search results returned by the code-generated database.
[0118] The search results returned by the code generation database may include a knowledge vector corresponding to the test code generation request carrying a domain label from the source domain. This knowledge vector can be used to assist in generating test code.
[0119] S330, Test agent 101 requests a code generation prompt template corresponding to the test code generation request from prompt center 107 based on the search results returned by the code generation database and the domain tags of the source domain.
[0120] Specifically, the prompt center 107 may include at least one code generation prompt template. The test agent 101 can match the code generation prompt template corresponding to the test code generation request from the at least one code generation prompt template based on the retrieval results returned by the code generation database and the domain tags of the source domain.
[0121] S332, Test agent 101 receives the code generation prompt template returned by prompt center 107.
[0122] S334. Test agent 101 assembles code generation prompts according to the code generation prompt template based on the test code generation request and retrieval results.
[0123] The code generation suggestion template includes placeholders for different information. Test agent 101 can fill or replace the placeholders in the code generation suggestion template according to the context and search results obtained from the test code generation request, thereby assembling the suggestion and obtaining the code generation suggestion.
[0124] The above-described S324 to S334 are specific implementations of assembling code generation prompts based on the domain tags of the source domain and the test code generation request in this embodiment of the application. Specifically, S326 to S328 involve retrieving the code generation database based on the domain tags of the source domain and the test code generation request, obtaining the retrieval results, and then assembling the code generation prompts based on the domain tags of the source domain, the test code generation request, and the retrieval results. S330 involves obtaining the code generation prompt template based on the domain tags of the source domain, the test code generation request, and the retrieval results. In practical applications, the test agent 101 can also assemble code generation prompts through other methods.
[0125] S336, Test agent 101 inputs code generation prompts into the code generation model in inference center 109.
[0126] S338, Test agent 101 receives the test code of the test object in the source domain returned by the code generation model.
[0127] S340 and test agent 101 map the test code of the test object in the source domain to the feature space of the target domain according to the domain mapping relationship, and obtain the test code of the test object in the target domain.
[0128] The domain mapping relationship includes the mapping relationship between the source domain and the target domain, which can be represented by a matrix. The test agent can use matrix transformations to map the test code of the test object in the source domain to the feature space of the target domain, thereby obtaining the test code of the test object in the target domain.
[0129] S342, Test agent 101 evaluates the test code of the test object in the target domain and obtains the evaluation result.
[0130] Test agent 101 evaluates the test code of the test object in the target domain and obtains the evaluation results. The evaluation dimensions may include quality evaluation metrics such as accuracy, recall, and pass rate (e.g., execution pass rate). The evaluation results can include the quality of the test code, which can be represented by the metric values of the evaluation metrics. Furthermore, test agent 101 can also output the evaluation results in the form of a test report.
[0131] S344, Test agent 101 sends feedback information on the evaluation results to data center 105 to update the model training corpus.
[0132] S346, the test agent 101 sends feedback information on the evaluation results to the knowledge repository 106 to update the knowledge vector.
[0133] S348, Test agent 101 sends feedback information on the evaluation results to prompt center 107 to update the code generation prompt template.
[0134] S350, the test agent 101 sends feedback information on the evaluation results to the artificial intelligence center 103 to update the parameters of the code generation model.
[0135] S352, Test agent 101 updates the domain recognition optimization strategy based on feedback information from the evaluation results.
[0136] Specifically, the test agent 101 can send evaluation results to the engine 108, and the engine 108 can obtain feedback information based on the evaluation results. In some possible implementations, the engine 108 can display the evaluation results, receive feedback information on the evaluation results, and send feedback information to the test agent. The feedback information may include at least one of the following: an updated domain recognition optimization strategy, updated parameters of the code generation model, updated mapping parameters, updated domain recognition parameters, updated model training corpus, or updated code generation prompt template.
[0137] The test agent 101 can send corresponding feedback information to the data center 105, knowledge warehouse 106, prompt center 107, or artificial intelligence center 103. Alternatively, the feedback component in the test agent 101 can also send feedback information to the domain adaptation recognition component. Specifically, the data center 105 can update the model training corpus based on the feedback information, the knowledge warehouse 106 can update the code generation database (e.g., updating knowledge vectors in the code generation database), the prompt center 107 can update the code generation prompt template based on the feedback information, and the artificial intelligence center 103 can update the parameters of the code generation model based on the feedback information.
[0138] The steps S342 to S352 described above are optional steps in the embodiments of this application. The test code generation method of this application may also omit the execution of steps S342 to S352. For example, when the quality of the generated test code is high, steps S342 to S352 may be omitted.
[0139] Based on the above description, this application provides a test code generation method. This method determines the source and target domains through adaptive domain identification, understands and analyzes the testing requirements of different domains using a code generation model, generates test code for the source domain, and then maps the source domain test code to the feature space of the target domain based on domain mapping relationships, thereby achieving efficient generation of cross-domain test code. In this way, it can efficiently generate test code for different programming languages, application types, business domains, technology stacks, or data characteristics, solving the problem that related methods may perform poorly on a wider range of programming tasks and have limited generalization ability. It can flexibly generate test code for different domains, adapt to various special situations or changes in requirements, and has high availability.
[0140] In the embodiment shown in Figure 3, a key aspect of test code generation is domain-adaptive recognition. Domain-adaptive recognition can be achieved using a domain recognition model. This model can be trained from a pre-trained model. The training process of the domain recognition model will be explained in detail below with reference to an embodiment.
[0141] Referring to Figure 4, which illustrates a training process for a domain recognition model, the training of the domain recognition model can be performed by the Artificial Intelligence Center 103. The Artificial Intelligence Center 103 can train the domain recognition model using a cross-domain adaptive algorithm based on a large model. This algorithm improves performance in cross-domain tasks by combining the deep representation learning capabilities of the large model with the domain-specific optimization of the adaptive algorithm. Specifically, the Artificial Intelligence Center 103 can jointly optimize the pre-trained model using the objective functions of a feature selection and mapper, an instance weighter, and an adversarial trainer to obtain the domain recognition model. The training process of the domain recognition model may include the following steps:
[0142] S402, Artificial Intelligence Center 103 obtains pre-trained models.
[0143] A pre-trained model is a model trained on a large-scale dataset. Pre-trained models can be large models, including LLMs. Through pre-training, the general feature representations learned on large-scale datasets can be used as initialization parameters to accelerate the training process on specific tasks. In other words, the AI Center 103 can use a pre-trained model as a starting point to train a domain recognition model. The initial parameters of the pre-trained model can be determined based on built-in domain knowledge. The AI Center 103 can understand and analyze the testing requirements of different domains, obtain relevant domain knowledge from the knowledge repository 106, and initialize the parameters of the pre-trained model.
[0144] S404, Artificial Intelligence Center 103 initializes the feature selector and mapper, instance weighter and adversarial trainer.
[0145] The goal of feature selection and mapping is to select representative features and map them from the source domain to the feature space of the target domain. The process of feature selection and mapping can be represented as a combination of a feature selection matrix S and a feature mapping matrix M. Assume the features in the source domain are X. s The feature of the target domain is X t Then the mapped features can be represented as: X′ s =SMX s (1)
[0146] Where, X′ s S is the feature selection matrix, used to select representative features, such as the most important features, and M is the feature mapping matrix, used to map the features of the source domain to the feature space of the target domain.
[0147] The goal of the instance weighter is to adjust the importance of different instances during training to mitigate the neighborhood bias problem. The weighted loss function can be expressed as:
[0148] Among them, w i and w j , respectively, are the weights of instances in the source domain and the target domain; l is the loss function; These are the features and labels mapped from instances in the source domain. It consists of the features and labels mapped from instances in the target domain, n s n represents the number of instances (samples) in the source domain. t This represents the number of instances (samples) in the target domain.
[0149] Adversarial trainers improve the generalization ability of pre-trained models by introducing adversarial noise into them. In the context of domain adaptation, adversarial trainers can encourage pre-trained models to learn domain-invariant features. The loss function of adversarial training typically consists of two parts: a classification loss and an adversarial loss.
[0150] Let D be the domain discriminator, used to distinguish instances from the source and target domains; G be the feature extractor, used to extract domain-invariant features; and f be an additionally trained domain classifier, used to distinguish whether the training data comes from the source or target domain. The loss function (or optimization objective) of the adversarial trainer can be expressed as:
[0151] Among them, L task It is a task-related loss function, which can be simply referred to as task loss. It is the adversarial loss function, also known simply as adversarial loss, where, This represents the probability that the domain discriminator classifies real data as real data. This represents the probability that the domain discriminator will classify generated fake data as the opposite of real data, i.e., the probability that fake data will still be classified as fake data. λ is the weighting coefficient that balances task loss and adversarial loss.
[0152] S406 and Artificial Intelligence Center 103 perform feature selection and mapping on the features extracted from the training data by the pre-trained model.
[0153] Model training can be performed online or offline. In some possible implementations, data center 105 can present sample data to the user, which may include corpora obtained from open-source repositories, receive domain labels annotated by the user on the corpora, and obtain training data. Furthermore, data center 105 can also perform augmentation processing on the labeled training data. For example, data center 105 can enhance the quality of the training data through data cleaning. In other possible implementations, AI center 103 can also obtain pre-labeled training data from data center 105. AI center 103 inputs the aforementioned training data into a pre-trained model, which can extract features from the input training data.
[0154] Artificial Intelligence Center 103 can perform feature selection and mapping on features extracted from training data using a feature selector and mapper. Specifically, Artificial Intelligence Center 103 can extract features from training data in the source and target domains using a pre-trained model, selecting features important for the domain recognition task (domain classification task). Furthermore, if the feature spaces of the source and target domains are inconsistent—for example, if the source language has four encoding rules and the target language has six—it indicates that the feature spaces of the source and target languages are inconsistent. In this case, Artificial Intelligence Center 103 can map the features of the source domain to the target feature space using a mapping algorithm (e.g., a feature mapping matrix).
[0155] S408 and Artificial Intelligence Center 103 assign weights to the training data.
[0156] For training data in the source and target domains, the AI center 103 can determine the sample importance of the training data and its domain similarity to other training data. Based on sample importance and domain similarity, the AI center 103 can assign weights to the training data in the source and target domains.
[0157] S410 and Artificial Intelligence Center 103 input the features extracted from the training data by the pre-trained model into the adversarial trainer.
[0158] The adversarial trainer trains an additional domain classifier whose goal is to distinguish whether the training data comes from the source domain or the target domain.
[0159] S412 and Artificial Intelligence Center 103 update the parameters of the pre-trained model based on the loss functions of the feature selection and mapper, instance weighter, and adversarial trainer.
[0160] Artificial Intelligence Center 103 can combine feature selection with the loss functions (or objective functions) of the mapper, instance weighter, and adversarial trainer to achieve joint optimization. The joint loss function used for joint optimization is shown below: Min S,M,G,f Max D (L weighted (S,M)+γAdvLoss(D,G,f)) (4)
[0161] Where γ is the weight coefficient of the balanced weighted loss function and the loss function of the adversarial trainer; AdvLoss(D,G,f) is the loss function of the adversarial trainer.
[0162] In practical applications, the joint optimization algorithm iteratively updates the parameters of the feature selection matrix S, feature mapping matrix M, feature extractor G, domain classifier f, and domain discriminator D to progressively optimize the pre-trained model, enabling it to achieve good performance in the target domain. Specifically, the AI Center 103 can update the parameters of the pre-trained model, feature selection matrix, feature mapping matrix, feature extractor, domain classifier, and domain discriminator based on the joint loss function. In other words, the parameters of the feature selection matrix S, feature mapping matrix M, feature extractor G, domain classifier f, and domain discriminator D can be iteratively updated together with the parameters of the pre-trained model.
[0163] S414 and Artificial Intelligence Center 103 evaluate and provide feedback on the updated pre-trained model.
[0164] Specifically, when the pre-trained model meets the training stopping condition, the AI center 103 can evaluate the updated pre-trained model. The training stopping condition may include, but is not limited to, reaching a set number of iterations or the loss function converging. The AI center 103 can evaluate the updated pre-trained model using sample data from the validation set. Based on the evaluation results, the AI center 103 can determine and adjust the hyperparameters, which may be fed back by the feedback component in the test agent 101. The AI center 102 can then continue training based on the adjusted hyperparameters.
[0165] Based on the aforementioned test code generation method, this application also provides a code development platform 10. The structure of the code development platform 10 will be described below with reference to Figure 1.
[0166] Referring to Figure 1, which shows a schematic diagram of a code development platform 10, the code development platform 10 includes:
[0167] Test agent 101 is used to receive a test code generation request, which is used to generate test code for a test object; and to determine the domain label of the source domain and the domain mapping relationship according to the test code generation request. The domain label of the source domain is used to indicate the domain to which the source code of the test object belongs, and the domain mapping relationship includes the mapping relationship between the source domain and the target domain, wherein the target domain is the domain to which the test code belongs.
[0168] The test agent 101 is further configured to assemble a code generation prompt based on the domain label of the source domain and the test code generation request. The code generation prompt is used to guide the code generation model to generate test code for the test object in the source domain. The code generation model is generated by training a language model. The code generation prompt is input into the code generation model to obtain the test code for the test object in the source domain. Based on the domain mapping relationship, the test code for the test object in the source domain is mapped to the feature space of the target domain to obtain the test code for the test object in the target domain.
[0169] The aforementioned test agent 101 can be implemented through software. Specifically, the test agent 101 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service. Virtualization services can include virtual machine (VM) services, bare metal server (BMS) services, or container services. VM services can be services that use virtualization technology to create virtual machine (VM) resource pools on multiple physical hosts to provide VMs for users to use on demand. BMS services are services that use virtualization technology to create BMS resource pools on multiple physical hosts to provide BMS for users to use on demand. Container services are services that use virtualization technology to create container resource pools on multiple physical hosts to provide containers for users to use on demand. A VM is a simulated virtual computer, that is, a logical computer. A BMS is a scalable, high-performance computing service with computing performance indistinguishable from traditional physical machines and features secure physical isolation. A container is a kernel virtualization technology that can provide lightweight virtualization to isolate user space, processes, and resources. It should be understood that the VM service, BMS service, and container service mentioned above are merely specific examples. In practical applications, virtualization services can also include other lightweight or heavyweight virtualization services, which are not specifically limited here.
[0170] Furthermore, the test agent 101 may include multiple modules or components. As shown in Figure 1, the test agent 101 may include a domain adaptive recognition component, a model inference component, and a cross-domain feature mapping component. Further, the test agent 101 may also include a preprocessing component, a retrieval reordering component, a prompting and concatenation component, a verification and evaluation component, and a feedback component. These components may be applications running on computing devices, which may be provided to users as virtualization services such as VM services, BMS services, or container services.
[0171] In some possible implementations, the code development platform 10 further includes a knowledge repository 106, which includes a code generation database;
[0172] The test agent 101 is specifically used for:
[0173] Based on the domain tags of the source domain and the test code generation request, the code generation database in the knowledge repository 106 is retrieved to obtain the retrieval results;
[0174] Based on the domain tags of the source domain, the test code generation request, and the search results, code generation suggestions are assembled.
[0175] Similar to the test agent 101, the knowledge repository 106 can be implemented through software, which can also be virtualized and provided to users in the form of virtualized services such as VM services, BMS services, and container services.
[0176] In some possible implementations, the test agent 101 is specifically used for:
[0177] Based on the domain tags of the source domain, the test code generation request, and the search results, obtain the code generation prompt template;
[0178] Based on the test code generation request and the search results, code generation prompts are assembled according to the code generation prompt template to obtain code generation prompts.
[0179] In some possible implementations, the test agent 101 is specifically used for:
[0180] The test code of the test object in the target domain is evaluated to obtain the evaluation result;
[0181] Update the domain identification optimization strategy, the parameters of the code generation model, the mapping parameters, the domain identification parameters, the model training corpus, or the code generation prompt template based on the evaluation results.
[0182] In some possible implementations, the test agent 101 is specifically used for:
[0183] Based on the test code generation request, a domain identification prompt is assembled;
[0184] The domain identification prompts are input into the domain identification model to obtain the domain labels of the source domain and the target domain. The domain identification model is generated by training a pre-trained model.
[0185] In some possible implementations, the code development platform 10 also includes:
[0186] Artificial Intelligence Center 103 is used to initialize a feature selector and mapper, an instance weighter, and an adversarial trainer. The feature selector and mapper includes a feature selection matrix and a feature mapping matrix. The adversarial trainer includes a feature extractor, a domain classifier, and a domain discriminator. Based on the joint loss function, the parameters of the pre-trained model, the feature selection matrix, the feature mapping matrix, the feature extractor, the domain classifier, and the domain discriminator are updated.
[0187] Similar to the test agent 101 and the knowledge repository 106, the artificial intelligence center 103 can be implemented through software. This software can be an application running on a computing device. Furthermore, the application can be virtualized, thus providing it to users in the form of VM services, BMS services, or container services.
[0188] In some possible implementations, the domain label includes at least one of a business domain label or a technology domain label.
[0189] This application also provides a computing device 500. As shown in FIG5, the computing device 500 includes: a bus 502, a processor 504, a memory 506, and a communication interface 508. The processor 504, the memory 506, and the communication interface 508 communicate with each other via the bus 502. The computing device 500 may be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 500.
[0190] Bus 502 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one line is used in Figure 5, but this does not imply that there is only one bus or one type of bus. Bus 502 can include pathways for transmitting information between various components of computing device 500 (e.g., memory 506, processor 504, communication interface 508).
[0191] Processor 504 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0192] Memory 506 may include volatile memory, such as random access memory (RAM). Memory 506 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD). Memory 506 stores executable program code, which processor 504 executes to implement the aforementioned test code generation method. Specifically, memory 506 stores instructions for the code development platform 10 to execute the test code generation method. Memory 506 may store instructions for the test agent 101 to execute the test code generation method. Furthermore, memory 506 may also store instructions for the artificial intelligence center 103, data center 105, knowledge repository 106, prompting center 107, engine 108, and inference center 109 to execute the test code generation method. It should be noted that the instructions of the various components of the code development platform 10 can also be distributed and stored in the memory 506 of multiple computing devices 500.
[0193] The communication interface 508 uses transceiver modules, such as, but not limited to, network interface cards and transceivers, to enable communication between the computing device 500 and other devices or communication networks.
[0194] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0195] As shown in Figure 6, the computing device cluster includes at least one computing device 500. The memory 506 of one or more computing devices 500 in the computing device cluster may store the same code development platform 10 for executing instructions of the test code generation method.
[0196] In some possible implementations, one or more computing devices 500 in the computing device cluster can also be used to execute some of the instructions used by the code development platform 10 to execute the test code generation method. In other words, a combination of one or more computing devices 500 can jointly execute the instructions used by the code development platform 10 to execute the test code generation method.
[0197] It should be noted that the memory 506 in different computing devices 500 in the computing device cluster can store different instructions for executing some functions of the code development platform 10.
[0198] Figure 7 illustrates one possible implementation. As shown in Figure 7, two computing devices 500A and 500B are connected via a communication interface 508. The memory in computing device 500A stores instructions for executing the functions of the test agent 101. These instructions may include instructions for implementing the functions of the domain adaptive recognition component, the model inference component, and the cross-domain feature mapping component. Furthermore, the instructions for executing the functions of the test agent 101 may also include a preprocessing component, a retrieval reordering component, a verification and evaluation component, and a feedback component.
[0199] The memory in computing device 500B stores instructions for executing the functions of the artificial intelligence center 103, data center 105, knowledge repository 106, prompting center 107, engine 108, and reasoning center 109. In other words, the memory 506 of computing devices 500A and 500B jointly stores the instructions used by the code development platform 10 to execute the test code generation method.
[0200] The connection method between the computing device clusters shown in Figure 7 can be considered because the test code generation method provided in this application requires a lot of resources for domain adaptive recognition and cross-domain feature mapping. Therefore, it is considered that the functions implemented by the test agent 101 are executed by independent computing devices, such as computing device 500A, while the functions implemented by the remaining parts, such as the artificial intelligence center 103, data center 105, knowledge warehouse 106, prompting center 107, engine 108, and inference center 109, are executed by computing device 500B.
[0201] It should be understood that the functions of computing device 500A shown in Figure 7 can also be performed by multiple computing devices 500. For example, the functions of the adaptive recognition component, model inference component, cross-domain feature mapping component, preprocessing component, retrieval re-ranking component, verification and evaluation component, and feedback component can be performed by multiple computing devices 500. Similarly, the functions of computing device 500B can also be performed by multiple computing devices 500.
[0202] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 8 illustrates one possible implementation. As shown in Figure 8, two computing devices 500C and 500D are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this type of possible implementation, the memory 506 in computing device 500C stores instructions for executing the functions of the test agent 101. Simultaneously, the memory 506 in computing device 500D stores instructions for executing the functions of the artificial intelligence center 103, data center 105, knowledge repository 106, prompting center 107, engine 108, and inference center 109.
[0203] The connection method between the computing device clusters shown in Figure 8 can be considered as follows: taking into account that the test code generation method provided in this application requires a lot of resources for domain identification and mapping the test code of the source domain to the feature space of the target domain, the function implemented by the test agent 101 is considered to be executed by an independent computing device, such as computing device 500C, and the functions implemented by the remaining parts, such as the artificial intelligence center 103, data center 105, knowledge warehouse 106, prompting center 107, engine 108, and inference center 109, are executed by computing device 500D.
[0204] It should be understood that the functions of computing device 500C shown in Figure 8 can also be performed by multiple computing devices 500. Similarly, the functions of computing device 500D can also be performed by multiple computing devices 500.
[0205] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the above-described method for generating test code applied to the code development platform 10.
[0206] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to execute the above-described test code generation method.
[0207] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.
Claims
1. A test code generation method, characterized in that, The method includes: Receive a test code generation request, which is used to generate test code for the test object; The source domain's domain label and domain mapping relationship are determined based on the test code generation request. The source domain's domain label is used to indicate the domain to which the source code of the test object belongs. The domain mapping relationship includes the mapping relationship between the source domain and the target domain, where the target domain is the domain to which the test code belongs. Based on the domain labels of the source domain and the test code generation request, a code generation prompt is assembled. The code generation prompt is used to guide the code generation model to generate test code for the test object in the source domain. The code generation model is generated by training a language model. Input the code generation prompt into the code generation model to obtain the test code for the test object in the source domain; Based on the domain mapping relationship, the test code of the test object in the source domain is mapped to the feature space of the target domain to obtain the test code of the test object in the target domain.
2. The method according to claim 1, characterized in that, The step of assembling code generation suggestions based on the domain tags of the source domain and the test code generation request includes: Based on the domain tags of the source domain and the test code generation request, the code generation database is retrieved to obtain the retrieval results; Based on the domain tags of the source domain, the test code generation request, and the search results, code generation suggestions are assembled.
3. The method according to claim 2, characterized in that, The step of assembling code generation suggestions based on the domain tags of the source domain, the test code generation request, and the search results includes: Based on the domain tags of the source domain, the test code generation request, and the search results, obtain the code generation prompt template; Based on the test code generation request and the search results, code generation prompts are assembled according to the code generation prompt template to obtain code generation prompts.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: The test code of the test object in the target domain is evaluated to obtain the evaluation result; Update the domain identification optimization strategy, the parameters of the code generation model, the mapping parameters, the domain identification parameters, the model training corpus, or the code generation prompt template based on the evaluation results.
5. The method according to any one of claims 1 to 4, characterized in that, The step of determining the domain label of the source domain based on the test code generation request includes: Based on the test code generation request, a domain identification prompt is assembled; The domain identification prompts are input into the domain identification model to obtain the domain labels of the source domain and the target domain. The domain identification model is generated by training a pre-trained model.
6. The method according to claim 5, characterized in that, The domain recognition model is trained in the following manner: Initialize a feature selector and mapper, an instance weighter, and an adversarial trainer. The feature selector and mapper includes a feature selection matrix and a feature mapping matrix. The adversarial trainer includes a feature extractor, a domain classifier, and a domain discriminator. The parameters of the pre-trained model, the feature selection matrix, the feature mapping matrix, the feature extractor, the domain classifier, and the domain discriminator are updated based on the joint loss function.
7. The method according to any one of claims 1 to 6, characterized in that, The domain label includes at least one of the business domain label or the technology domain label.
8. A code development platform, characterized in that, The code development platform includes: A test agent is used to receive a test code generation request, which is used to generate test code for a test object; and to determine the domain label of the source domain and the domain mapping relationship based on the test code generation request. The domain label of the source domain is used to indicate the domain to which the source code of the test object belongs, and the domain mapping relationship includes the mapping relationship between the source domain and the target domain, wherein the target domain is the domain to which the test code belongs. The testing agent is further configured to assemble a code generation prompt based on the domain label of the source domain and the test code generation request. The code generation prompt is used to guide the code generation model to generate test code for the test object in the source domain. The code generation model is generated by training a language model. The code generation prompt is input into the code generation model to obtain the test code for the test object in the source domain. Based on the domain mapping relationship, the test code for the test object in the source domain is mapped to the feature space of the target domain to obtain the test code for the test object in the target domain.
9. The code development platform according to claim 8, characterized in that, The code development platform also includes a knowledge repository, which includes a code generation database; The test agent is specifically used for: Based on the domain tags of the source domain and the test code generation request, the code generation database is retrieved to obtain the retrieval results; Based on the domain tags of the source domain, the test code generation request, and the search results, code generation suggestions are assembled.
10. The code development platform according to claim 9, characterized in that, The test agent is specifically used for: Based on the domain tags of the source domain, the test code generation request, and the search results, obtain the code generation prompt template; Based on the test code generation request and the search results, code generation prompts are assembled according to the code generation prompt template to obtain code generation prompts.
11. The code development platform according to any one of claims 8 to 10, characterized in that, The test agent is specifically used for: The test code of the test object in the target domain is evaluated to obtain the evaluation result; Update the domain identification optimization strategy, the parameters of the code generation model, the mapping parameters, the domain identification parameters, the model training corpus, or the code generation prompt template based on the evaluation results.
12. The code development platform according to any one of claims 8 to 11, characterized in that, The test agent is specifically used for: Based on the test code generation request, a domain identification prompt is assembled; The domain identification prompts are input into the domain identification model to obtain the domain labels of the source domain and the target domain. The domain identification model is generated by training a pre-trained model.
13. The code development platform according to claim 12, characterized in that, The code development platform also includes: The artificial intelligence center is used to initialize a feature selector and mapper, an instance weighter, and an adversarial trainer. The feature selector and mapper includes a feature selection matrix and a feature mapping matrix. The adversarial trainer includes a feature extractor, a domain classifier, and a domain discriminator. Based on the joint loss function, the parameters of the pre-trained model, the feature selection matrix, the feature mapping matrix, the feature extractor, the domain classifier, and the domain discriminator are updated.
14. The code development platform according to any one of claims 8 to 13, characterized in that, The domain label includes at least one of the business domain label or the technology domain label.
15. A computing device cluster, characterized in that, The computing device cluster includes at least one computing device, the at least one computing device including at least one processor and at least one memory, the at least one memory storing computer-readable instructions; the at least one processor executes the computer-readable instructions to cause the computing device cluster to perform the test code generation method as described in any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, Includes computer-readable instructions; the computer-readable instructions are used to implement the test code generation method according to any one of claims 1 to 7.
17. A computer program product, characterized in that, Includes computer-readable instructions; the computer-readable instructions are used to implement the test code generation method according to any one of claims 1 to 7.