A test case generation method, device, electronic device and storage medium
Through the automatic test case generation framework, the code change records are obtained based on the distributed version control system, and the test cases are generated and updated. The time-consuming and labor-consuming problem of writing and maintaining test cases in the existing technology is solved, and the automation and efficiency of test cases are achieved.
Patent Information
- Application Number
- CN202411964691.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-04
AI Technical Summary
In the prior art, the writing and maintenance of test cases during software development and maintenance requires a lot of manpower and time. As the software is frequently iterative and updated, manual analysis code changes are prone to errors, resulting in incomplete and inaccurate testing.
By obtaining the historical submission record of the code file based on the distributed version control system, determining the object code file for the test case to be generated, and comparing the object code file with the reference code file to determine the change file. Generate target test cases corresponding to target code files through the automatic test case generation framework based on the type of the change file and the reference test cases.
Automatic generation and update of test cases is realized, timeliness and effectiveness of test cases is ensured, software development efficiency is greatly improved, and software maintenance costs are reduced.
Smart Images

Figure CN119759790A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a test case generation method, device, electronic device and storage medium. Background Art
[0002] During software development and maintenance, in order to verify the software running results and ensure the correctness of the software in the continuous iteration process, programmers need to write a large number of test cases for testing. Traditional test cases mainly rely on testers to manually write test cases based on software requirements documents and functional design documents. When the software is updated, testers need to manually analyze the code changes and manually modify the relevant test cases. Therefore, the writing and maintenance of test cases requires a lot of manpower and time. With the frequent iteration and update of software, manual analysis of code changes is more prone to errors and missing key change points. It is difficult to manually update test cases, which can easily lead to incomplete and inaccurate testing. The expected results of the test cases are inconsistent with the actual code impact, affecting the quality of the software and making it difficult to ensure the timeliness and effectiveness of test case generation. Summary of the invention
[0003] The present disclosure provides a test case generation method, device, electronic device and storage medium to at least solve the above technical problems existing in the prior art.
[0004] According to a first aspect of the present disclosure, a method for generating a test case is provided, the method comprising: obtaining a historical submission record of a code file based on a distributed version control system; determining a target code file for a test case to be generated according to a version number of the code file; comparing the target code file with a reference code file to determine a changed file; and generating a target test case corresponding to the target code file through an automatic test case generation framework according to a type of the changed file and a reference test case corresponding to the reference code.
[0005] In one possible implementation, the type of the change file is a new code file, and the reference test case corresponding to the reference code and the type of the change file are used to generate a target test case corresponding to the target code file through an automatic test case generation framework, including: parsing the new code file through a code analysis tool to generate a first abstract syntax tree of the code contained in the new code file; analyzing the first abstract syntax tree to determine key elements in the code; generating a first sub-test case corresponding to the new code file through an automatic test case generation framework based on the first abstract syntax tree and the key elements; combining the first sub-test case with the reference test case to obtain a target test case corresponding to the target code file.
[0006] In one possible implementation, the type of the change file is an update code file, and the reference test case corresponding to the reference code and the type of the change file are used to generate a target test case corresponding to the target code file through an automatic test case generation framework, including: performing code difference analysis on the update code file through a source code difference analyzer to determine key change points; parsing the update code file to generate a second abstract syntax tree for the code contained in the update code file; determining an initial sub-test case corresponding to the update code file based on the reference test case; updating the initial sub-test case through an automatic test case generation framework according to the second abstract syntax tree and the key change points to obtain a second sub-test case corresponding to the update code file; replacing the initial sub-test case with the second sub-test case to generate a target test case corresponding to the target file code.
[0007] In one possible implementation, the type of the change file is a deletion code file, and the target test case corresponding to the target code file is generated through an automatic test case generation framework based on the type of the change file and the reference test case corresponding to the reference code, including: determining a third sub-test case corresponding to the deletion code file from the reference test case; deleting the third sub-test case from the reference test case to obtain a target test case corresponding to the target file code.
[0008] In one possible implementation, the method further includes: analyzing the abstract syntax tree of the target code file and the target test case to generate a test case report.
[0009] According to a second aspect of the present disclosure, a test case generation device is provided, the device comprising: an acquisition module for acquiring historical submission records of a code file based on a distributed version control system; a determination module for determining a target code file for a test case to be generated according to a version number of the code file; a comparison module for comparing the target code file with a reference code file to determine a changed file; and a generation module for generating a target test case corresponding to the target code file through an automatic test case generation framework according to a type of the changed file and a reference test case corresponding to the reference code.
[0010] In one possible implementation, the type of the changed file is a new code file, and the generation module includes: a first generation sub-module, used to parse the new code file through a code analysis tool to generate a first abstract syntax tree of the code contained in the new code file; a first analysis sub-module, used to analyze the first abstract syntax tree to determine the key elements in the code; a second generation sub-module, used to generate a first sub-test case corresponding to the new code file through an automatic test case generation framework according to the first abstract syntax tree and the key elements; a first determination sub-module, used to combine the first sub-test case with the reference test case to obtain a target test case corresponding to the target code file.
[0011] In one possible implementation, the type of the change file is an update code file, and the generation module includes: a second analysis submodule, used to perform code difference analysis on the update code file through a source code difference analyzer to determine key change points; a third generation submodule, used to parse the update code file to generate a second abstract syntax tree of the code contained in the update code file; a second determination submodule, used to determine an initial sub-test case corresponding to the update code file based on the reference test case; the second determination submodule is also used to update the initial sub-test case through an automatic test case generation framework according to the second abstract syntax tree and the key change points to obtain a second sub-test case corresponding to the update code file; the third determination submodule is used to replace the initial sub-test case with the second sub-test case to generate a target test case corresponding to the target file code.
[0012] In one possible implementation, the type of the change file is a deletion code file, and the generation module includes: a fourth determination submodule, used to determine a third sub-test case corresponding to the deletion code file from the reference test case; the fourth determination submodule is also used to delete the third sub-test case from the reference test case to obtain a target test case corresponding to the target file code.
[0013] In one possible implementation manner, the device further includes: an analysis module, configured to analyze the abstract syntax tree of the target code file and the target test case to generate a test case report.
[0014] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the present disclosure.
[0018] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method described in the present disclosure.
[0019] The disclosed test case generation method, device, electronic device and storage medium first obtain the historical submission record of the code file based on the distributed version control system, determine the target code file of the test case to be generated according to the version number of the code file, compare the target code file with the reference code file that already has the reference test case, determine the changed file, and generate the target test case corresponding to the target code file through the automatic test case generation framework according to the type of the changed file and the reference test case. By applying this method, the test case can be automatically generated through the automatic test case generation framework, and when the code is updated, the test case can be automatically updated based on the change of the code, which can ensure the timeliness and effectiveness of the test case, greatly improve the software development efficiency, and reduce the software maintenance cost.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present disclosure are shown in an exemplary and non-limiting manner, in which:
[0022] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.
[0023] Figure 1 The following is a schematic diagram showing the implementation process of a method for generating a test case according to an embodiment of the present disclosure. Figure 1 ;
[0024] Figure 2 The following is a schematic diagram showing the implementation process of a method for generating a test case according to an embodiment of the present disclosure. Figure 2 ;
[0025] Figure 3 The following is a schematic diagram showing the implementation process of a method for generating a test case according to an embodiment of the present disclosure. Figure 3 ;
[0026] Figure 4A module schematic diagram of a test case generation device according to an embodiment of the present disclosure is shown;
[0027] Figure 5 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0028] In order to make the purpose, features, and advantages of the present disclosure more obvious and easy to understand, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0029] Figure 1 The following is a schematic diagram showing the implementation process of a method for generating a test case according to an embodiment of the present disclosure. Figure 1 .
[0030] See also Figure 1 According to a first aspect of an embodiment of the present disclosure, a method for generating a test case is provided, the method comprising:
[0031] Step 101, obtaining historical submission records of code files based on a distributed version control system;
[0032] Step 102, determining the target code file of the test case to be generated according to the version number of the code file;
[0033] Step 103, comparing the target code file with the reference code file to determine the changed file;
[0034] Step 104 , generating a target test case corresponding to the target code file through an automatic test case generation framework according to the type of the changed file and the reference test case corresponding to the reference code.
[0035] This application first obtains the historical submission record of the code file based on the distributed version control system, which is Git. Git encourages developers to create and merge branches. A branch is an independent path in the code base, allowing developers to develop or experiment with new features without interfering with the main line. Once the development is completed, the branch can be merged back to the main line. Git records changes in the project through submissions. Each submission saves the state of the project at a certain moment and records the version number corresponding to the project. Therefore, this application can obtain the historical submission record of the code file corresponding to the project based on Git, and determine the code file of the test case to be generated as the target code file based on the version number of the code file displayed in the historical submission record.
[0036] Determine a reference code file, which has generated a corresponding reference test case. Usually, a code file adjacent to the target code file that has generated a corresponding test case is selected as the reference code file, because the code changes in the adjacent code file are relatively small compared to the target code file, which facilitates faster generation of target test cases corresponding to the target code file. Compare the target code file with the reference code file to obtain a comparison result, and determine the change file based on the comparison result. The change file represents the file in which the target code file has changed relative to the reference code file. Code changes usually include three situations: addition, deletion, and modification. Therefore, the types of change files include newly added code files, deleted code files, and changed code files. For the change file, the corresponding sub-test case can be generated through the automatic test case generation framework. Finally, according to the type of the change file, the sub-test case corresponding to the change file is combined with the reference test case corresponding to the reference code file to obtain the target test case corresponding to the target code file.
[0037] It is understandable that in order to further improve development efficiency, after obtaining the change files, the change files can be initially filtered to exclude non-code files such as text files and configuration files, and the code files can be used as the final change files.
[0038] This application first obtains the historical submission record of the code file based on the distributed version control system, determines the target code file of the test case to be generated according to the version number of the code file, compares the target code file with the reference code file that already has a reference test case, determines the changed file, and generates the target test case corresponding to the target code file through the automatic test case generation framework according to the type of the changed file and the reference test case. Applying this method, test cases can be automatically generated through the automatic test case generation framework. When the code is updated, the test cases are automatically updated based on the changes in the code, which can ensure the timeliness and effectiveness of the test cases, greatly improve the software development efficiency, and reduce the software maintenance cost.
[0039] In one possible implementation, Figure 2 As shown, the type of the changed file is a newly added code file. According to the type of the changed file and the reference test case corresponding to the reference code, a target test case corresponding to the target code file is generated through an automatic test case generation framework, including:
[0040] Step 201, parsing the newly added code file by a code analysis tool to generate a first abstract syntax tree of the code included in the newly added code file;
[0041] Step 202, analyzing the first abstract syntax tree to determine key elements in the code;
[0042] Step 203, generating a first sub-test case corresponding to the newly added code file through an automatic test case generation framework according to the first abstract syntax tree and the key elements;
[0043] Step 204: Combine the first sub-test case with the reference test case to obtain a target test case corresponding to the target code file.
[0044] When the type of the changed file is a new code file, it indicates that the code in the new code file is the code that the target code file adds compared to the reference code file. The code in the new code file is parsed through a code analysis tool such as Eclipse JDT to generate a first abstract syntax tree corresponding to the code in the new code file. The first abstract syntax tree is analyzed through static analysis technology to identify key elements in the code, which include functions, methods, variables, conditional branches, etc. in the code. According to the first abstract syntax tree and the identified key elements, a first sub-test case corresponding to the new code file is generated through an automatic test case generation framework, and the first sub-test case is combined with the reference test case corresponding to the reference code file to obtain a target test case corresponding to the target code file. Finally, the generated first abstract syntax tree, the first sub-test case, and the association relationship with the new code file and the target code file are stored.
[0045] In one possible implementation, Figure 3 As shown, the type of the changed file is an updated code file. According to the type of the changed file and the reference test case corresponding to the reference code, a target test case corresponding to the target code file is generated through an automatic test case generation framework, including:
[0046] Step 301, performing code difference analysis on the updated code file through a source code difference analyzer to determine key change points;
[0047] Step 302, parsing the update code file to generate a second abstract syntax tree of the code included in the update code file;
[0048] Step 303, determining an initial sub-test case corresponding to the updated code file based on the reference test case;
[0049] Step 304, updating the initial sub-test case through the automatic test case generation framework according to the second abstract syntax tree and the key change points, and obtaining a second sub-test case corresponding to the updated code file;
[0050] Step 305: Replace the initial sub-test case with the second sub-test case to generate a target test case corresponding to the target file code.
[0051] When the type of the changed file is an updated code file, it indicates that the code in the updated code file is the code that causes differences between the target code file and the reference code file. For the updated code file, first use the source code difference analyzer ChangeDistiller to perform a difference analysis on the code in the updated code file to determine the code and corresponding positions that cause differences between the target code file and the reference code file, and determine the code that causes differences between the target code file and the reference code file as key change points. The positions where functions, methods, variables or conditional branches change can be determined as key change points. ChangeDistiller is a tree-difference-based tool that can identify specific changes in the code based on the old and new codes, such as identifying the addition, deletion, and modification of classes; the addition, deletion, and modification of methods; the addition, deletion, and modification of code lines; the addition, deletion, and modification of comments; the movement of code blocks and the positions of movement, etc.
[0052] Similarly, a code analysis tool is used to parse the code in the updated code file to generate a second abstract syntax tree corresponding to the code in the updated code file. The initial sub-test case corresponding to the changed code file portion is determined from the reference test case, and the initial sub-test case is the test case corresponding to the code before the change. The initial sub-test case is updated through the automatic test case generation framework according to the second abstract syntax tree and the identified key change points to obtain a second sub-test case corresponding to the changed code file. Specifically, if the threshold of a condition judgment in the target code file represented by the updated code file has changed compared to the reference code file, when the initial sub-test case is updated through the automatic test case generation framework, the input value in the corresponding initial sub-test case will be adjusted according to the new threshold, and the expected output result will also be updated according to the new logic; for the newly added code logic, a new test case method is generated, and for the deleted code logic, the test case method that is no longer used is deleted.
[0053] The generated second sub-test case is used to replace the initial sub-test case in the reference test case, so as to obtain the target test case corresponding to the target code file. At the same time, the database is updated based on the updated code file and the corresponding second abstract syntax tree and the second sub-test case.
[0054] In one possible implementation mode, the type of the changed file is a deletion code file, and a target test case corresponding to the target code file is generated through an automatic test case generation framework based on the type of the changed file and the reference test case corresponding to the reference code, including: determining a third sub-test case corresponding to the deletion code file from the reference test case; deleting the third sub-test case from the reference test case to obtain a target test case corresponding to the target file code.
[0055] When the type of the changed file is a deleted code file, it indicates that the code in the deleted code file is a file deleted by the reference code file, so the third sub-test case corresponding to the part of the code is determined from the reference test case, and the test case obtained after deleting the third sub-test case from the reference test case is the target test case corresponding to the target code file. Similarly, the abstract syntax tree corresponding to the deleted code file, the third sub-test case and the association relationship with the deleted code are deleted from the database.
[0056] In one possible implementation, the method further includes: analyzing the abstract syntax tree of the target code file and the target test case to generate a test case report.
[0057] The changed parts of the target code file compared to the reference code file can be highlighted so that users can more intuitively perceive the changes. The abstract syntax tree and target test cases of the target code file are analyzed to generate a test case report. The analysis content may include the analysis of the update of the abstract syntax tree, the analysis of the update of the target test cases, the analysis of the test coverage, the analysis of the test results, etc. A test case report is generated based on the corresponding analysis results.
[0058] A test case generation method of the present application can be seamlessly embedded in the continuous integration framework of modern software companies such as Jenkins, GitLab CI, etc., and the trigger mechanism is set by using the hook and other mechanisms of the continuous integration framework. During the software development and maintenance process, the programmer updates the code of the project. When it is detected that the new code is submitted to the local or administrator-set code repository, the test case generation method can be automatically triggered to scan and run the new code to generate test cases corresponding to the new code. This can promote the automation and standardization of the software development process, further improve the team's development efficiency, and reduce the maintenance cost of the software.
[0059] Figure 4 A module schematic diagram of a test case generation device according to an embodiment of the present disclosure is shown.
[0060] See also Figure 4 According to the second aspect of the present disclosure, a test case generation device is provided, the device comprising: an acquisition module 401, used to acquire the historical submission record of the code file based on the distributed version control system; a determination module 402, used to determine the target code file to generate the test case according to the version number of the code file; a comparison module 403, used to compare the target code file with the reference code file to determine the changed file; a generation module 404, used to generate the target test case corresponding to the target code file through an automatic test case generation framework according to the type of the changed file and the reference test case corresponding to the reference code.
[0061] In one possible implementation, the type of the changed file is a new code file, and the generation module 404 includes: a first generation sub-module 4041, which is used to parse the new code file through a code analysis tool to generate a first abstract syntax tree of the code contained in the new code file; a first analysis sub-module 4042, which is used to analyze the first abstract syntax tree to determine the key elements in the code; a second generation sub-module 4043, which is used to generate a first sub-test case corresponding to the new code file through an automatic test case generation framework according to the first abstract syntax tree and the key elements; a first determination sub-module 4044, which is used to combine the first sub-test case with the reference test case to obtain a target test case corresponding to the target code file.
[0062] In one possible implementation, the type of the changed file is an update code file, and the generation module 404 includes: a second analysis submodule 4045, which is used to perform code difference analysis on the update code file through a source code difference analyzer to determine key change points; a third generation submodule 4046, which is used to parse the update code file and generate a second abstract syntax tree of the code contained in the update code file; a second determination submodule 4047, which is used to determine the initial sub-test case corresponding to the update code file based on the reference test case; the second determination submodule 4047 is also used to update the initial sub-test case through an automatic test case generation framework according to the second abstract syntax tree and key change points to obtain a second sub-test case corresponding to the update code file; the third determination submodule 4048 is used to replace the initial sub-test case with the second sub-test case to generate a target test case corresponding to the target file code.
[0063] In one embodiment, the type of the changed file is a deletion code file, and the generation module 404 includes: a fourth determination submodule 4049, used to determine the third sub-test case corresponding to the deletion code file from the reference test case; the fourth determination submodule 4049 is also used to delete the third sub-test case from the reference test case to obtain a target test case corresponding to the target file code.
[0064] In one possible implementation, the device further includes: an analysis module 405, configured to analyze the abstract syntax tree of the target code file and the target test case, and generate a test case report.
[0065] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
[0066] Figure 5A schematic block diagram of an example electronic device 800 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0067] like Figure 5 As shown, the device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0068] A number of components in the device 500 are connected to the I / O interface 505, including: an input unit 506, such as a keyboard, a mouse, etc.; an output unit 507, such as various types of displays, speakers, etc.; a storage unit 508, such as a disk, an optical disk, etc.; and a communication unit 509, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 509 allows the device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0069] The computing unit 501 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 501 performs the various methods and processes described above, such as a method for generating a test case. For example, in some embodiments, a method for generating a test case may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of a method for generating a test case described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform a method for generating a test case by any other appropriate means (e.g., by means of firmware).
[0070] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0071] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0072] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0073] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0074] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0075] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0076] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0077] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0078] The above is only a specific embodiment of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for generating a test case, characterized in that: The method comprises: Obtain historical submission records of code files based on distributed version control systems; Determine the target code file for the test case to be generated according to the version number of the code file; Compare the target code file with the reference code file to determine the changed file; A target test case corresponding to the target code file is generated through an automatic test case generation framework according to the type of the changed file and the reference test case corresponding to the reference code.
2. The method according to claim 1, characterized in that: The type of the changed file is a newly added code file, and the generating a target test case corresponding to the target code file through an automatic test case generation framework according to the type of the changed file and the reference test case corresponding to the reference code includes: Parsing the newly added code file by a code analysis tool to generate a first abstract syntax tree of the code included in the newly added code file; Analyze the first abstract syntax tree to determine key elements in the code; Generate a first sub-test case corresponding to the newly added code file through an automatic test case generation framework according to the first abstract syntax tree and the key elements; The first sub-test case is combined with the reference test case to obtain a target test case corresponding to the target code file.
3. The method according to claim 1, characterized in that The type of the change file is an update code file, and the generating a target test case corresponding to the target code file through an automatic test case generation framework according to the type of the change file and the reference test case corresponding to the reference code includes: Perform code difference analysis on the updated code file by using a source code difference analyzer to determine key change points; Parsing the update code file to generate a second abstract syntax tree of the code contained in the update code file; Determining an initial sub-test case corresponding to the updated code file based on the reference test case; The initial sub-test case is updated through an automatic test case generation framework according to the second abstract syntax tree and the key change point to obtain a second sub-test case corresponding to the updated code file; The initial sub-test case is replaced by the second sub-test case to generate a target test case corresponding to the target code file.
4. The method according to claim 1, characterized in that: The type of the changed file is a deleted code file, and the generating a target test case corresponding to the target code file through an automatic test case generation framework according to the type of the changed file and the reference test case corresponding to the reference code includes: Determine a third sub-test case corresponding to the deleted code file from the reference test case; The third sub-test case is deleted from the reference test case to obtain a target test case corresponding to the target file code.
5. The method according to claim 1, characterized in that The method further comprises: The abstract syntax tree of the target code file and the target test case are analyzed to generate a test case report.
6. A test case generation device, characterized in that: The device comprises: An acquisition module is used to obtain historical submission records of code files based on a distributed version control system; A determination module, used to determine the target code file of the test case to be generated according to the version number of the code file; A comparison module, used to compare the target code file with the reference code file to determine the changed file; A generation module is used to generate a target test case corresponding to the target code file through an automatic test case generation framework according to the type of the change file and the reference test case corresponding to the reference code.
7. The device according to claim 6, characterized in that The type of the changed file is a newly added code file, and the generation module includes: A first generating submodule, configured to parse the newly added code file by using a code analysis tool to generate a first abstract syntax tree of the code included in the newly added code file; A first analysis submodule, used to analyze the first abstract syntax tree to determine key elements in the code; A second generating submodule, configured to generate a first sub-test case corresponding to the newly added code file through an automatic test case generation framework according to the first abstract syntax tree and the key elements; The first determination submodule is used to combine the first sub-test case with the reference test case to obtain a target test case corresponding to the target code file.
8. The device according to claim 6, characterized in that The type of the change file is an update code file, and the generation module includes: A second analysis submodule is used to perform code difference analysis on the update code file through a source code difference analyzer to determine key change points; A third generating submodule is used to parse the update code file and generate a second abstract syntax tree of the code included in the update code file; A second determination submodule, configured to determine an initial sub-test case corresponding to the updated code file based on the reference test case; The second determination submodule is further used to update the initial sub-test case through an automatic test case generation framework according to the second abstract syntax tree and the key change point to obtain a second sub-test case corresponding to the updated code file; The third determination submodule is used to replace the initial sub-test case with the second sub-test case to generate a target test case corresponding to the target file code.
9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 5.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-5.