CN117891732A - Code testing method and device - Google Patents

Code testing method and device Download PDF

Info

Publication number
CN117891732A
CN117891732A CN202410064259.6A CN202410064259A CN117891732A CN 117891732 A CN117891732 A CN 117891732A CN 202410064259 A CN202410064259 A CN 202410064259A CN 117891732 A CN117891732 A CN 117891732A
Authority
CN
China
Prior art keywords
test
code
tested
range
case
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410064259.6A
Other languages
Chinese (zh)
Inventor
杜兴文
张静静
谢晓群
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202410064259.6A priority Critical patent/CN117891732A/en
Publication of CN117891732A publication Critical patent/CN117891732A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a code testing method and device, and relates to the technical field of software development. One embodiment of the method comprises the following steps: the method comprises the steps that a test range can be automatically determined for a code to be tested, a test instruction matched with the test range is searched, a preset text processing model is controlled to generate a test case covering the test range based on the searched test instruction, and the test is executed based on the test case; according to the embodiment of the invention, the automatic degree and accuracy of code testing are improved by automatically determining the testing range, automatically generating the testing case and executing the testing, the testing efficiency is improved to a great extent, and the labor cost is saved.

Description

Code testing method and device
Technical Field
The present invention relates to the field of software development technologies, and in particular, to a code testing method and device.
Background
In software development, as software functions and code amounts increase, test portions for various types of code are also becoming more and more important.
At present, a developer usually creates a corresponding test case according to the code developed by the developer and the requirement analysis, and then the tester executes a corresponding test based on the test case to confirm and debug the code; under the condition of higher software code iteration updating speed, the existing method has the problems of poor testing universality and flexibility, and influences the development efficiency; the problem of code not being tested may also result from manually creating test cases.
Disclosure of Invention
In view of the above, the embodiment of the invention provides a code testing method and device, which can automatically determine a testing range for a code to be tested, search a testing instruction matched with the testing range, and control a preset text processing model to generate a testing case covering the testing range based on the searched testing instruction so as to execute a test based on the testing case; according to the embodiment of the invention, the degree of automation and the accuracy of code testing are improved by automatically determining the testing range, automatically generating the testing case and executing the testing, the testing efficiency is improved to a great extent, and the labor cost is saved.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a code testing method, including: responding to a test request for a code to be tested, and determining a test range of the code to be tested, wherein the test range comprises a difference code of the code to be tested and an original code and call chain information associated with the difference code; searching a test instruction matched with the difference code and the call chain information, and controlling a preset text processing model to generate at least one test case covering the test range by using the searched test instruction; and testing the code to be tested based on the test case.
Optionally, the determining the test range of the code to be tested includes: pulling a first code branch where the code to be tested is located and a second code branch directly or indirectly dependent on the first code branch from a code library where the code to be tested is located; comparing the first code branch and the second code branch to determine the difference code; compiling the first code branch and a main code branch on which the first code branch depends to obtain a compiled code packet; analyzing the compiled code packet to obtain the call chain information of the test object in the code to be tested and the object in the main code branch.
Optionally, the testing the code to be tested based on the test case includes: and sending the test case to an automatic test module, so that the automatic test module executes the code to be tested according to the test case, and outputting a test result aiming at the code to be tested.
Optionally, the code testing method further includes: the following operations are iteratively executed until the test result evaluates that the test coverage meets the preset coverage range: evaluating the test coverage rate of the test case according to the test result; under the condition that the test coverage rate does not meet a preset coverage rate range, optimizing the test instruction, and controlling a preset text processing model by utilizing the optimized test instruction to generate at least one optimized test case covering the test range; and retesting the code to be tested by using the optimized test case.
Optionally, the controlling the preset text processing model by using the found test instruction generates at least one test case covering the test range, and further includes: and determining whether the test object contained in the test case meets the condition of executing the test by using the simulation data, and if so, generating a new test case added with the simulation data for the test object.
Optionally, the controlling the preset text processing model by using the found test instruction generates at least one test case covering the influence range, and further includes: and adding an assertion statement for each test case by using a preset assertion generating algorithm, and capturing a code operation exception when the test is executed based on the test case through the assertion statement.
Optionally, a plurality of types of test tasks are built based on the distributed framework, the test tasks including: processing a test instruction task, a test case generation task and an automatic test execution task; the method further comprises the steps of: scheduling the task of processing the test instruction to determine a test instruction corresponding to the code to be tested; scheduling the test case generation task to control the preset text processing model to generate at least one test case covering the influence range based on the test instruction; and dispatching an automatic test execution task to execute the test case.
Optionally, the code testing method further includes providing a visual test maintenance page to change one or more of the test instruction, the test case, and the test task through the visual test maintenance page; and displaying the test result information through the visual test maintenance page.
In order to achieve the above object, according to a second aspect of the embodiments of the present invention, there is provided a code testing apparatus, comprising: the system comprises a range determining module, a use case generating module and an execution testing module; wherein,
The determining range module is used for responding to a test request for the code to be tested, and determining the test range of the code to be tested, wherein the test range comprises a difference code of the code to be tested and an original code and call chain information associated with the difference code;
The generating case module is used for searching a test instruction matched with the difference code and the call chain information, and controlling a preset text processing model to generate at least one test case covering the test range by using the searched test instruction;
And the execution test module is used for testing the code to be tested based on the test case.
Optionally, the code testing device is configured to determine a testing range of a code to be tested, and includes: pulling a first code branch where the code to be tested is located and a second code branch directly or indirectly dependent on the first code branch from a code library where the code to be tested is located; comparing the first code branch and the second code branch to determine the difference code; compiling the first code branch and a main code branch on which the first code branch depends to obtain a compiled code packet; analyzing the compiled code packet to obtain the call chain information of the test object in the code to be tested and the object in the main code branch.
Optionally, the code testing device is configured to test the code to be tested based on the test case, and includes: and sending the test case to an automatic test module, so that the automatic test module executes the code to be tested according to the test case, and outputting a test result aiming at the code to be tested.
Optionally, the code testing device is further configured to iteratively execute the following operations until the test result evaluates that the test coverage meets the preset coverage range: evaluating the test coverage rate of the test case according to the test result; under the condition that the test coverage rate does not meet a preset coverage rate range, optimizing the test instruction, and controlling a preset text processing model by utilizing the optimized test instruction to generate at least one optimized test case covering the test range; and retesting the code to be tested by using the optimized test case.
Optionally, the code testing device is configured to control a preset text processing model to generate at least one test case covering the test range by using the found test instruction, and further includes: and determining whether the test object contained in the test case meets the condition of executing the test by using the simulation data, and if so, generating a new test case added with the simulation data for the test object.
Optionally, the code testing device is configured to control a preset text processing model to generate at least one test case covering the influence range by using the found test instruction, and further includes: and adding an assertion statement for each test case by using a preset assertion generating algorithm, and capturing a code operation exception when the test is executed based on the test case through the assertion statement.
Optionally, the code testing device is configured to construct multiple types of testing tasks based on the distributed framework, where the testing tasks include: processing a test instruction task, a test case generation task and an automatic test execution task; the method further comprises the steps of: scheduling the task of processing the test instruction to determine a test instruction corresponding to the code to be tested; scheduling the test case generation task to control the preset text processing model to generate at least one test case covering the influence range based on the test instruction; and dispatching an automatic test execution task to execute the test case.
Optionally, the code testing device is further configured to provide a visual test maintenance page, so that one or more of the test instruction, the test case, and the test task are changed through the visual test maintenance page; and displaying the test result information through the visual test maintenance page.
To achieve the above object, according to a third aspect of an embodiment of the present invention, there is provided an electronic device for code testing, including: one or more processors; and a storage means for storing one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the method as described in any of the methods of code testing above.
To achieve the above object, according to a fourth aspect of the embodiments of the present invention, there is provided a computer-readable medium having stored thereon a computer program, characterized in that the program, when executed by a processor, implements a method as described in any one of the above code test methods.
One embodiment of the above invention has the following advantages or benefits: the method comprises the steps that a test range can be automatically determined for a code to be tested, a test instruction matched with the test range is searched, a preset text processing model is controlled to generate a test case covering the test range based on the searched test instruction, and the test is executed based on the test case; according to the embodiment of the invention, the degree of automation and the accuracy of code testing are improved by automatically determining the testing range, automatically generating the testing case and executing the testing, the testing efficiency is improved to a great extent, and the labor cost is saved.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a flow chart of a code testing method according to an embodiment of the present invention;
FIG. 2A is a schematic diagram of a code testing method according to an embodiment of the present invention;
FIG. 2B is a schematic diagram of a structure for determining a test range according to an embodiment of the present invention;
FIG. 3 is a schematic flow chart of generating test cases according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a code testing device according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
fig. 6 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In the technical scheme of the invention, the related processes of collecting, using, storing, sharing, transferring and the like of the personal information of the user accord with the regulations of related laws and regulations, the user needs to be informed and obtain the consent or the authorization of the user, and when the personal information of the user is applicable, the technical processes of de-identification and/or anonymization and/or encryption are performed on the personal information of the user.
As shown in fig. 1, an embodiment of the present invention provides a code testing method, which may include the following steps:
Step S101: and responding to a test request for the code to be tested, and determining a test range of the code to be tested, wherein the test range comprises a difference code of the code to be tested and an original code and call chain information associated with the difference code.
Specifically, the code to be tested is a code changed in the development process, for example, the code is modified, added, deleted and the like, and it can be understood that in the development process, the code change has test necessity due to multi-level and multi-dimensional dependency relationship among the codes so as to overcome the influence caused by the code change. Where the tests for the code may be of various types, such as unit tests, regression tests, etc., the present application is applicable to any type of test. The method for determining the code to be tested comprises the following steps: 1) Code to be tested may be designated by a developer or tester through a visualization page or code management tool; 2) Scanning codes of a code library according to set intervals (such as daily, weekly and the like), automatically judging whether code changes exist according to the modification time of a code file, and determining the changed codes as codes to be tested; 3) And monitoring the condition of code change, and determining the operation with the test code by taking the code change as a trigger condition. Wherein the code to be tested may be attributed to one or more code branches (including information such as code file locations, file directories, etc.) in the code library.
Further, determining a test range of the code to be tested, wherein the test range comprises a difference code of the code to be tested and an original code and call chain information associated with the difference code. The test range (namely, the influence range caused by code change) comprises a difference code generated after the code is changed and the information of the calling chain relation of the code directly or indirectly; namely, the test range comprises the difference code of the code to be tested and the original code and call chain information associated with the difference code; it will be appreciated that in the development process, the code is changed to be continuously iterated, and in the embodiment of the present invention, the original code may refer to a code corresponding to any version of the code to be tested before the change.
Further, in an embodiment of the present invention, a specific method for determining a test range of a code to be tested includes:
1) Pulling a first code branch where the code to be tested is located and a second code branch directly or indirectly dependent on the first code branch from a code library where the code to be tested is located; comparing the first code branch and the second code branch to determine the difference code; for example, based on the git code library, the difference of the latest codes on two branches is compared by using an instruction gitdiff branch1 branch2, and a code file with the difference is determined, wherein branch1 is the first code branch, and branch2 is the second code branch.
2) Compiling the first code branch and a main code branch on which the first code branch depends to obtain a compiled code packet; analyzing the compiled code packet to obtain call chain information of the test object in the code to be tested and the object in the main code branch; for example, based on a code library, pulling a development code branch and a main branch code, compiling and packaging (for example, using a maven command), generating 2 jar packets (namely, compiling the code packets) to generate corresponding branch jar packets for the development branch, and generating a master jar packet by the main branch; further, acquiring a static code calling relation through a class file (namely a class file) obtained after compiling the generated jar package and the code; analyzing jar package files and class files, combining the determined difference codes, calculating detailed differences of code files of all differences, extracting class names and method names in the files according to file dimensions, respectively storing the class names and the method names in the files into an array, further performing traversal codes, writing the class names and the method names in the array into an xml file after traversal is completed, and utilizing the xml file to reflect the calling relation of the class and the method; further, filtering and de-duplication processing is carried out on the content of the xml file through the identification (namely the package name) of the jar package, and the class, the method and the relation are stored in a database; the method comprises the steps of marking a controller by a method, connecting the method relations in series by the code, displaying the relation of a total relation tree of the code engineering in data, receiving parameter information such as class, method, variable and the like through a controllable interface based on the total relation tree to obtain call chain information of the method, including backward call relation, forward call relation and the like, so that a list corresponding to the call chain information is determined and output, and the list comprises the method and method detailed information of a code to be tested, a controller (i.e. a controller) affected by the method, a specific type (such as addition, deletion, modification and the like) modified by the method and a specific statement of a method influence range. In the process of obtaining the Controller information, the method for obtaining the Class object of the Class is to obtain the Class object through layer-by-layer recursion analysis, obtain the path of the Controller Class through engineering static codes, and read and obtain the Controller Class object from the jar package by using a java Class loader.
3) The calling chain information can be obtained through the steps 1) and 2), and comprises various data such as a method, an interface, controller information, a request type, a URL, parameter information, comparison information and the like associated with the code to be tested; further, specific information and the like contained in the acquired test range are stored in a file or a data source to serve as basic data for executing the step of generating the test case later.
The following beneficial effects (1) fully evaluating the test range can be achieved by the step of determining the test range; the method solves the problems that multi-branch codes are combined to a main branch, and the positions of modified files and specific codes cannot be accurately positioned in the prior art, and improves the accuracy and the automation degree of determining the test range. (2) reducing the missing test rate: the problem that a large-scale test resource is required to be put into continuous test in the prior art is solved, the test coverage rate is improved, the missing test rate is reduced, and the labor cost is saved. (3) accurate testing; the method solves the problem that the test range of the test code is inaccurate (the range is too large and the range is too small) in the prior art. The interface cases related to the test range (influence range) can be directly determined, the test cases can be automatically executed, and the test report can be automatically output. (4) The problem of repeated labor is solved, and the testing efficiency is improved.
Step S102: searching a test instruction matched with the difference code and the call chain information, and controlling a preset text processing model to generate at least one test case covering the test range by using the searched test instruction.
Specifically, in the embodiment of the present invention, the test instruction is an instruction (for example, text) for controlling the preset text processing model to generate at least one test case covering the test range, where the control preset text processing model may be AIGC models, AIGC (ARTIFICIAL INTELLIGENCE GENERATED Content) is a generated artificial intelligence model, which is an artificial intelligence technology driven natural language processing tool, and can generate corresponding output information based on patterns and statistical rules seen in the pre-training stage. In an embodiment of the present invention, the model may be used to receive test instructions and correspondingly generate at least one test case covering the test scope.
It can be understood that corresponding test instructions may be preset for different codes to be tested, for example, the test instructions are: collecting the testing range of the latest submitted codes of the function B of the application A, designing an automatic testing case according to the testing range, or generating the testing case for the whole codes, or generating the testing case for the code branch D based on the rule abc, and the like; the invention is not limited to the specific content and format of the test instruction. Further, a worker (for example, a developer or a tester) can edit and maintain the test instruction based on the page provided by the invention, determine the binding relation between the test instruction and the code to be tested, and store the binding relation between the test instruction and the code to be tested. The test cases used by the test code may include various information such as the test code, test step descriptions, and the like.
Further preferably, the controlling the preset text processing model by using the found test instruction generates at least one test case covering the test range, and further includes: and determining whether the test object contained in the test case meets the condition of executing the test by using the simulation data, and if so, generating a new test case added with the simulation data for the test object. Specifically, in the code test phase, if there is a case where the test data source is not provided, the test can be performed by the simulation data, so in a case where it is determined that one or more test cases can perform the test using the simulation data, new test cases to which the simulation data is added are further generated for the test object (e.g., interface, method, etc.). Wherein the simulation data can be determined by using a dynamic generation algorithm by Mock.
Further, the controlling the preset text processing model by using the found test instruction to generate at least one test case covering the influence range further includes: and adding an assertion statement for each test case by using a preset assertion generating algorithm, and capturing a code operation exception when the test is executed based on the test case through the assertion statement. Specifically, an automatic assertion generating algorithm of Mutate tools can be adopted, assertion sentences are added at the tail part of each test case according to the corresponding method, and the content of the test case generated by the preset text processing model is enriched.
Step S103: and testing the code to be tested based on the test case.
Specifically, the information of the test case can be input into the interface of the automatic test module to drive the automatic execution module to execute the test case and output a test result; that is, the testing the code to be tested based on the test case includes: and sending the test case to an automatic test module, so that the automatic test module executes the code to be tested according to the test case, and outputting a test result aiming at the code to be tested.
Further, monitoring and analyzing the obtained test result to evaluate the test coverage rate of the test case by evaluating the test result; therefore, the test instruction and the test case can be optimized in a cyclic and iterative mode, and the condition that the test coverage rate meets the preset coverage rate threshold value is determined. That is, the following operations are iteratively executed until the test result evaluates that the test coverage meets the preset coverage range: evaluating the test coverage rate of the test case according to the test result; under the condition that the test coverage rate does not meet a preset coverage rate range, optimizing the test instruction, and controlling a preset text processing model by utilizing the optimized test instruction to generate at least one optimized test case covering the test range; and retesting the code to be tested by using the optimized test case. The method for optimizing the test instruction comprises the following steps: re-editing the test instruction text, e.g., adding or subtracting or modifying text descriptions; or optimizing test cases, including: regenerating test cases by using the optimized test instructions; or optimizing the running sequence of the test cases; or selecting an optimal test case from a plurality of generated test cases.
As shown in fig. 2A, the embodiment of the invention provides a structural schematic diagram of a code testing method; it comprises the following steps: a plurality of processing modules such as a front end, a business layer, a data layer, a storage layer, an operation environment and the like.
Specifically, the page with the front end can do: test instruction maintenance and display, test case maintenance and display, test result maintenance and display, and test task maintenance and display. That is, a visual test maintenance page is provided to change one or more of the test instructions, the test cases, and the test tasks through the visual test maintenance page; and displaying the test result information through the visual test maintenance page.
Further, the test tasks maintain and demonstrate management associated with the test tasks, in embodiments of the invention, multiple types of test tasks are built based on a distributed framework, including: processing a test instruction task, a test case generation task and an automatic test execution task; further, scheduling test instruction task to determine a test instruction corresponding to the code to be tested; scheduling the test case generation task to control the preset text processing model to generate at least one test case covering the influence range based on the test instruction; and dispatching an automatic test execution task to execute the test case. The efficiency of the test is improved by scheduling multiple tasks. The test tasks are maintained and managed through the pages, so that the task states, suspending/resuming tasks, terminating running tasks and the like can be dynamically modified, and the flexibility of task management is improved by supporting online configuration scheduling task participation and online checking of scheduling results.
The service layer can be used for determining a plurality of services in the test range, the generation of the execution test cases, the management of test tasks, the analysis of test instructions, the management of the test cases, the execution of the test cases, the management of test reports and the management of test logs.
The data layer can be utilized to process test instructions, test cases, test logs, test reports and the like aiming at data required in an automatic test process.
The data processed by the data layer can be stored by a storage layer through a database (such as MySQL, etc.), a data search engine (such as ES, etc.), a cache, etc., and the data is subjected to persistence management.
With the operating environment, the test may be performed under different environments, such as a test environment, a pre-release environment, a production environment, it may be appreciated that different operating environments may have different test emphasis points, in embodiments of the present invention, one or more of the production environment, the pre-release environment, and the test environment may be selected, and maintenance and storage of different environment configuration information may be performed by the front end based on the dimensions of the application, where both the test case and the test execution environment depend on the environment management portion, e.g., where the test case corresponding to the russian environment may be generated and automated test performed in the case where the test environment is selected.
The invention can be applied to automatic testing in the field of software development. The existing test cases and codes are collected and analyzed, the test codes are generated by utilizing AIGC technology, and the test strategy is optimized in real time in the test process, so that the test efficiency and accuracy can be improved, the test cost is reduced, and the method has wide application prospect in the field of software development.
The test efficiency can be improved through the plurality of processing modules, so that the software quality is improved, and the overall development progress is improved.
As shown in fig. 2B, an embodiment of the present invention provides a schematic structural diagram for determining a test range; which includes a call chain analysis engine 201 and a code analysis engine 202;
The method comprises the steps that a calling chain analysis engine and a code analysis engine acquire information of codes to be tested from a code base, the calling chain analysis engine performs analysis and determines calling chain information, and the acquired calling chain information is stored in a data source; the code analysis engine performs the steps of determining the discrepancy code and determining a test entry (e.g., method, interface, etc.) from a data source containing call chain information; and combining the chain analysis engine and the code analysis engine to output a test range so as to execute subsequent automatic test steps according to the test range.
That is, the determining the test range of the code to be tested includes: pulling a first code branch where the code to be tested is located and a second code branch directly or indirectly dependent on the first code branch from a code library where the code to be tested is located; comparing the first code branch and the second code branch to determine the difference code; compiling the first code branch and a main code branch on which the first code branch depends to obtain a compiled code packet; analyzing the compiled code packet to obtain the call chain information of the test object in the code to be tested and the object in the main code branch.
As shown in FIG. 3, an embodiment of the present invention provides a process for generating test cases, which may include the following steps;
Inputting a code to be tested and a matched test instruction into a preset text processing model, and selecting an operation environment (such as a test environment, a production environment and the like) to which a test case belongs;
step S301: and generating a basic object contained in the test case. The base object includes an application object (e.g., information such as a base type of the test object) to which the test case corresponds.
Step S302: and generating a method contained in the test case. The method comprises method identification, parameter entering information and the like.
Step S303: an assertion statement is generated.
Step S304: a test case set is generated.
Step S305: and obtaining a test case output test result.
Step S306: code coverage is analyzed.
Step S307: the test cases are optimized and integrated into a test case set.
The descriptions of step S304 to step S307 are: the following operations are iteratively executed until the test result evaluates that the test coverage meets the preset coverage range: evaluating the test coverage rate of the test case according to the test result; optimizing the test instruction under the condition that the test coverage rate does not meet a preset coverage rate range, and controlling a preset text processing model by utilizing the optimized test instruction to generate at least one optimized test case covering the test range; and retesting the code to be tested by using the optimized test case.
As shown in fig. 4, an embodiment of the present invention provides a test apparatus 400, including a determining range module 401, a generating use case module 402, and an executing test module 403; wherein,
The determining range module 401 is configured to determine a testing range of a code to be tested in response to a testing request for the code to be tested, where the testing range includes a difference code between the code to be tested and an original code and call chain information associated with the difference code;
The generating case module 402 is configured to search a test instruction matched with the difference code and the call chain information, and control a preset text processing model to generate at least one test case covering the test range by using the searched test instruction;
The execution test module 403 is configured to test the code to be tested based on the test case.
The embodiment of the invention also provides an electronic device for code testing, which comprises: one or more processors; and a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the method provided by any of the embodiments described above.
The embodiment of the invention also provides a computer readable medium, on which a computer program is stored, which when executed by a processor implements the method provided by any of the above embodiments.
Fig. 5 illustrates an exemplary system architecture 500 to which the code testing method or code testing apparatus of embodiments of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 is used as a medium to provide communication links between the terminal devices 501, 502, 503 and the server 505. The network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 505 via the network 504 using the terminal devices 501, 502, 503 to receive or send messages or the like. Various client applications such as an electronic mall client application, a web browser application, a search class application, an instant messaging tool, a mailbox client, and the like may be installed on the terminal devices 501, 502, 503.
The terminal devices 501, 502, 503 may be a variety of electronic devices having a display screen and supporting a variety of client applications, including but not limited to smartphones, tablet computers, laptop and desktop computers, and the like.
The server 505 may be a server providing various services, such as a background management server providing support for client applications used by the user with the terminal devices 501, 502, 503. The background management server can process the received code test request and feed back the test result to the terminal equipment.
It should be noted that, the code testing method provided in the embodiment of the present invention is generally executed by the server 505, and accordingly, the code testing device is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, there is illustrated a schematic diagram of a computer system 600 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 6 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other through a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, mouse, etc.; an output portion 607 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The drive 610 is also connected to the I/O interface 605 as needed. Removable media 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed as needed on drive 610 so that a computer program read therefrom is installed as needed into storage section 608.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication portion 609, and/or installed from the removable medium 611. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 601.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules and/or units involved in the embodiments of the present invention may be implemented in software, or may be implemented in hardware. The described modules and/or units may also be provided in a processor, e.g., may be described as: a processor includes a determine scope module, a generate use case module, and an execute test module. The names of these modules do not constitute a limitation on the module itself in some cases, and for example, the determine scope module may also be described as "determine difference code and invoke chain information module".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: responding to a test request for a code to be tested, and determining a test range of the code to be tested, wherein the test range comprises a difference code of the code to be tested and an original code and call chain information associated with the difference code; searching a test instruction matched with the difference code and the call chain information, and controlling a preset text processing model to generate at least one test case covering the test range by using the searched test instruction; and testing the code to be tested based on the test case.
According to the embodiment of the invention, the test range can be automatically determined for the code to be tested, the test instruction matched with the test range is searched, and the preset text processing model is controlled to generate the test case covering the test range based on the searched test instruction, so that the test is executed based on the test case; according to the embodiment of the invention, the degree of automation and the accuracy of code testing are improved by automatically determining the testing range, automatically generating the testing case and executing the testing, the testing efficiency is improved to a great extent, and the labor cost is saved.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (11)

1. A code testing method, comprising:
Responding to a test request for a code to be tested, and determining a test range of the code to be tested, wherein the test range comprises a difference code of the code to be tested and an original code and call chain information associated with the difference code;
searching a test instruction matched with the difference code and the call chain information, and controlling a preset text processing model to generate at least one test case covering the test range by using the searched test instruction;
and testing the code to be tested based on the test case.
2. The method of claim 1, wherein the step of determining the position of the substrate comprises,
The determining the test range of the code to be tested comprises the following steps:
Pulling a first code branch where the code to be tested is located and a second code branch directly or indirectly dependent on the first code branch from a code library where the code to be tested is located;
comparing the first code branch and the second code branch to determine the difference code;
Compiling the first code branch and a main code branch on which the first code branch depends to obtain a compiled code packet;
analyzing the compiled code packet to obtain the call chain information of the test object in the code to be tested and the object in the main code branch.
3. The method of claim 1, wherein the step of determining the position of the substrate comprises,
The testing the code to be tested based on the test case comprises the following steps:
And sending the test case to an automatic test module, so that the automatic test module executes the code to be tested according to the test case, and outputting a test result aiming at the code to be tested.
4. A method as claimed in claim 3, further comprising:
the following operations are iteratively executed until the test result evaluates that the test coverage meets the preset coverage range:
evaluating the test coverage rate of the test case according to the test result;
Under the condition that the test coverage rate does not meet a preset coverage rate range, optimizing the test instruction, and controlling a preset text processing model by utilizing the optimized test instruction to generate at least one optimized test case covering the test range;
and retesting the code to be tested by using the optimized test case.
5. The method of claim 2, wherein the step of determining the position of the substrate comprises,
The method for generating the test case by using the searched test instruction to control a preset text processing model to generate at least one test case covering the test range further comprises the following steps:
and determining whether the test object contained in the test case meets the condition of executing the test by using the simulation data, and if so, generating a new test case added with the simulation data for the test object.
6. The method of claim 2, wherein the step of determining the position of the substrate comprises,
The method for generating the test case by using the searched test instruction to control a preset text processing model to generate at least one test case covering the influence range further comprises the following steps:
And adding an assertion statement for each test case by using a preset assertion generating algorithm, and capturing a code operation exception when the test is executed based on the test case through the assertion statement.
7. The method of claim 1, wherein the step of determining the position of the substrate comprises,
Constructing a plurality of types of test tasks based on a distributed framework, wherein the test tasks comprise: processing a test instruction task, a test case generation task and an automatic test execution task;
The method further comprises the steps of:
scheduling the task of processing the test instruction to determine a test instruction corresponding to the code to be tested;
scheduling the test case generation task to control the preset text processing model to generate at least one test case covering the influence range based on the test instruction;
And dispatching an automatic test execution task to execute the test case.
8. The method according to any one of claims 1 to 6, wherein,
A visual test maintenance page is provided,
Changing one or more of the test instruction, the test case and the test task through the visual test maintenance page;
And
And displaying the test result information through the visual test maintenance page.
9. A test device, comprising: the system comprises a range determining module, a use case generating module and an execution testing module; wherein,
The determining range module is used for responding to a test request for the code to be tested, and determining the test range of the code to be tested, wherein the test range comprises a difference code of the code to be tested and an original code and call chain information associated with the difference code;
The generating case module is used for searching a test instruction matched with the difference code and the call chain information, and controlling a preset text processing model to generate at least one test case covering the test range by using the searched test instruction;
And the execution test module is used for testing the code to be tested based on the test case.
10. An electronic device, comprising:
one or more processors;
Storage means for storing one or more programs,
When executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-8.
11. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-8.
CN202410064259.6A 2024-01-16 2024-01-16 Code testing method and device Pending CN117891732A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410064259.6A CN117891732A (en) 2024-01-16 2024-01-16 Code testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410064259.6A CN117891732A (en) 2024-01-16 2024-01-16 Code testing method and device

Publications (1)

Publication Number Publication Date
CN117891732A true CN117891732A (en) 2024-04-16

Family

ID=90643914

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410064259.6A Pending CN117891732A (en) 2024-01-16 2024-01-16 Code testing method and device

Country Status (1)

Country Link
CN (1) CN117891732A (en)

Similar Documents

Publication Publication Date Title
US20180253296A1 (en) Software kit release management
US9811325B2 (en) Systems and methods for dynamically replacing code objects for code pushdown
CN108845940B (en) Enterprise-level information system automatic function testing method and system
US11593342B2 (en) Systems and methods for database orientation transformation
EP2557499A1 (en) A system and method for automatic impact variable analysis and field expansion in mainframe systems
CN111125064B (en) Method and device for generating database schema definition statement
CN113326247B (en) Cloud data migration method and device and electronic equipment
EP4195108A1 (en) Method and apparatus for generating and applying deep learning model based on deep learning framework
CN114138674A (en) Automatic testing method and device and computer equipment
CN115543781A (en) Method and interactive system for automatically verifying automobile software model
CN115509522A (en) Interface arranging method and system for low-code scene and electronic equipment
CN114217848A (en) Dependency relationship processing method and device, electronic equipment and computer storage medium
CN113377342B (en) Project construction method and device, electronic equipment and storage medium
CN113032257A (en) Automatic test method, device, computer system and readable storage medium
CN117235527A (en) End-to-end containerized big data model construction method, device, equipment and medium
US20230153081A1 (en) Methods and systems for correlating source code commitments and model result records during model development
CN117891732A (en) Code testing method and device
CN113448869B (en) Method and device for generating test case, electronic equipment and computer readable medium
CN115454826A (en) Regression testing method, device, electronic equipment and storage medium
CN114579120A (en) Application code processing method and device, electronic equipment and storage medium
CN115291928A (en) Task automatic integration method and device of multiple technology stacks and electronic equipment
CN111367791B (en) Method, device, medium and electronic equipment for generating test case
CN113885841A (en) Script generation method and device, electronic equipment and readable medium
CN113051479A (en) File processing and recommendation information generation method, device, equipment and storage medium
CN113032256A (en) Automatic test method, device, computer system and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination