Code testing method, computing device, storage medium and program product
By integrating test plugins and intelligent generation models into code development tools, test code is automatically generated and executed, solving the problems of low efficiency and poor accuracy of manually writing test code, and achieving efficient and accurate code testing.
Patent Information
- Application Number
- CN202511536511.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2026-02-06
AI Technical Summary
Manually writing test code results in low testing efficiency and poor accuracy.
By integrating test plugins into code development tools, test code can be generated using intelligent generation models, and test operations can be executed automatically, including test environment detection and updates for the target code, thus achieving a fully automated testing process.
It improves the automation, efficiency, and accuracy of code testing, lowers the barrier to entry for writing test code, and achieves a fully automated testing process.
Smart Images

Figure CN121478643A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of computer technology, and particularly relate to a code testing method, a computing device, a storage medium and a program product. BACKGROUND
[0002] Code testing refers to a process of verifying the correctness of code, verifying whether the code runs as expected by writing special test code, so as to find errors and correct them to ensure code quality.
[0003] At present, a tester usually formulates a test task in combination with target code to be tested, manually writes corresponding test code, and automatically executes the target code by running the test code to implement testing of the target code. However, manual writing of test code has problems of low testing efficiency and poor accuracy. SUMMARY
[0004] Embodiments of the present application provide a code testing method, a computing device, a storage medium and a program product to solve the problem of low testing efficiency and poor accuracy of manual writing of test code in the prior art.
[0005] In a first aspect, a code testing method is provided in embodiments of the present application, applied to a test plug-in integrated in a code development tool, and the method comprises: obtaining target code selected in a code editing interface; providing test prompt information; generating a test instruction in response to a triggering operation on the test prompt information; detecting a test environment of the target code and updating the test environment according to an environment detection result in response to the test instruction; generating test code corresponding to the target code by using at least one intelligent generation model; executing the test code to test the target code in the updated test environment and outputting a test result.
[0006] In a second aspect, a code testing method is provided in embodiments of the present application, applied to a code development tool integrated with a test plug-in, and the method comprises: determining target code in response to a code selection operation in a code editing interface; The test plug-in is called to detect a test environment of the target code in a case where a test instruction is detected, and the test environment is updated according to an environment detection result; at least one intelligent generation model is used to generate test code corresponding to the target code; the test code is executed in the updated test environment to test the target code, and a test result is output; and the test instruction is generated in response to a trigger operation on test prompt information.
[0007] In a third aspect, an embodiment of the present application provides a code testing apparatus configured in a test plug-in, the test plug-in being integrated in a code development tool, and the apparatus comprising: a target code acquisition module configured to acquire target code selected in a code editing interface; a prompt information providing module configured to provide test prompt information; a test instruction generating module configured to generate a test instruction in response to a trigger operation on the test prompt information; a test environment detecting module configured to detect a test environment of the target code in response to the test instruction, and update the test environment according to an environment detection result; a test code generating module configured to use at least one intelligent generation model to generate test code corresponding to the target code; a first code testing module configured to execute the test code in the updated test environment to test the target code, and output a test result.
[0008] In a fourth aspect, an embodiment of the present application provides a code testing apparatus configured in a code development tool, the code development tool integrating a test plug-in, and the apparatus comprising: a target code determining module configured to determine target code in response to a code selection operation in a code editing interface; a second code testing module configured to call the test plug-in to detect a test environment of the target code in a case where a test instruction is detected, and update the test environment according to an environment detection result; use at least one intelligent generation model to generate test code corresponding to the target code; execute the test code in the updated test environment to test the target code, and output a test result; and the test instruction is generated in response to a trigger operation on test prompt information.
[0009] In a fifth aspect, an embodiment of the present application provides a computing device, comprising a processing component, a storage component; the storage component stores a computer program and a code development tool integrated with a test plug-in; the computer program is used to be invoked by the processing component, and run the code development tool integrated with the test plug-in; the test plug-in is used to implement the code testing method in the first aspect above; and the code development tool is used to implement the code testing method in the second aspect above.
[0010] In a sixth aspect, an embodiment of the present application provides a computer storage medium, storing a computer program and a code development tool integrated with a test plug-in; the computer program is invoked by a processing component, and runs the code development tool integrated with the test plug-in; the test plug-in is used to implement the code testing method in the first aspect above; and the code development tool is used to implement the code testing method in the second aspect above.
[0011] In a seventh aspect, an embodiment of the present application provides a computer program product, comprising computer programs / instructions; the computer programs / instructions are invoked by a processing component, and run a code development tool integrated with a test plug-in; the test plug-in is used to implement the code testing method in the first aspect above; and the code development tool is used to implement the code testing method in the second aspect above.
[0012] The embodiments of the present application obtain the target code selected in the code editing interface through the test plug-in integrated in the code development tool, and provide test prompt information; in response to a trigger operation for the test prompt information, a test instruction is generated; in response to the test instruction, the test environment of the target code is detected, and the test environment is updated according to the environment detection result; at least one intelligent generation model is used to generate test code corresponding to the target code, and the test code is executed in the updated test environment to test the target code, and a test result is output. The present application automatically generates test code for the target code through the intelligent generation model, and automatically executes the test operation of the target code, which solves the pain points of low efficiency and poor accuracy of manually writing test code, and effectively reduces the threshold of writing test code. In addition, the test plug-in is integrated in the code development tool, and the automatic test process from test environment detection to test code generation and target code testing is realized through the test plug-in. The entire test process is triggered and executed by one key after the target code is selected. The present application realizes a fully automatic test process, greatly improves the automation degree, efficiency and accuracy of code testing.
[0013] These and other aspects of the present application will become more apparent in the following description of embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0014] The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the application. In the drawings: Figure 1 A flow chart of an embodiment of a code testing method provided by the present application is shown; Figure 2 A schematic diagram of a code editing interface provided by the present application is shown; Figure 3 A schematic diagram of a test environment updating process provided by the present application is shown; Figure 4 A flow chart of an embodiment of another code testing method provided by the present application is shown; Figure 5 A schematic diagram of a technical architecture in an actual application scenario provided by the present application is shown; Figure 6 A structural schematic diagram of an embodiment of a code testing device provided by the present application is shown; Figure 7 A structural schematic diagram of an embodiment of another code testing device provided by the present application is shown; Figure 8 A structural schematic diagram of an embodiment of a computing device provided by the present application is shown. DETAILED DESCRIPTION
[0015] To make the objectives, technical solutions, and advantages of the present application clearer, the technical solutions of the present application will be described below in conjunction with specific embodiments of the present application and corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0016] It should be noted that in the case where the embodiments of the present application involve user information (including but not limited to user device information, user personal information, etc.), the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the embodiments of the present application are all information and data authorized by the user or authorized by all parties, and the collection, use, and processing of related data need to comply with relevant laws, regulations, and standards of relevant countries and regions, and provide corresponding operation portals for users to choose authorization or refusal. In addition, the various models (including but not limited to language models or large models) involved in the present application are in compliance with relevant legal and standard regulations.
[0017] In addition, it should be noted that, in the case that the embodiments of the present application involve user interaction operations or triggering operations, the user interaction operations or triggering operations involved in the embodiments of the present application include but are not limited to various modes of interaction operations such as touch operations, gesture operations, voice operations, head movement operations, eye movement operations, etc.; wherein the touch operation includes but is not limited to click operation, double-click operation, long-press operation, sliding operation, pinch operation or mouse hovering operation, etc. The sliding operation includes but is not limited to straight-line sliding, curve sliding, etc.
[0018] It should be noted that the technical solutions of the embodiments of the present application are applicable to a network virtual environment, and the user described is generally referred to as a "virtual user". A real user can register a user account in a server through a registration method to obtain a user identity in a network environment. A same user account can be logged into the server through different types of user terminals, so that the server can identify the same user. The interaction operation between the server and the user can be implemented based on the user account, and the corresponding data received or sent by the server to the user is also implemented based on the user account, which is actually received or sent by the user terminal corresponding to the user account to the server. In addition, communication between users through user accounts can also be implemented. Wherein, the user can refer to an individual, or an institution such as an enterprise, etc., and the present application does not make specific limitations thereto.
[0019] As can be known from the background art, at present, the code testing process is usually performed by manually writing corresponding test code based on target code to be tested for testing the target code. However, the manual writing of test code has the pain points of low writing efficiency and poor accuracy. To solve the technical problem, the inventors think that an artificial intelligence model can be used to replace manual writing of test code. On this basis, in order to further improve the automation degree of code testing, the inventors have carried out a series of researches and proposed the solution of the embodiments of the present application. The basic idea is as follows: a test plug-in integrated in a code development tool is used to obtain target code selected in a code editing interface and provide test prompt information. In response to a trigger operation for the test prompt information, a test instruction is generated. In response to the test instruction, a test environment of the target code is detected, and the test environment is updated according to the environment detection result. At least one intelligent generation model is used to generate test code corresponding to the target code, and the test code is executed in the updated test environment to test the target code, and a test result is output. The present solution automatically generates test code for the target code by using an intelligent generation model, and automatically executes the test operation of the target code, thereby solving the pain points of low efficiency and poor accuracy of manual writing of test code, and effectively reducing the threshold of writing test code. In addition, the test plug-in is integrated in the code development tool, and the automatic test process from test environment detection to test code generation and target code testing is realized by the test plug-in. The entire test process is triggered and executed by one key after the target code is selected. The fully automatic test process greatly improves the automation degree, efficiency and accuracy of code testing.
[0020] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0021] Figure 1A flowchart of an embodiment of a code testing method provided by the present application can be executed by a test plug-in integrated in a code development tool. The code development tool can be an application for providing a program development environment, such as an integrated development environment (IDE) tool. The code development tool of the present embodiment can integrate a code editor, a compiler, a debugger, a graphical user interface, etc. The code editor can be, for example, Visual Studio Code (VSCode), which supports multiple programming languages and frameworks, has a rich plug-in ecosystem, intelligent code completion, debugging functions, and version control integration. The code development tool can also provide an extension interface for users to develop custom extension plug-ins. The test plug-in integrated in the code development tool of the present embodiment can be a plug-in with code testing functions developed based on the extension interface and distributed and installed in the code development tool through an application store. In the present embodiment, the code edited by the code development tool can be tested through the test plug-in.
[0022] In practical applications, the code development tool can be implemented as a standalone client that can perform code editing and other operations without connecting to an external network. Of course, it can also be implemented as a network client, such as a web application. The present application does not limit this. The code development tool is deployed in an electronic device, which can have a display screen and support information browsing, such as a personal mobile terminal, such as a mobile phone, a tablet computer, a personal computer, a desktop computer, a smart speaker, a smart watch, etc.
[0023] Similarly, some operations performed by the test plug-in can also be executed locally without connecting to an external network. Of course, it can also request a test server connected to the test plug-in through a network to execute, etc. The present application does not limit this. The test server can include servers providing various services. It should be noted that the test server can be implemented as a distributed server cluster composed of multiple servers or as a single server. The server can also be a server of a distributed system or a server combined with a blockchain. The server can also be a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, etc. Basic cloud computing services, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
[0024] Figure 1 The code testing method can include the following steps: S101, acquire target code selected in a code editing interface.
[0025] The code editing interface can be an interface provided by a code development tool to perform code editing operations. A user can perform code editing operations in the code editing interface and store the edited code in the form of a file in a code repository of the code development tool, or open any code file stored in the code repository in the code editing interface. The code repository can be a systematic storage space provided by an integrated development environment to store, manage and track code. The target code is the code to be tested in this embodiment, i.e., the code under test. The target code can be selected by the user in the code editing interface according to actual testing requirements. In one practical application, the technical solution of the embodiment of the present application can be applied to unit testing, and the target code can be a testable unit in a code file, which can be the code file itself or a minimum testable unit such as a function, method or component in the code file.
[0026] One application scenario of this embodiment can be to test the currently edited code after completing the code editing operation in the code editing interface. At this time, the user can directly perform selection operations on the currently edited code in the code editing interface according to actual testing requirements, and the test plug-in can acquire the code selected by the user as the target code. For example, in this scenario, the user can perform a full selection operation on the currently edited code, and the test plug-in can acquire all the code displayed in the code editing interface as the target code. Of course, the user can also perform a partial code selection operation on the currently edited code, and the test plug-in can acquire the selected partial code in the code editing interface as the target code.
[0027] Another application scenario can be to test a project code file stored in the code repository. At this time, the user can enter the code repository from the code editing interface according to actual testing requirements, and perform selection operations on the project code file stored in the code repository, and the test plug-in can acquire all or part of the code in the project code file selected by the user as the target code. For example, in this scenario, the code repository can be entered from the code editing interface, and the code file to be tested can be opened in the code repository, and the code editing interface will display the project code in the project code file at this time. The user can perform a full selection operation on the project code in the project code file, and the test plug-in can acquire all the selected project code as the target code. The user can also perform a selection operation on part of the code in the project code file, and the test plug-in can acquire the selected code as the target code.
[0028] Optionally, one implementation of this step could be: detecting code selection operations in the code editing interface and obtaining the selected target code. Specifically, in this embodiment, when a user has code testing needs, they can perform a selection operation on the target code to be tested in the code editing interface. The testing plugin will actively detect in real time whether a code selection operation exists in the code editing interface. If it does, the code selected by the selection operation will be obtained as the target code. For example, such as... Figure 2 As shown, the testing plugin can detect in real time whether there is a code selection operation in the area where the code editing panel 201 is located. If there is, the code in the gray background area selected by the selection operation is taken as the target code.
[0029] Another implementation could be to provide code retrieval hints and, in response to the triggering action of these hints, read the target code selected in the code editing interface. The code retrieval hints would then prompt the user to select the target code to be tested. For example, it could be... Figure 2 The plugin panel area 202 in the code editing interface displays either a "Select Code for Testing" component or an "Add Code" component. In this embodiment, the testing plugin provides code retrieval prompts to the user through the code editing interface. If the user has testing needs, they will select the target code to be tested in the code editing interface and trigger the code retrieval prompt. After detecting the user's trigger operation on the code retrieval prompt, the testing plugin reads the selected code as the target code in the code editing interface. It should be noted that the user can select the target code to be tested first and then trigger the code retrieval prompt, or they can trigger the code retrieval prompt first and then select the target code to be tested. For example, as shown... Figure 2 As shown, the test interpolation responds to the triggering operation of code acquisition prompt information (such as the "Select code for testing" component), and reads the code selected by the user in the gray background area from the code editing panel as the target code.
[0030] Of course, the testing plugin can also support both of the above implementation methods at the same time, namely, actively detecting and obtaining target code, and passively reading target code in response to user triggers, so as to improve the flexibility and diversity of target code acquisition.
[0031] S102 provides test prompt information.
[0032] The test prompt message is used to prompt the execution of code test operations. Triggering the test prompt message will trigger the relevant operations for code testing (i.e., the subsequent operations S103-S106).
[0033] The test plug-in in the embodiment provides the test prompt information in the code editing interface. Optionally, a plug-in panel can be displayed in the code editing interface, and the test prompt information is displayed in the plug-in panel. The plug-in panel can be an operation panel set for all plug-ins or test plug-ins integrated in the code development tool. As shown in FIG. 10, the code editing interface includes a plug-in panel area 202, and the test prompt information, i.e., a "select code for testing" component, is displayed in the area. The code editing interface is functionally divided in the embodiment, such as being divided into a code editing panel, a plug-in panel, and a test result display panel, to further improve the standardization and rationality of the display area layout of the code editing interface. Figure 2
[0034] In S103, a test instruction is generated in response to a triggering operation on the test prompt information.
[0035] The test instruction is used to instruct to perform a test operation on the selected target code. After the test plug-in detects the test operation triggered on the test prompt information, the test instruction is automatically generated.
[0036] In some embodiments, if the test prompt information is the same as the code acquisition prompt information introduced in S101, the triggering operation on the code acquisition prompt information is detected by default after the target code selected in the code editing interface is read, and the test instruction for the target code is automatically triggered after the target code is acquired.
[0037] In S104, a test environment of the target code is detected in response to the test instruction, and the test environment is updated according to the environment detection result.
[0038] The test environment can be an environment resource required for performing a test operation on the target code. In order to avoid interruption of the test process due to problems in the test environment during code testing, the test environment is detected before code testing in the embodiment, such as detecting the integrity (such as whether there is a lack of software and hardware resources, version mismatch, lack of configuration data, and other abnormalities), consistency, stability, and security of the test environment. If problems are detected in the test environment, the test environment is repaired based on the problems, for example, if there is an integrity problem, the missing resources can be installed, the version mismatched resources can be changed, and the configuration data can be set, so as to update the test environment and ensure that the test plug-in can correctly run the test code of the target code and obtain the test result in the future. Optionally, the test environment can be detected by a preset detection rule.
[0039] In some embodiments, to further ensure the integrity and consistency of the test environment, this embodiment may use dependency analysis to intelligently detect the test environment of the target code. Specifically, in response to test instructions, it may detect whether there are missing environment dependencies and / or version conflicts in the test environment of the target code; if so, it may install the missing environment dependencies in the test environment and / or correct the version conflict environment dependencies, and generate test environment configuration data; if not, it may generate test environment configuration data.
[0040] Environment dependencies can be external resources that the test code depends on, such as tool libraries, third-party libraries, frameworks, and components. If these dependencies are not installed or are not configured correctly, it may lead to inaccurate test results or test failures. Furthermore, since multiple versions of environment dependencies may exist, test environment checks can perform not only missing dependency detection but also version conflict detection.
[0041] The configuration data can be environment dependency configuration data, which is used to indicate how to use dependencies, etc. The test environment can be generated based on the environment dependencies and configuration data.
[0042] Specifically, such as Figure 3 As shown, the test plugin can respond to test instructions by determining the environment dependencies and versions required to execute the current code test (S301). Then, according to preset detection rules (such as regular expressions), it checks whether the current test environment is missing the required environment dependencies, or whether the versions of the installed environment dependencies conflict with the required versions (S302).
[0043] If the required environment dependency is missing, install the missing required version of the environment dependency in the current test environment. If the environment dependency has already been installed, but the version of the environment dependency in the test environment is inconsistent with the required version, that is, there is a version conflict, the environment dependency of the required version (i.e., the version parsed by S301) can be reinstalled in the current test environment to replace the original version of the environment dependency in the test environment, thereby correcting the version conflict of the dependent environment. The version conflict of the dependent environment can also be corrected by confirming the actual required version through manual interaction. For example, version selection prompt information can be generated based on the multiple version information of the existing version conflict, wherein the multiple version information of the existing version conflict can include the version number of the environment dependency already installed in the test environment and the version number required by the environment dependency parsed by S301. In response to a version selection operation triggered in response to the version selection prompt information, a selected version is determined, and based on the selected version, the environment dependency with a version conflict is corrected in a similar manner as described above (S303). If the dependent environment does not have the case of missing environment dependency and version conflict, the test environment configuration data can be generated directly at this time. If at least one of the cases of missing environment dependency and version conflict exists, the corresponding installation of the missing environment dependency and / or the correction of the environment dependency with a version conflict is performed, and then the operation of generating the configuration data of the test environment is performed. Specifically, when generating the configuration information of the test environment, the addition or modification of the configuration data can be configured from the dimensions of writing rules configuration, test environment configuration, test step configuration, and definition of project infrastructure and dependency configuration (S304).
[0044] The embodiment develops a test environment intelligent detection algorithm based on dependency tree analysis, which can identify version conflicts and missing environment dependencies of various test frameworks, automatically generate configuration files and execute installation instructions for missing environment dependencies, ensure the integrity and consistency of the test environment, and avoid the problem of environment configuration interrupting the test workflow.
[0045] Optionally, when generating the configuration data of the test environment, the required multi-dimensional configuration data can be written into the configuration file in advance based on the versions of the code development framework and the test framework of the code development tool. At this time, the test plug-in can call the data writing interface of the code development tool to write the configuration data recorded in the configuration file into the configuration data of the test environment.
[0046] S105, using at least one intelligent generation model, generates test code corresponding to the target code.
[0047] The test code is code for performing a test operation on the target code, that is, running the test code can control the target code to simulate the actual running process. For example, if the target code is the code corresponding to the login component of an application. At this time, the test code can be code for simulating a user inputting an account and password in the login component and clicking a login button to trigger the login component to perform a login operation. The at least one intelligent generation model of the embodiment can be a model for generating test code for the target code.
[0048] It should be noted that the intelligent generation model involved in the technical solutions provided in the embodiments of the present application, such as the intelligent code enhancement model, the intelligent object generation model, the intelligent code generation model, and the intelligent code repair model involved below, can adopt a deep learning model with a relatively large model parameter scale, wherein the large model is only one model example, and the embodiments of the present application do not limit the number of model parameters supported by the deep learning model adopted to meet the actual demand. The deep learning model involved in the embodiments of the present application can be a language model (Language Model, LM) or a multimodal model (Multimodal Model, MM) based on artificial intelligence.
[0049] In the embodiment, if the at least one intelligent generation model is used to generate the test code corresponding to the target code, the prompt instruction can be generated based on the target code. For example, the target code is taken as input data, and then one or more condition information in role setting, code generation requirements (such as constraint conditions, processing steps, output requirements, etc.), generation logic (such as thought chain), and example data is combined to generate the prompt instruction. The generated prompt instruction is input into the intelligent generation model, and the intelligent generation model generates the test code corresponding to the target code according to the code generation requirements and the generation logic with reference to the example data.
[0050] In the implementation, the plurality of intelligent generation models are independently operated and generate the test code corresponding to the target code based on the prompt instruction, and then the final test code is determined according to the test codes generated by the plurality of intelligent generation models. For example, the test code with a high confidence level can be selected as the final test code in combination with the confidence levels of the test codes generated by the plurality of intelligent generation models. The test codes generated by the plurality of intelligent generation models can also be displayed to the user in a man-machine interactive manner, and the final test code is determined based on the selection operation of the user on the plurality of test codes. The plurality of test codes can also be integrated by using an intelligent model with a code integration function to generate more accurate test code. In another implementation, the test code generation task can be divided into subtasks, and the plurality of intelligent generation models can be responsible for the subtasks to generate the test code in cooperation with each other.
[0051] It should be noted that the intelligent generation model has a high requirement on the hardware performance of the electronic device, and therefore the intelligent generation model is usually deployed on the server. If the code development tool integrated with the test plug-in is deployed on the server, the test plug-in can directly call the at least one intelligent generation model to generate the test code corresponding to the target code. If the code development tool integrated with the test plug-in is deployed on the user side, the test plug-in can call the test server to generate the test code corresponding to the target code by using the at least one intelligent generation model. For example, a test code generation request carrying the target code can be sent to the test server, so that the test server acquires the target code in response to the test code generation request, calls the at least one intelligent generation model to generate the test code corresponding to the target code, and feeds back to the test plug-in on the user side. The test plug-in deployed on the user side can call the intelligent generation model to generate the test code, which provides a guarantee.
[0052] S106, executing the test code to test the target code in the test environment after the update, and outputting a test result.
[0053] In this embodiment, the test code can be executed by running the target test script (i.e., a script for automatically executing the test code) in the test environment after the update, so as to test the target code, and the test result can be generated according to the running log of the test code. Specifically, the running error information, the test coverage (such as the comprehensive coverage, the branch coverage, the function coverage, and the function coverage), and the test pass rate can be parsed from the running log, and the parsed information can be integrated as the test result.
[0054] In some embodiments, in order to realize that after the test code is generated, the subsequent code testing operation can be automatically executed, after S105 is executed, the embodiment further includes: in response to the generation of the test code, writing the test code in the form of a code file into a preset directory, and adjusting the file name of the test code corresponding to the preset directory according to the file path of the target code; and correspondingly, when this step is executed, the target test script can be run in the preset directory to call the test code file corresponding to the file path of the target code, and the test code file can be executed in the updated test environment to test the target code and output the test result. When the file name of the test code corresponding to the preset directory is adjusted according to the file path of the target code, the description information of the test file can be added on the basis of the target file path, so as to obtain the file name corresponding to the test file. For example, if the file path of the target code is "card / productCard", the file name corresponding to the test code can be adjusted to "card_productCard.ai.test.tsx". The advantage of such setting is that the explainability of the file name is improved, for example, through "card_productCard.ai.test.tsx", it can be directly seen that the file is the test code of the target code with the file path "card / productCard" generated by ai.
[0055] It should be noted that the code testing method of the embodiment can be used for front-end or back-end code testing scenarios. For different testing scenarios, when the code testing method of the embodiment is executed, the test environment can be detected according to the actual application code development framework and test framework and its version, and after the test environment is updated according to the environment detection result, the test code generation and running operation is executed.
[0056] In some embodiments, when the embodiment outputs the test result, the test result can be displayed in the code editing interface. As shown in Figure 2 The test result displayed in the test result display panel 203 of the code editing interface can include but is not limited to the file name of the target code, the related information of the test error, the test coverage, and the test pass rate.
[0057] The embodiment obtains target code selected in a code editing interface through a test plug-in integrated in a code development tool, and provides test prompt information. In response to a trigger operation on the test prompt information, a test instruction is generated. In response to the test instruction, a test environment of the target code is detected, and the test environment is updated according to an environment detection result. At least one intelligent generation model is used to generate test code corresponding to the target code. The test code is executed in the updated test environment to test the target code, and a test result is output. The scheme automatically generates test code for the target code through an intelligent generation model, and automatically executes the test operation of the target code, solving the pain points of low efficiency and poor accuracy of manually writing test code, and effectively reducing the threshold of writing test code. In addition, the test plug-in is integrated in the code development tool, and the test plug-in is used to realize the automatic test process from test environment detection to test code generation and target code testing. The entire test process is triggered and executed by one key after selecting the target code. The full-automatic test process greatly improves the automation, efficiency and accuracy of code testing.
[0058] In addition, the embodiment also integrates the shortcut operation mode with the IDE ecology, designs a shortcut instruction awakening mechanism based on code selection, triggers the generation of a test instruction without dialogue interaction, and uses the API (Application Programming Interface) of a standard code development tool to develop, ensuring seamless integration with mainstream front-end development IDEs, providing higher flexibility and user experience than independent IDEs.
[0059] Since the generation task of the test code is a complex long task, directly letting the intelligent generation model execute the long task may cause inattention and low accuracy due to hallucination. To solve this problem, in some embodiments, the generation task of the test code can be disassembled based on an AI (Artificial Intelligence) code generation architecture, and the disassembled subtasks are executed by at least one intelligent generation model in sequence to generate the test code. That is, at least one intelligent generation model is used to update the information of the target code while keeping the code logic of the target code unchanged as a constraint condition; the code dependency in the updated target code is detected, and a virtual object replacing the code dependency is generated; and the test code is generated based on the updated target code and the virtual object.
[0060] Specifically, at least one intelligent generation model can be used to update the information of the target code while keeping the code logic of the target code unchanged as a constraint condition.
[0061] In an implementation, the information updating operation can include complementing the definition information of the missing parameter type in the target code (i.e., type definition information complementing), to ensure that accurate parameter types can be provided when generating test code for the target code subsequently, and to reduce errors in the test code. For example, it can be determined whether each parameter variable in the target code has corresponding type definition information (such as text type, string type, numerical value type, etc.), and type information complementing can be performed on the parameter variable that does not have type definition information.
[0062] In another implementation, the information updating operation can include modifying the import path in the target code. Since the import path corresponding to the external transmission parameter (which belongs to the code dependency in the following description) in the target code is a relative path, the external transmission parameter cannot be obtained through the relative path in the test process due to the lack of the real external transmission parameter. Therefore, the embodiment can modify the import path corresponding to the external transmission parameter in the target code to the absolute path of the external transmission parameter (the virtual parameter value corresponding to the external transmission parameter is stored in the absolute path), to ensure that the test code can obtain the virtual parameter value corresponding to the external transmission parameter based on the modified import path. For example, a path containing a preset character (i.e., a character contained in the relative path) in the target code is found as the relative path, and the relative path is modified to the absolute path according to the modification rule.
[0063] Of course, the information updating operation can also include type definition information complementing and import path modifying.
[0064] After the information updating of the target code, all code dependencies contained in the target code can be traversed and identified, and a virtual object (Mock) replacing each code dependency can be generated. The code dependency can be an external resource that needs to be depended on during the running of the target code, such as a framework, a tool library, a third-party library, etc. The embodiment replaces the code dependency of the target code with the virtual object, simulates the response of the code dependency through a preset behavior and return value, to ensure the independence and controllability of the test process.
[0065] In addition, after the virtual object is generated, the updated target code can be parsed to determine at least one test case, and test code for the target object can be generated based on the generated virtual object and the test case. The embodiment divides the complex test code generation task into three sub-tasks of code complementing (i.e., target code repairing), virtual object generation, and test code generation, each of which is configured with a special prompt instruction (i.e., prompt instruction) and an independent model session context, to improve the AI generation accuracy through task focusing, effectively solving the problems of model attention dispersion and illusion in the model output result in the long task, and improving the accuracy of the finally generated test code.
[0066] Optionally, in the present embodiment, the above-mentioned disassembled sub-tasks can be implemented by an intelligent generation model, or can be implemented by multiple intelligent models cooperating with each other to improve the accuracy of the test code. For example, the following operations can be implemented by an intelligent code enhancement model, an intelligent object generation model, and an intelligent code generation model.
[0067] Operation 1, using an intelligent code enhancement model to complete the type definition information and correct the import path of the target code with the constraint condition of keeping the code logic of the target code unchanged.
[0068] In the present embodiment, the target code can be taken as input data, combined with one or more conditional information in role setting (such as code testability enhancement expert), path correction requirements (such as constraint conditions (i.e. keeping the code logic of the target code unchanged), type definition information and import path update steps, output requirements, etc.), update logic (such as the thinking chain corresponding to the analysis of type definition information and import path), and example data, to generate a prompt instruction, and input the generated prompt instruction into the intelligent code enhancement model. The intelligent code enhancement model takes the example data as a reference, keeps the code logic of the target code unchanged as a prerequisite, and performs the update steps of type definition information and import path according to the thinking chain corresponding to the analysis of type definition information and import path, to obtain the updated target code that meets the output requirements. The present embodiment is based on the code context completion technology of AI reasoning, automatically extracts and completes the type definition information of the target code, intelligently converts the relative path into an absolute path, and provides accurate type guidance for the subsequent test code generation process (such as parameter construction and assertion generation, etc.), which significantly reduces the path error and type mismatch problem of the generated test code.
[0069] Operation 2, using an intelligent object generation model to detect the code dependency in the updated target code and generate a virtual object to replace the code dependency.
[0070] In the present embodiment, the target code updated in operation 1 can be taken as input data, combined with one or more conditional information in role setting (such as virtual object analysis expert), virtual object generation requirements (such as constraint conditions, virtual object type requirements, generation steps, and output requirements, etc.), virtual object generation logic (such as thinking chain), and example data, to generate a prompt instruction. The generated prompt instruction is input into the intelligent object generation model, which takes the example data as a reference, executes the steps of detecting the code dependency in the updated target code and generating a virtual object to replace the code dependency according to the thinking chain of the virtual object generation logic under the condition of meeting the constraint conditions, to obtain the virtual object that meets the output requirements.
[0071] Operation 3, generating the test code based on the target code after the update and the virtual object by using the intelligent code generation model.
[0072] The embodiment can generate the prompt instruction by taking the target code after the update of operation 1 and the virtual object generated in operation 2 as input data, combining one or more condition information in role setting (such as a technical expert focusing on code testing), code generation requirements (such as constraint conditions (such as prohibiting modification of the virtual object code), code generation steps and output requirements, and the like), test code generation logic (such as a thinking chain), and example data, and the like. The generated prompt instruction is input into the intelligent code generation model. The intelligent code generation model takes the example data as a reference, and generates the test code that meets the output requirements by performing operations such as analyzing the target code, selecting a test strategy, generating a test case list, and writing the virtual object code in the case of meeting the constraint conditions.
[0073] The embodiment uses the intelligent code enhancement model, the intelligent object generation model, and the intelligent code generation model to respectively perform each subtask after the disassembly. Compared with using one intelligent generation model to implement the above subtasks, the complexity of the processing task of each model is reduced, and the accuracy of the execution result is improved.
[0074] It should be noted that the intelligent code enhancement model, the intelligent object generation model, and the intelligent code generation model can be the same model or different models.
[0075] In some embodiments, the test code determined by using at least one intelligent generation model can have code errors, thereby affecting the accuracy of the test result. In order to avoid this problem and ensure the reliability of the test result, the embodiment can perform error detection on the test code when performing the above S106 step, and repair the test code according to the error detection result; in the test environment after the update, the test code after the repair is executed to test the target code, and the test result is output. Thus, an end-to-end automatic and non-intervention workflow from environment detection, environment dependency installation, code generation, to automatic repair, and then execution of the test code is realized. The traditional dialog-driven mode is abandoned, a full-automatic test code generation and execution process of one-key triggering and background silent code repair is realized, the user does not need to participate too much, and the convenience of the operation process is improved.
[0076] In the embodiment, one implementable way of performing error detection on the test code and repairing the test code according to the error detection result can be that an intelligent code repair model is used to analyze the generated test code, to determine whether the test code has errors (such as syntax errors, code logic errors, virtual object errors, and the like), and to automatically repair the test code according to the detection result.
[0077] Yet another implementation manner can be implemented through the following three sub-steps: Sub-step one, in the test environment after the update, the test code is executed in silence to test the target code, and the running log of the test code is obtained.
[0078] This embodiment can be that in the test environment after the update, the target test script (i.e. the script of the test code) is executed in silence to execute the test code to test the target code, and the running log of the test code is obtained. The test code is executed in silence in this embodiment, and the repair of the test code can be completed without the user's awareness.
[0079] Sub-step two, determining the error type existing in the test code according to the running log.
[0080] The running log obtained in this embodiment records the related information of the running error, and the related information of the running error can be analyzed to determine the error type existing in the test code. For example, the related information of the running error can be analyzed to determine the error type existing in the test code according to the analysis rule corresponding to each error type; or the related information of the running error recorded in the running log can be identified by an intelligent error identification model to determine the error type existing in the test code.
[0081] In the case of decomposing the test code generation task into three sub-tasks of target code update, virtual object generation and test code generation, the target code update generally does not cause the test code running error, so the errors existing in the test code can be divided into virtual object errors and test code errors. This example can determine the error type existing in the test code based on the exception stack information contained in the stack call data of the test code execution contained in the running log. Specifically, if the exception stack information contains a preset character, it is determined that the error type includes a virtual object error; if the exception stack information points to the test code, it is determined that the error type includes a test code error. This embodiment can quickly and accurately locate the error type existing in the test code according to the exception stack information, thereby ensuring accurate repair of the test code.
[0082] In actual application, the running error recorded in the running log of the test code can be caused by the error of the test code, or caused by the error of the target code or the error of the configuration data. The determination manner of the error type of the test code has been introduced in the above embodiment. Next, the determination manner of the error type of the target code and the configuration data is introduced. Specifically, if the exception stack information points to the target code, it is determined that the error type includes a target code error (i.e., the target code has an error); if the exception stack information points to the configuration data, it is determined that the error type includes a configuration error (i.e., the configuration data has an error). The target code error and the configuration error can be fed back to the user as the test result, so that the user can update the target code or the configuration information.
[0083] Sub-step three, repairing the test code according to the error type.
[0084] Specifically, in the case that the error type of the test code includes the virtual object error and / or the test code error, the test code is repaired for the virtual object error and / or the test code error. For example, the test code can be repaired according to the repair rule corresponding to each error type. The test code can also be repaired by using a model according to the error type.
[0085] When the test code is repaired by using the model according to the error type, the intelligent repair model specially used for code repair is used to repair the test code based on the test code and the corresponding error type, to obtain the repaired test code. The at least one intelligent generation model used to generate the test code can also be used to repair the test code in combination with historical data and the error type, to regenerate the repaired test code. The historical data can include data input, parsed and generated by the intelligent generation model in the process of generating the test code. For example, if the error type is the virtual object error, the intelligent object generation model can be used to repair the previously generated virtual object based on the virtual object error and the historical data, and the intelligent code generation model can be used to repair the test code in combination with the historical data and the repaired virtual object. If the error type is the test code error, the intelligent code can be used to repair the test code based on the historical data and the test code error. In this embodiment, the intelligent generation model used to generate the test code is used to repair the test code, without the need to repeatedly input the test code, reducing the input complexity. In the process of repairing the test code, the intelligent generation model can use the historical data reserved in the code generation stage as context information to assist in repairing the test code, improving the repair efficiency and accuracy of the test code.
[0086] After the test code is generated, the embodiment runs the test code in an actual test environment, obtains a running log, and performs automatic classification of four types of errors in a manner of call stack analysis and regular matching, establishes a mapping mechanism from errors to repair tasks, realizes real-time feedback of a running result in a real test environment and targeted repair of the test code, makes up for the defect that the test code generated by the intelligent generation model lacks a running environment, realizes automatic repair of the code and then testing, and improves the first-time test pass rate of the test code.
[0087] In some embodiments, if the error type of the test code corresponds to multiple errors, the test code can be repaired in sequence according to the order of occurrence of the multiple errors, in combination with the error types corresponding to the multiple errors.
[0088] In some embodiments, in the case where the error type includes a target code error and / or a configuration error, and there is no virtual object error and test code error, a test result is generated based on the running log and the target code error and / or the configuration error. At this time, the coverage and test pass rate of the current code test can be determined based on the running log, and the test result is generated together with the target code error and / or the configuration error and fed back to the user.
[0089] In some embodiments, the test code after one repair operation may still have errors, for example, one repair may not be able to repair all errors of the test code, or new errors may be caused during the repair process. In order to ensure the accuracy of the test result, the embodiment further includes, in response to the repair operation of the test code, continuing to execute the test code in a silent manner in the updated test environment, and obtaining a running log of the test code until the test code meets the repair requirements; wherein the repair requirements can be that the test code has no errors, or that the existing errors cannot be further repaired. In the case where the test code meets the repair requirements, a test result is generated according to the running log generated by the latest execution of the test code, and the test result is output. Specifically, after each repair operation is performed, the operation of obtaining the running log in sub-step one is returned, if the running log shows that the test code still has errors, the operations of sub-step two and sub-step three are continued, the test log is repaired again, and the operation of sub-step one is re-executed for the repaired test task, until the running log shows that there is no error of the test code, or the existing error of the test code cannot be further repaired. At this time, the test result is generated according to the running log generated by the latest execution of the test code. It should be noted that if there is still an error of the test code that cannot be repaired, or a target code error or a configuration error, it can be added to the test result, so that the user can update the test code, the target code and the configuration data.
[0090] In some embodiments, in order to facilitate the user to intuitively understand the execution state of the code test, the embodiment can further include: obtaining an execution state corresponding to the test instruction; displaying state prompt information corresponding to the execution state in the plug-in panel. The state prompt information is used to prompt the user about the current execution state of the code test task. For example, Figure 2 The content displayed in block 204 is the state prompt information. Specifically, the test plug-in can detect the execution state corresponding to the test instruction in real time (such as which one of the test environment detection state, the test code generation state, the test code repair state, and the execution test code state), and then display the prompt information corresponding to the execution state in the plug-in panel.
[0091] The above embodiments introduce the specific process of implementing code testing by the test plug-in integrated in the code development tool. The technical solutions of the present application will be introduced from the perspective of the code development tool as follows. Figure 4 As shown in FIG. 8, when applied to the code development tool, the code testing method of the embodiment can include the following steps: S401, in response to a code selection operation in the code editing interface, determining a target code.
[0092] S402, calling the test plug-in, detecting the test environment of the target code in the case of detecting a test instruction, and updating the test environment according to the environment detection result; using at least one intelligent generation model to generate test code corresponding to the target code; executing the test code in the updated test environment to test the target code, and outputting a test result; the test instruction is generated in response to a trigger operation on the test prompt information.
[0093] It should be noted that the specific implementation manner of the code development tool calling the test plug-in to execute S402 operation in the embodiment is the same as the implementation manner of the test plug-in executing the related operation in the above embodiments, and no further description is made.
[0094] In some embodiments, the code development tool of the embodiment has both code editing and code testing functions, so the method of the embodiment further includes editing the target code in response to a code editing operation in the code editing interface. Specifically, the code editing operation of the target code in the code editing interface can be performed before S401 is executed to develop the target code, that is, the target code obtained by executing S401 can be the code newly developed by the user in the code editing interface. The code editing operation of the target code in the code editing interface can also be performed based on the test result after S402 is executed, that is, the target code edited in response to the code editing operation can be modified.
[0095] In some embodiments, the embodiment further includes, before performing S401, installing a test plug-in in a code development tool in response to an installation instruction for the test plug-in, such as installing the plug-in in a front-end integrated development environment of the code development tool. Thus, the installed test code is called to automatically perform a test operation on the target code.
[0096] In some embodiments, after S402 calls the test plug-in to generate test code, the test code can be first error-detected, and the test code can be repaired according to the error detection result, and then the test code is further executed in the updated test environment to test the target code and output the test result. The specific implementation manner has been introduced in the above embodiment, and will not be described here.
[0097] In an actual application, taking the target code as an example of the code of an arbitrary front-end unit, the code testing method of the embodiment is introduced. As shown in Figure 5 The AI application platform can be a test server that can provide AI services as described above, and includes a plurality of selectable intelligent generation models (such as model one to model four). The AI application platform can generate a prompt instruction for the corresponding intelligent generation model through a prompt word engineering module to control the intelligent generation model to generate test code. The model session memory module in the AI application platform is used to record data generated during model running (such as input data, thinking and reasoning data, and output data of the model). In this embodiment, the model session memory module can provide historical data for the intelligent generation model repairing the test code during the test code repairing process, without the need to repeatedly input historical data such as test code, thereby reducing the input complexity, and using the historical data as context information to assist in repairing the test code, thereby improving the repairing efficiency and accuracy. Figure 5 The unit test generation link in the AI application platform is an execution link for the test plug-in to generate test code. The test plug-in can call at least one intelligent generation model implementation in the AI application platform during execution of the unit test generation link. The plug-in side is the test plug-in that performs unit testing, and the following will be described in combination with Figure 5 The code testing method of the embodiment is introduced.
[0098] First, a test plug-in needs to be installed in a code development tool deployed on a computing device, and the test plug-in needs to be invoked in a code editing interface of the code development tool, and a plug-in view (i.e., a plug-in panel) is displayed. The plug-in view displays test prompt information and state prompt information corresponding to the execution state of unit testing.
[0099] After the test plug-in is invoked, it actively detects whether there is a code selection operation in the code editing interface (S501). If there is, the code under test (i.e., the target code) is obtained. At this time, if a trigger operation for the test prompt information is detected in the plug-in view (S502), the test instructions corresponding to the code under test are generated based on the core instruction logic (S503). In response to the test instructions, the test plug-in first detects the test environment of the code under test, and updates the test environment according to the environment detection result, and then executes the single test generation link. Specifically, the obtained code under test is first subjected to code analysis and completion processing (i.e., information updating of the code under test), including type definition information completion and / or import path correction (S504), to obtain the completed code under test. Then, for the completed code under test, Mock list identification is performed from the dimensions of precise library methods, UI component library, global variables, custom components, React-related, and function services (S505) to generate Mock list code, and then at least one intelligent generation model of an AI application platform is called to analyze the completed code under test (i.e., the completed code), select a test strategy, generate test cases, and write Mock list code in the test cases, thereby obtaining test code. In order to ensure the accuracy of the test code, the generated test code can be asserted during the generation of the test code. If the assertion passes, the generation of the test code is completed (S506). Next, in response to the generation of the test code, the test code is written in the form of a code file in a preset directory, and the file name of the test code corresponding to the file path of the code under test is adjusted in the preset directory (i.e., written in the file). In response to the writing operation in the preset directory, the test code corresponding to the file path of the code under test is called in the preset directory, and the test script is executed in the updated test environment to perform the test code file in the actual running environment to test the code under test, and the running log of the test code (i.e., the execution of the test script) is obtained. Then, the running log is parsed to determine whether the test code has Mock errors and / or test code errors (S507). If there are, the corresponding intelligent generation model in the AI application platform is continuously called, and S506 is returned to repair the test code according to the error type until the test code meets the repair requirements. According to the running log generated by the last execution of the test code, the test result is generated.
[0100] The embodiment adopts the sub-task disintegration manner to disintegrate the code generation task of the complex unit test into three links of code analysis and completion (S504), Mock list identification (S505), and test code generation (S506), each of which is executed by calling the corresponding intelligent generation model in the AI application platform, and for each link, a special prompt instruction is designed through the prompt word engineering module to guide the corresponding intelligent generation model to accurately complete each sub-task. The model illusion phenomenon under the complex long task is suppressed, the task focus and the code generation accuracy are significantly improved, and the probability of the first test success of the unit test is improved. The embodiment also supports automatically triggering the integrity and version compatibility of the detection environment in response to the test instruction of the unit component, automatically completing the missing dependency installation, and generating configuration data. An end-to-end fully automated process is realized, the test environment consistency is ensured, the test workflow interruption caused by the test environment problem is eliminated, and the environment configuration cost is reduced. In addition, the embodiment also builds an error type identification algorithm and an automatic repair mechanism, obtains running error information in the running log through silent execution of the test script, feeds back the intelligent classification to the corresponding intelligent generation model for repair, and realizes autonomous repair of the test code defects. The inherent defects of the intelligent generation model in generating the test code without a running environment are compensated, a "generation-error analysis-repair" closed loop is established, and the first pass rate of the test code is improved. In summary, the embodiment realizes the full-process automation from environment configuration to test code generation to error repair, and the user participation is reduced to the minimum. At the same time, the test plug-in adopted supports seamless integration of multiple integrated development environments, and provides a more efficient, more intelligent, and more convenient unit test automation solution for users.
[0101] The detailed implementation and beneficial effects of each step in the method of the embodiment have been described in detail in the foregoing embodiments, and will not be described in detail here.
[0102] It should be noted that in some of the processes described in the foregoing embodiments and the accompanying drawings, a plurality of operations appear in a specific order, but it should be clearly understood that these operations can be executed or in parallel without following the order in which they appear in this document. The serial numbers of the operations, such as S101, S102, etc., are only used to distinguish different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes can include more or fewer operations, and the operations can be executed in sequence or in parallel. It should be noted that the "first", "second", etc. in this document are used to distinguish different messages, devices, modules, etc., and do not represent the order of precedence. Also, "first" and "second" are not different types.
[0103] Figure 6 A structural schematic diagram of one embodiment of a code testing device provided by the present application is shown. Figure 6The illustrated code testing apparatus is configured in a test plug-in integrated in a code development tool, and the apparatus comprises: a target code obtaining module 601 configured to obtain a target code selected in a code editing interface; a prompt information providing module 602 configured to provide test prompt information; a test instruction generating module 603 configured to generate a test instruction in response to a triggering operation on the test prompt information; a test environment detecting module 604 configured to detect a test environment of the target code in response to the test instruction, and update the test environment according to an environment detection result; a test code generating module 605 configured to generate test code corresponding to the target code by using at least one intelligent generation model; a first code testing module 606 configured to execute the test code to test the target code in the updated test environment, and output a test result.
[0104] In an optional embodiment, the apparatus further comprises a code repairing module configured to detect errors of the test code, and repair the test code according to an error detection result. The first code testing module 606 is specifically configured to execute the repaired test code to test the target code in the updated test environment, and output a test result.
[0105] In an optional embodiment, the code repairing module is specifically configured to execute the test code to test the target code in the updated test environment in a silent mode, and obtain a running log of the test code; determine a type of errors existing in the test code according to the running log; and repair the test code according to the type of errors.
[0106] In an optional embodiment, the running log comprises stack call data of executing the test code; the stack call data contains exception stack information; the code repairing module is specifically configured to determine that the type of errors includes a virtual object error if the exception stack information contains a preset character; determine that the type of errors includes a test code error if the exception stack information points to the test code; and repair the test code for the virtual object error and / or the test code error if the type of errors existing in the test code includes the virtual object error and / or the test code error.
[0107] In an optional embodiment, the apparatus further includes: a test result generation module, configured to determine that the error type includes a target code error if the exception stack information points to target code; determine that the error type includes a configuration error if the exception stack information points to configuration data; and generate test results based on the runtime log and the target code error and / or configuration error in the first case where the error type includes a target code error and / or a configuration error, and there are no virtual object errors or test code errors.
[0108] In an optional embodiment, the code repair module is further configured to use the at least one intelligent generation model, combined with historical data and the error type, to repair the test code and regenerate the repaired test code.
[0109] In an optional embodiment, the code repair module is further specifically used to respond to the repair operation of the test code, continue to execute the test code silently in the updated test environment, and obtain the running log of the test code until the test code meets the repair requirements; the first code test module 606 is further used to generate test results based on the running log generated by the most recent execution of the test code when the test code meets the repair requirements; and output the test results.
[0110] In an optional embodiment, the test code generation module 605 is specifically configured to use at least one intelligent generation model to update the target code with the constraint of keeping the code logic of the target code unchanged; detect code dependencies in the updated target code and generate virtual objects to replace the code dependencies; and generate test code based on the updated target code and the virtual objects.
[0111] In an optional embodiment, the test code generation module 605 is further configured to use an intelligent code enhancement model to complete the type definition information and correct the import path of the target code while keeping the code logic of the target code unchanged as a constraint; use an intelligent object generation model to detect code dependencies in the updated target code and generate virtual objects to replace the code dependencies; and use the intelligent code generation model to generate test code based on the updated target code and the virtual objects.
[0112] In an optional embodiment, the test code generation module 605 is further configured to call a test server to generate test code corresponding to the target code using at least one intelligent generation model.
[0113] In an optional embodiment, the target code obtaining module 601 is specifically configured to detect a code selection operation in a code editing interface, and obtain the selected target code; or, provide code obtaining prompt information, and read the selected target code in the code editing interface in response to a triggering operation of the code obtaining prompt information.
[0114] In an optional embodiment, the test environment detecting module 604 is specifically configured to detect whether the test environment of the target code has an environment dependency missing and / or a version conflict in response to the test instruction; if yes, install the missing environment dependency in the test environment, and / or correct the environment dependency with the version conflict, and generate the test environment configuration data; if no, generate the configuration data of the test environment.
[0115] In an optional embodiment, the apparatus further comprises a file writing module configured to write the test code in the form of a code file into a preset directory in response to a generation operation of the test code, and adjust a file name of the test code corresponding to the target code according to a file path of the target code; the first code testing module 606 is specifically configured to invoke a test code file corresponding to the file path of the target code in the preset directory in response to a writing operation in the preset directory, and execute the test code file in the test environment after the update to test the target code, and output a test result.
[0116] In an optional embodiment, the prompt information providing module 602 is specifically configured to display a plug-in panel in the code editing interface; and display the test prompt information in the plug-in panel.
[0117] In an optional embodiment, the apparatus further comprises a test state displaying module configured to obtain an execution state corresponding to the test instruction; and display state prompt information corresponding to the execution state in the plug-in panel.
[0118] Figure 6 The code testing apparatus can perform Figure 1 The implementation principle and technical effects of the code testing method according to the embodiments are not described again. The specific operation manner of each module and unit in the code testing apparatus according to the above embodiments has been described in detail in the embodiments of the method, and will not be described again.
[0119] Figure 7 FIG. 1 shows a structural schematic diagram of another embodiment of a code testing apparatus provided by the present application, Figure 7 The code testing apparatus is configured in a code development tool, the code development tool integrates a test plug-in, and the apparatus comprises: The target code determination module 701 is configured to determine target code in response to a code selection operation in a code editing interface. The second code testing module 702 is configured to call the test plug-in, detect a test environment of the target code in a case where a test instruction is detected, and update the test environment according to an environment detection result; generate test code corresponding to the target code by using at least one intelligent generation model; execute the test code in the updated test environment to test the target code, and output a test result; and the test instruction is generated in response to a trigger operation on test prompt information.
[0120] In an optional embodiment, the apparatus further includes a code editing module configured to edit the target code in response to a code editing operation in the code editing interface.
[0121] In an optional embodiment, the apparatus further includes a plug-in installation module configured to install the test plug-in in a code development tool in response to an installation instruction on the test plug-in.
[0122] Figure 7 The code testing apparatus can perform Figure 4 The implementation principle and technical effects of the code testing method in the embodiments are not described again. The specific operation manner of each module and unit in the code testing apparatus in the above embodiments has been described in detail in the embodiments related to the method, and will not be described in detail here.
[0123] Figure 8 An embodiment of a structure schematic diagram of a computing device provided in the present application is shown in FIG. 8. Figure 8 As shown, in practice, the computing device can include a storage component 801 and a processing component 802.
[0124] The storage component 801 is configured to store computer programs, and can be configured to store other various data to support operations on the computing device. Examples of the data include instructions of any application program or method for operating on the computing device, data structures, contact data, phonebook data, messages, pictures, videos, and the like.
[0125] The processing component 802 is coupled to the storage component 801, and is configured to execute computer programs in the storage component 801, for implementing the code testing method shown in Figure 1 or 4.
[0126] Further, as shown in Figure 8 The computing device can further include a communication component 803, a display component 804, a power supply component 805, an audio component 806, and other components. Figure 8The diagram only shows some components and does not mean that the device includes only these components. Figure 8 The components shown. Additionally... Figure 8 The components within the dashed box are optional, not mandatory, and their specific requirements depend on the product form of the computing device. The computing device in this embodiment can be a terminal device such as a desktop computer, laptop computer, smartphone, or IoT (Internet of Things) device, or a server-side device such as a conventional server, cloud server, or server array. If the computing device in this embodiment is implemented as a terminal device such as a desktop computer, laptop computer, or smartphone, it may include... Figure 8 The components within the dashed box; if the computing device in this embodiment is implemented as a conventional server, cloud server, or server array, etc., then it may not include... Figure 8 The component within the dashed box.
[0127] The processing component described above includes one or more processors to execute computer instructions to complete all or part of the steps in the method described above. Alternatively, the processing component may be implemented as one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the method described above.
[0128] The aforementioned storage components can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random-Access Memory (SRAM), Electrically Erasable Programmable Read Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0129] The aforementioned communication component is configured to facilitate wired or wireless communication between the device housing the communication component and other devices. The device housing the communication component can access wireless networks based on communication standards, such as mobile communication networks, or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel.
[0130] The display component can include a screen, which can include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense a touch, a slide and a gesture on the touch panel. The touch sensor can not only sense a boundary of a touching or a sliding movement, but also detect a duration and a pressure associated with the touching or the sliding movement.
[0131] The power component provides power to various components of the device in which the power component is located. The power component can include a power management system, one or more power sources, and other components associated with generating, managing and distributing power to the device in which the power component is located.
[0132] The audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC) that is configured to receive an external audio signal when the device in which the audio component is located is in an operational mode, such as a call mode, a recording mode and a voice recognition mode. The received audio signal can be further stored in a memory or transmitted via the communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals.
[0133] Accordingly, the embodiments of the present application also provide a computer readable storage medium storing a computer program, when the computer program is executed by a processor, the processor is enabled to implement each step in the above-mentioned method embodiments. The computer readable storage medium includes volatile or non-volatile or a combination thereof, and can be removable or non-removable. Examples of the computer readable storage medium include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital video disc (DVD) or other optical storage, magnetic cassette, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium Accordingly, the embodiments of the present application also provide a computer program product, which comprises computer programs or instructions, and when the computer programs or instructions are executed by a processor, the processor can realize each step in the above-mentioned method embodiments. It should be understood that each process or combination of multiple processes in the above-mentioned method flow can be realized by the computer programs or instructions. In addition, these computer programs or instructions can be applied to the processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing devices, so that the processor of the general-purpose computer, the special-purpose computer, the embedded processor or other programmable data processing devices can be realized as a device for realizing the corresponding functions in the above-mentioned method embodiments.
[0134] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-mentioned system, device and unit can refer to the corresponding processes in the above-mentioned method embodiments, which will not be described here.
[0135] It should also be noted that the terms "comprising", "including", or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or further includes elements inherent to such a process, method, article or device. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article or device including the element.
[0136] Finally, it should be noted that the above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. within the spirit and principles of the present application shall be included in the scope of the claims of the present application.
Claims
1. A code testing method, characterized in that, The method, applied to a testing plugin integrated into a code development tool, includes: Retrieve the target code selected in the code editing interface; Provide test prompts; In response to a triggering operation based on the test prompt information, a test instruction is generated; In response to the test command, the test environment of the target code is detected, and the test environment is updated according to the environment detection results; At least one intelligent generation model is used to generate test code corresponding to the target code; In the updated test environment, the test code is executed to test the target code, and the test results are output.
2. The method according to claim 1, characterized in that, In the updated test environment, executing the test code to test the target code and outputting the test results includes: Perform error detection on the test code and repair the test code based on the error detection results; In the updated test environment, the repaired test code is executed to test the target code, and the test results are output.
3. The method according to claim 2, characterized in that, The step of performing error detection on the test code and repairing the test code based on the error detection results includes: In the updated test environment, the test code is executed silently to test the target code, and the execution log of the test code is obtained; Determine the type of error present in the test code based on the runtime log; Repair the test code according to the error type.
4. The method according to claim 3, characterized in that, The runtime log includes: stack trace data of the execution of the test code; the stack trace data includes exception stack information; The error types determined based on the runtime logs include: If the exception stack information contains preset characters, the error type is determined to include virtual object error; If the exception stack information points to test code, the error type is determined to include a test code error; The step of fixing the test code according to the error type includes: If the error types present in the test code include virtual object errors and / or test code errors, the test code shall be repaired to address the virtual object errors and / or test code errors.
5. The method according to claim 4, characterized in that, Also includes: If the exception stack information points to the target code, then the error type is determined to include a target code error; If the exception stack information points to configuration data, then the error type is determined to include a configuration error; If the error types include target code errors and / or configuration errors, and there are no virtual object errors or test code errors, test results are generated based on the runtime logs and the target code errors and / or configuration errors.
6. The method according to claim 3, characterized in that, The step of fixing the test code according to the error type includes: Using the at least one intelligent generation model, combined with historical data and the error type, the test code is repaired to regenerate the repaired test code.
7. The method according to claim 3, characterized in that, In the updated test environment, the repaired test code is executed to test the target code, and the test results are output, including: In response to the repair operation of the test code, continue to execute the test code silently in the test environment after the update, and obtain the execution log of the test code until the test code meets the repair requirements; If the test code meets the repair requirements, the test results are generated based on the execution log generated from the most recent execution of the test code. Output the test results.
8. The method according to claim 1, characterized in that, The step of generating test code corresponding to the target code using at least one intelligent generation model includes: Using at least one intelligent generation model, with the constraint of keeping the code logic of the target code unchanged, the target code is updated; code dependencies in the updated target code are detected and virtual objects are generated to replace the code dependencies; and test code is generated based on the updated target code and the virtual objects.
9. The method according to claim 8, characterized in that, The process involves using at least one intelligent generation model to update the target code while maintaining its original code logic, and detecting code dependencies in the updated target code to generate virtual objects that replace those dependencies. And based on the updated target code and the virtual object, the generated test code includes: Using an intelligent code enhancement model, with the constraint of keeping the code logic of the target code unchanged, the target code is supplemented with type definition information and / or the import path is corrected. Using a smart object generation model, code dependencies in the updated target code are detected, and virtual objects are generated to replace the code dependencies. Using an intelligent code generation model, test code is generated based on the updated target code and the virtual object.
10. The method according to any one of claims 1-9, characterized in that, The step of generating test code corresponding to the target code using at least one intelligent generation model includes: The test server is invoked to generate test code corresponding to the target code using at least one intelligent generation model.
11. The method according to claim 1, characterized in that, The process of obtaining the target code selected in the code editing interface includes: Detect code selection operations in the code editing interface and obtain the selected target code; Alternatively, provide code retrieval prompts and, in response to the triggering operation of the code retrieval prompts, read the target code selected in the code editing interface.
12. The method according to claim 1, characterized in that, The step of responding to the test instruction by detecting the test environment of the target code and updating the test environment based on the environment detection results includes: In response to the test command, detect whether there are missing environment dependencies and / or version conflicts in the test environment of the target code; If so, install the missing environment dependencies in the test environment and / or fix the conflicting environment dependencies, and generate the test environment configuration data; If not, generate the configuration data for the test environment.
13. The method according to claim 1, characterized in that, Also includes: In response to the test code generation operation, the test code is written to a preset directory as a code file, and the file name corresponding to the test code in the preset directory is adjusted according to the file path of the target code; In the updated test environment, executing the test code to test the target code and outputting the test results includes: In response to a write operation in a preset directory, the test code file corresponding to the file path of the target code is called in the preset directory, and the test code file is executed in the updated test environment to test the target code and output the test results.
14. The method according to claim 1, characterized in that, The provision of the test prompt information includes: The plugin panel is displayed in the code editing interface; The test prompt information is displayed in the plugin panel.
15. The method according to claim 1, characterized in that, Also includes: Obtain the execution status corresponding to the test instruction; The status prompt information corresponding to the execution status is displayed in the plugin panel.
16. A code testing method, characterized in that, Applied to code development tools, wherein the code development tools integrate testing plugins, the method includes: In response to code selection in the code editing interface, the target code is determined; The test plugin is invoked to detect the test environment of the target code when a test instruction is detected, and the test environment is updated according to the environment detection results; at least one intelligent generation model is used to generate test code corresponding to the target code; in the updated test environment, the test code is executed to test the target code and the test results are output; the test instruction is generated in response to a trigger operation for test prompt information.
17. The method according to claim 16, characterized in that, Also includes: In response to a code editing operation in the code editing interface, the target code is edited.
18. A computing device, characterized in that, This includes processing components and storage components; The storage component stores a computer program and a code development tool integrated with a testing plugin; the computer program is invoked by the processing component to run the code development tool integrated with the testing plugin, the testing plugin being used to implement the code testing method as described in any one of claims 1-15, and the code development tool being used to implement the code testing method as described in claim 16 or 17.
19. A computer-readable storage medium, characterized in that, It stores a computer program and a code development tool with integrated testing plugins. The computer program is called by a processing component and runs the code development tool with integrated testing plugins. The testing plugins are used to implement the code testing method as described in any one of claims 1-15, and the code development tool is used to implement the code testing method as described in claim 16 or 17.
20. A computer program product, characterized in that, The method includes a computer program or instructions that are invoked by a processing component and run a code development tool integrated with a testing plugin, the testing plugin being used to implement the code testing method as described in any one of claims 1-15, and the code development tool being used to implement the code testing method as described in claim 16 or 17.