Test code generation method and device, equipment, storage medium and program product
By generating test code, software security problems caused by the diversity of test code frameworks in the prior art are solved, and software security and testing efficiency are improved.
Patent Information
- Application Number
- CN202411373716.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-09-29
AI Technical Summary
Before software functions are updated or launched, when testing software code through unit testing in the existing technology, developers need to build different code testing frameworks, resulting in an increase in the possibility of vulnerabilities in the test code and reducing the security of the software .
By obtaining the software method functions to be tested in the test data packet, obtaining and modifying the implementation methods of the target method functions according to the method function identification and implementation methods entered by the user, generating test codes, avoiding the introduction of other test frameworks, thereby reducing the possibility of security vulnerabilities sex.
Improves the security of the software, avoids the risk of vulnerabilities caused by the increase in test code, simplifies the testing process, and reduces the difficulty of user operations.
Smart Images

Figure CN119002929A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of big data technology, and in particular, relates to a method, device, equipment, storage medium and program product for generating test code. Background Art
[0002] Before updating software functions or launching the software, the software code needs to be tested. Currently, unit testing is used to test part of the software code, thereby reducing testing costs.
[0003] However, when building the test code, developers need to write the resource code and complete test code of the external resources used by the method function to be tested, and build a complete code test framework. In this way, different code test frameworks need to be built for different method functions, and finally the test code written by the developer will be inserted into the software's online data package. Therefore, as the test code increases, the possibility of vulnerabilities in the test code increases, reducing the security of the software. Summary of the invention
[0004] The embodiments of the present application provide a method, apparatus, device, storage medium and program product for generating test codes, which can improve the security of software.
[0005] In a first aspect, an embodiment of the present application provides a method for generating test code, comprising:
[0006] Acquire a test data packet, wherein the test data packet includes method functions in the software to be tested;
[0007] In response to a user input, obtaining a method function identifier to be tested and an implementation method corresponding to the method function identifier to be tested, wherein the implementation method is used to represent a method for testing the method function to be tested corresponding to the method function identifier to be tested;
[0008] According to the method function identifier to be tested, obtaining a target method function corresponding to the method function identifier to be tested in the test data packet;
[0009] The implementation mode corresponding to the target method function is modified to the implementation mode corresponding to the method function identifier to be tested, and the test code is obtained.
[0010] In a possible implementation, acquiring, in the test data packet, a target method function corresponding to the method function identifier to be tested, includes:
[0011] Decompressing the test data packet to obtain a bytecode file, wherein the bytecode file includes an access path to the test file;
[0012] Acquire the test file through the access path of the test file;
[0013] Parse the test file to obtain the method function corresponding to the test file;
[0014] The target method function corresponding to the method function identifier to be tested is obtained from the method function corresponding to the test file.
[0015] In a possible implementation, after modifying the implementation corresponding to the target method function to the implementation corresponding to the method function identifier to be tested to obtain the test code, the method further includes:
[0016] Run the test code and send a call request to the baffle server according to the modified implementation method;
[0017] Receive a return value returned by the baffle server;
[0018] A test result of the target method function is determined based on the return value.
[0019] In a possible implementation, determining the test result of the target method function based on the return value includes:
[0020] Convert the data format of the return value according to a preset format conversion process to obtain a target format return value;
[0021] The test result of the target method function is determined according to the target return value.
[0022] In a possible implementation manner, before receiving the return value returned by the baffle server, the method further includes:
[0023] The return value corresponding to the method function to be tested is configured in the baffle server according to the implementation mode corresponding to the method function to be tested.
[0024] In a possible implementation manner, before obtaining the function identifier of the method to be tested and the implementation manner corresponding to the function identifier of the method to be tested in response to the user's input, the method further includes:
[0025] An input from a user on a configuration interface is received, wherein the input includes the function identifier of the method to be tested and an implementation method corresponding to the function identifier of the method to be tested.
[0026] In a second aspect, an embodiment of the present application provides a device for generating test code, including:
[0027] An acquisition module is used to acquire a test data packet, wherein the test data packet includes all method functions in the software to be tested;
[0028] The acquisition module is further used to obtain a method function identifier to be tested and an implementation method corresponding to the method function identifier to be tested in response to a user's input, wherein the implementation method is used to represent a method for testing the method function to be tested corresponding to the method function identifier to be tested;
[0029] The acquisition module is further used to acquire, according to the method function identifier to be tested, a target method function corresponding to the method function identifier to be tested in the test data packet;
[0030] The modification module is used to modify the implementation mode corresponding to the target method function to the implementation mode corresponding to the method function identifier to be tested, so as to obtain the test code.
[0031] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the method for generating test code as described in any one of the first aspects is implemented.
[0032] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method for generating test code as described in any one of the first aspects is implemented.
[0033] In a fifth aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device can execute the test code generation method as described in any one of the first aspects.
[0034] The method, device, equipment, storage medium and program product for generating test code of the embodiment of the present application obtain a test data packet, a method function identifier to be tested and an implementation method corresponding to the method function identifier to be tested, wherein the test data packet includes all method functions in the software to be tested. Then, the method function contained in the test data packet is compared with the method function to be tested. For the target method function corresponding to the method function identifier to be tested in the test data packet, the implementation method of the target method function in the test data packet is modified according to the implementation method corresponding to the method function identifier to be tested, and the test code is obtained. Wherein, since the method function of the software to be tested is included in the test data packet, the target method function in the test data packet is replaced by the implementation method of the method function to be tested preset. The generated test code can be used for unit testing of the method function to be tested. In this way, in the test framework corresponding to the existing test data packet, by modifying the implementation of the target method function that needs to be unit tested, a test code for the target method function can be generated. It avoids introducing other test frameworks, thereby reducing the possibility of introducing security vulnerabilities and improving the security of the software to be tested. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0036] Figure 1 It is a flowchart of a method for generating test code provided by an embodiment of the present application;
[0037] Figure 2 It is a flowchart of a method for determining a test result provided by an embodiment of the present application;
[0038] Figure 3 is an exemplary schematic diagram of a method for generating test code provided by an embodiment of the present application;
[0039] Figure 4 It is a structural schematic diagram of a bytecode replacement device provided by an embodiment of the present application;
[0040] Figure 5 is a structural diagram of a device for generating test codes provided by another embodiment of the present application;
[0041] Figure 6 It is a structural schematic diagram of an electronic device provided in yet another embodiment of the present application. DETAILED DESCRIPTION
[0042] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0043] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0044] It should be noted that the acquisition, storage, use and processing of data in the embodiments of the present application are in compliance with the relevant provisions of national laws and regulations.
[0045] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0046] Currently, for the Java language, the following two types of frameworks are usually used for code testing:
[0047] The first type of framework is a unit testing framework, which is used to provide organizational management functions in the code testing process and verify the test results. For example, the unit testing framework can be JUnit or TestNG. JUnit and TestNG are both testing frameworks for the Java programming language, mainly used for unit testing.
[0048] The second type of framework is a simulation framework, which is used to simulate external resources that method functions or interfaces depend on, for example, external resources may be databases or interfaces, etc. As an example, the simulation framework may be Mockito, PowerMock, or EasyMock, etc.
[0049] Combining the above two types of frameworks, the testing process for the code is as follows:
[0050] Users write unit test environments and simulation frameworks in code engineering;
[0051] The unit test scope is defined by the user. Specifically, the unit test scope may include specific method functions or specific interfaces.
[0052] For the test objects within the scope of the unit test, use the simulation framework to write the code of the external resources corresponding to the test objects and simulate the return values returned by the external resources.
[0053] The user uses the unit test environment to write the test code corresponding to the test object, runs the test code on the device, and determines the test results of the test code.
[0054] When writing test codes using the above method, the test codes written in the code testing phase will be included in the production launch package of the software, and each time a user writes a test code, new vulnerabilities may be introduced into the test code due to the different writing habits of each user. Therefore, as the amount of test code increases, the possibility of introducing vulnerabilities into the production launch package increases, thereby reducing the security of the software.
[0055] In order to solve the problems in the prior art, embodiments of the present invention provide a method, apparatus, device, storage medium and program product for generating test codes.
[0056] The following is an introduction to the test code generation method provided by an embodiment of the present invention.
[0057] Figure 1 FIG. 1 is a flow chart showing a method for generating test codes according to an embodiment of the present invention. The method is applied to electronic devices such as Figure 1 As shown, the method may include the following steps:
[0058] S101. Obtain a test data packet.
[0059] The test data package includes all the method functions in the software to be tested. The test data package is obtained by compiling and packaging the software source code written by the developer.
[0060] S102 . In response to a user input, obtain a method function identifier to be tested input by the user and an implementation method corresponding to the method function identifier to be tested.
[0061] Among them, the method function to be tested corresponding to the method function to be tested identifier is the test object that needs to be unit tested and is circled by the user. The implementation method is used to represent the method for testing the method function to be tested corresponding to the method function to be tested identifier. In an embodiment of the present application, the implementation method corresponding to the method function to be tested is determined based on the external resources configured by the developer. For example, if the external resources are generated based on the simulation of the baffle server, the implementation method corresponding to the method function to be tested can be configured to request the return value of the method function to be tested from the baffle server.
[0062] S103: According to the method function identifier to be tested, a target method function corresponding to the method function identifier to be tested is obtained in the test data packet.
[0063] The electronic device traverses the method functions included in the test data packet, and compares them with the method functions corresponding to the method function identifier to be tested, to determine the target method function. Specifically, the number of the target method function is at least one.
[0064] S104: Modify the implementation mode corresponding to the target method function into the implementation mode corresponding to the method function identifier to be tested, and obtain the test code.
[0065] The implementation of the method function in the test data packet usually includes caller information and callee information corresponding to the method function. The electronic device can modify the implementation of the target method function by modifying the callee information.
[0066] Adopting the above method, obtain the test data packet, the method function identifier to be tested and the implementation method corresponding to the method function identifier to be tested, wherein the test data packet includes all the method functions in the software to be tested. Then compare the method function contained in the test data packet with the method function to be tested, for the target method function in the test data packet corresponding to the method function identifier to be tested, modify the implementation method of the target method function in the test data packet according to the implementation method corresponding to the method function identifier to be tested, and obtain the test code. Wherein, since the test data packet includes the method function of the software to be tested, the target method function in the test data packet is replaced by the preset implementation method of the method function to be tested. The generated test code can be used to unit test the method function to be tested. In this way, in the test framework corresponding to the existing test data packet, by modifying the implementation of the target method function that needs to be unit tested, the test code for the target method function can be generated. Avoid introducing other test frameworks, thereby reducing the possibility of introducing security vulnerabilities and improving the security of the software to be tested.
[0067] It should be noted that the above-mentioned function identifier of the method to be tested and the implementation method corresponding to the function identifier of the method to be tested are obtained by the electronic device receiving the user's input on the configuration interface, and the input includes the function identifier of the method to be tested and the implementation method corresponding to the function identifier of the method to be tested.
[0068] The identifier of the method function to be tested may be the name of the method function to be tested.
[0069] In a possible implementation, the configuration interface includes a drop-down menu, and the drop-down menu may include all method functions in the test data package. The user can select the method function to be tested in the drop-down menu by clicking the drop-down menu. The electronic device obtains the identifier corresponding to the method function to be tested in response to the method function to be tested selected by the user. The configuration interface also includes an implementation configuration area, and the user configures the implementation corresponding to the selected method function to be tested in the implementation configuration area. The electronic device obtains the user's input on the configuration interface, thereby obtaining the method function identifier to be tested and the implementation corresponding to the method function identifier to be tested.
[0070] In another possible implementation, the configuration interface includes a method function to be tested configuration area, in which the user can configure the method function to be tested and the implementation corresponding to the method function to be tested.
[0071] In this way, users can pre-configure the method function to be tested and the corresponding implementation method of the method function to be tested according to their actual business needs, so as to implement the subsequent testing of the method function to be tested. In this way, the generated test code is more in line with the actual business needs of users.
[0072] With respect to the above S102, according to the method function identifier to be tested, obtaining the target method function corresponding to the method function identifier to be tested in the test data packet specifically includes the following steps:
[0073] Step 1: Decompress the test data packet to obtain a bytecode file.
[0074] The bytecode file contains the access path of the test file.
[0075] The test data packet is obtained by the electronic device compiling and packaging the software source code written by the developer, so the test data packet needs to be decompressed. In one example, the test data packet can be a jar package or a war package.
[0076] Step 2: Get the test file through the test file access path.
[0077] Step 3: Parse the test file and obtain the method function corresponding to the test file.
[0078] The electronic device can call an open source bytecode analysis tool to parse the test file. By analyzing each test file one by one, the caller information and callee information of each method function in the test data packet can be obtained.
[0079] For example, an open source bytecode analysis tool may be (A Java bytecode manipulation and analysis framework, ASM). The parsed test data packet includes method function 1, caller 1 corresponding to method function 1, callee 2, and communication protocol 1 used for data interaction with callee 2; method function 2, caller 3 corresponding to method function 2, callee 4, and communication protocol 2 used for data interaction with callee 4; wherein the callee information includes the above-mentioned callee identification and the communication protocol used when the electronic device interacts with the callee corresponding to the callee identification for data interaction.
[0080] Step 4: Obtain the target method function corresponding to the method function identifier to be tested in the method function corresponding to the test file.
[0081] In one implementation, the method function to be tested is identified as the method function name to be tested. The electronic device determines the corresponding method function name to be tested based on the method function to be tested identification, and then traverses the names of the method functions in the test file, and takes the method function whose name is consistent with the method function name to be tested as the target method function.
[0082] In another implementation, a correspondence between the method function identifier to be tested and the method function to be tested is pre-set in the electronic device. After obtaining the user's input in the configuration interface, the electronic device searches for the method function to be tested corresponding to the method function identifier to be tested locally according to the preset correspondence, and then searches for the method function identical to the method function to be tested in the method function of the test file, and uses the found method function as the target method function.
[0083] By adopting the method provided in the embodiment of the present application, after obtaining the test data packet, the access path of the test file can be obtained by decompressing the test data packet, thereby obtaining the test file. In this way, the method function corresponding to the test file can be determined, which facilitates the electronic device to compare the method function of the test file with the method function to be tested corresponding to the method function to be tested, and determine the target method function. By comparing the method function of the test file with the method function to be tested in a traversal manner, the accuracy of the search can be improved.
[0084] In some embodiments of the present application, after the test code is generated, the test code is run to generate the test result. Figure 2As shown, after the above S104, the implementation mode corresponding to the target method function is modified to the implementation mode corresponding to the test method function, and the test code is obtained, the method further includes:
[0085] S201. Run the test code and send a call request to the baffle server according to the modified implementation method.
[0086] The baffle server is a simulated external resource that the user pre-configures based on the method function to be tested. In one example, the call request can be a Hypertext Transfer Protocol (HTTP) request, and the baffle server can meet baffle requirements such as http-like interface transactions, database calls, and code internal function calls.
[0087] S202: Receive a return value returned by the baffle server.
[0088] Before receiving the return value returned by the baffle server, the return value corresponding to the method function to be tested may be configured in the baffle server according to the implementation manner corresponding to the method function to be tested.
[0089] In this way, by modifying the implementation of the target method function, the internal functions, external interfaces, and database calls of the software are uniformly connected to the baffle server, and the baffle server provides the return value for the target method function, thereby achieving unified and standardized management of test cases, avoiding users writing different test cases due to different external resources that different method functions rely on, and reducing the complexity of the test code. In addition, for the newly added target method function, the user only needs to configure the corresponding return value on the baffle server, which reduces the user's operation difficulty and improves the test efficiency.
[0090] S203. Determine the test result of the target method function based on the return value.
[0091] By adopting the method provided in the embodiment of the present application, after generating the test code, a call request is sent to the preset baffle server according to the modified implementation method, wherein the baffle server is preset based on the target method function, so the baffle server can return the return value of the target method function to the electronic device. In this way, the baffle server can realize various baffle requirements of the target method function.
[0092] It should be noted that after the electronic device receives the return value returned by the baffle server, it can convert the data format of the return value so that the electronic device can recognize the return value returned by the baffle server. Specifically, the above S203, determining the test result of the target method function based on the return value, can be implemented as follows:
[0093] The data format of the return value is converted according to the preset format conversion process to obtain the target format return value. The test result of the target method function is determined according to the target return value.
[0094] Among them, the above-mentioned configuration interface also includes a format conversion configuration area, and the user can configure the format conversion process in the format conversion configuration area. After the electronic device receives the user's input in the format conversion configuration area, it determines the preset format conversion process and converts the data format of the return value according to the preset format conversion process.
[0095] By adopting the method provided in the embodiment of the present application, after receiving the return value returned by the baffle server, the data format of the return value is converted using a preset format conversion process, so that the baffle server can be suitable for other target method functions, thereby improving the universality of the baffle server.
[0096] The following combination Figure 3 A method for generating test code provided by an embodiment of the present application is introduced, such as Figure 3 As shown, the method includes:
[0097] S301. Obtain the source code of the project under test.
[0098] Among them, the source code of the project under test is the software source code written by the above-mentioned developers.
[0099] S302: compile and package the source code of the project under test.
[0100] S303, packaging the compiled source code into a generated product.
[0101] The packaged product is the test data package mentioned above. Specifically, the test data package can be a jar package or a war package.
[0102] S304: Analyze the generated product and replace the bytecode.
[0103] Among them, analyzing the generated product is the process of analyzing the test file using the open source bytecode analysis tool mentioned above. For the specific method of analyzing the test file and modifying the implementation method of the target method function, please refer to the relevant description in the above embodiment.
[0104] S305: Generate a packaged product after replacement.
[0105] It can be understood that after the implementation mode of the target method function corresponding to the test file is modified as described above, the modified test file needs to be compiled and packaged again.
[0106] S306: Deploy services for the packaged product.
[0107] S307: Send an http request to the baffle server.
[0108] The baffle server is used to simulate the external resources corresponding to the method function to be tested, and is pre-configured by the user based on the method function to be tested.
[0109] The electronic device runs the modified test data packet, sends an http request to the baffle server according to the modified implementation method, and requests the baffle server for the return value of the method to be tested.
[0110] It should be noted that the above-mentioned analysis of the generated product and the bytecode replacement are performed by Figure 4 The bytecode replacement device shown is completed. Figure 4 As shown, the device includes a file processing module, a code analysis module, a pile management module, a bytecode reading and writing module, and a message format conversion module.
[0111] Among them, the file processing module is used to decompress the test data packet generated after compilation and packaging, obtain the bytecode file, and trigger the traversal logic of all bytecode files.
[0112] The code analysis module uses the built-in open source bytecode analysis tool to analyze the test files corresponding to the bytecode files one by one to obtain the caller information and callee information of each method function.
[0113] The pile management module is used to provide the configuration interface in the above embodiment, and the user can configure the method function to be tested, the implementation method corresponding to the method function to be tested, and the format conversion process in the pile management module. Figure 4 In the bytecode replacement device shown, the callee information of the method to be tested configured by the user in the stub management module includes a Redis database, a Mybaitis platform, and a communication protocol http.
[0114] The bytecode reading and writing module is used to modify the implementation mode of the target method function in the test file to the implementation mode of the method to be tested pre-configured in the stub management module. Then the file processing module compiles and packages the modified test file to generate a modified test data packet.
[0115] The message format conversion module is used to convert the data format of the return value returned by the baffle server so that the electronic device can recognize the return value.
[0116] Adopt the method provided by the embodiment of the present application, when the user needs to test a specific method function, by configuring the method function to be tested and the implementation corresponding to the method function to be tested in the pile management module, there is no need to rewrite the software source code, that is, the test code generation method provided by the embodiment of the present application does not need to rely on the source code of the project to be tested, so it is non-invasive to the project to be tested, thereby avoiding the introduction of new vulnerabilities in the production on-line package, and improving the security of the software. And there is no need to open the software source code to the user, the user configures the implementation corresponding to the method function to be tested and the method function to be tested in the pile management module, which reduces the complexity of authority management. By modifying the implementation of the method function, the internal functions, external interfaces and database calls of the software are uniformly connected to the baffle server, and the baffle server provides a return value for the method function to be tested, thereby realizing the unified and standardized management of the test case, avoiding the need for users to write different test cases due to the different external resources that different method functions rely on, and reducing the complexity of the test code.
[0117] Based on the same concept, the present application embodiment also provides a device for generating test codes, such as Figure 5 As shown, the device comprises:
[0118] The acquisition module 501 is used to acquire a test data packet, wherein the test data packet includes all method functions in the software to be tested;
[0119] The acquisition module 501 is further used to obtain a method function identifier to be tested and an implementation method corresponding to the method function identifier to be tested in response to a user's input, wherein the implementation method is used to represent a method for testing the method function to be tested corresponding to the method function identifier to be tested;
[0120] The acquisition module 501 is further configured to acquire, in the test data packet, a target method function corresponding to the method function identifier to be tested according to the method function identifier to be tested;
[0121] The modification module 502 is used to modify the implementation mode corresponding to the target method function to the implementation mode corresponding to the method function identifier to be tested, so as to obtain the test code.
[0122] In a possible implementation, the acquisition module 501 is used to:
[0123] Decompressing the test data packet to obtain a bytecode file, wherein the bytecode file includes an access path to the test file;
[0124] Decompressing the test data packet to obtain a bytecode file, wherein the bytecode file includes an access path to the test file;
[0125] Acquire the test file through the access path of the test file;
[0126] Parse the test file to obtain the method function corresponding to the test file;
[0127] The target method function corresponding to the method function identifier to be tested is obtained from the method function corresponding to the test file.
[0128] In a possible implementation, the device further includes:
[0129] A running module, used for running the test code, and sending a call request to the baffle server according to the modified implementation mode;
[0130] A receiving module, used for receiving a return value returned by the baffle server;
[0131] A determination module is used to determine a test result of the target method function based on the return value.
[0132] In a possible implementation, a module is determined, specifically for:
[0133] Convert the data format of the return value according to a preset format conversion process to obtain a target format return value;
[0134] The test result of the target method function is determined according to the target return value.
[0135] In a possible implementation, the device further includes:
[0136] A configuration module is used to configure the return value corresponding to the target method function in the baffle server according to the implementation mode corresponding to the method function to be tested.
[0137] In a possible implementation, the receiving module is further used to receive user input on a configuration interface, where the input includes the function identifier of the method to be tested and an implementation method corresponding to the function identifier of the method to be tested.
[0138] The embodiments of the present application provide various modules of the device for data transmission, which can realize Figure 1 The functions of each step of the method for data transmission are provided, and the corresponding technical effects can be achieved. For the sake of brevity, they will not be repeated here.
[0139] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.
[0140] The electronic device 600 may include a processor 601 and a memory 602 storing computer program instructions.
[0141] Specifically, the processor 601 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0142] The memory 602 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 602 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 602 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 602 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 602 is a non-volatile solid-state memory.
[0143] In certain embodiments, the memory may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to one aspect of the present application.
[0144] The processor 601 implements any one of the data transmission methods in the above embodiments by reading and executing computer program instructions stored in the memory 602 .
[0145] In some examples, the electronic device 600 may further include a communication interface 603 and a bus 604. Figure 6 As shown, the processor 601, the memory 602, and the communication interface 603 are connected via a bus 604 and communicate with each other.
[0146] The communication interface 603 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0147] Bus 604 includes hardware, software or both, and the parts of online data flow billing equipment are coupled to each other. For example, but not limitation, bus 604 may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front-side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 604 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.
[0148] Exemplarily, the electronic device 600 may be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA).
[0149] The electronic device 600 can execute the test code generation method in the embodiment of the present application, thereby realizing the combination Figure 1 and Figure 5 A method and apparatus for test code generation is described.
[0150] In addition, in combination with the test code generation method in the above embodiment, the embodiment of the present application also provides a computer-readable storage medium for implementation. The computer-readable storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any one of the data transmission methods in the above embodiment is implemented. Examples of computer-readable storage media include non-transitory computer-readable storage media, such as portable disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, etc.
[0151] An embodiment of the present application also provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, any one of the test code generation methods in the above embodiments is implemented.
[0152] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0153] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0154] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0155] The above reference is according to the method of the embodiment of the present application, the flow chart of the device (system) and the computer program product and / or the block diagram described various aspects of the present application.It should be understood that each square box in the flow chart and / or the block diagram and the combination of each square box in the flow chart and / or the block diagram can be realized by computer program instructions.These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the realization of the function / action specified in one or more square boxes of the flow chart and / or the block diagram.Such a processor can be but is not limited to a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit.It can also be understood that each square box in the block diagram and / or the flow chart and the combination of the square boxes in the block diagram and / or the flow chart can also be realized by the dedicated hardware that performs the specified function or action, or can be realized by the combination of dedicated hardware and computer instructions.
[0156] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A method for generating test code, characterized in that: include: Acquire a test data packet, wherein the test data packet includes method functions in the software to be tested; In response to a user input, obtaining a method function identifier to be tested and an implementation method corresponding to the method function identifier to be tested, wherein the implementation method is used to represent a method for testing the method function to be tested corresponding to the method function identifier to be tested; According to the method function identifier to be tested, obtaining a target method function corresponding to the method function identifier to be tested in the test data packet; The implementation mode corresponding to the target method function is modified to the implementation mode corresponding to the method function identifier to be tested, and the test code is obtained.
2. The method according to claim 1, characterized in that The step of acquiring, in the test data packet, a target method function corresponding to the method function identifier to be tested, according to the method function identifier to be tested, comprises: Decompressing the test data packet to obtain a bytecode file, wherein the bytecode file includes an access path to the test file; Acquire the test file through the access path of the test file; Parse the test file to obtain the method function corresponding to the test file; The target method function corresponding to the method function identifier to be tested is obtained from the method function corresponding to the test file.
3. The method according to claim 1, characterized in that: After modifying the implementation mode corresponding to the target method function to the implementation mode corresponding to the method function identifier to be tested to obtain the test code, the method further includes: Run the test code and send a call request to the baffle server according to the modified implementation method; Receive a return value returned by the baffle server; A test result of the target method function is determined based on the return value.
4. The method according to claim 3, characterized in that The determining the test result of the target method function based on the return value includes: Convert the data format of the return value according to a preset format conversion process to obtain a target format return value; The test result of the target method function is determined according to the target return value.
5. The method according to claim 3, characterized in that: Before receiving the return value returned by the baffle server, the method further includes: The return value corresponding to the method function to be tested is configured in the baffle server according to the implementation mode corresponding to the method function to be tested.
6. The method according to claim 1, characterized in that Before obtaining the function identifier of the method to be tested and the implementation manner corresponding to the function identifier of the method to be tested in response to the user's input, the method further includes: An input from a user on a configuration interface is received, wherein the input includes the function identifier of the method to be tested and an implementation method corresponding to the function identifier of the method to be tested.
7. A device for generating test code, characterized in that: include: An acquisition module is used to acquire a test data packet, wherein the test data packet includes all method functions in the software to be tested; The acquisition module is further used to obtain a method function identifier to be tested and an implementation method corresponding to the method function identifier to be tested in response to a user's input, wherein the implementation method is used to represent a method for testing the method function to be tested corresponding to the method function identifier to be tested; The acquisition module is further used to acquire, according to the method function identifier to be tested, a target method function corresponding to the method function identifier to be tested in the test data packet; The modification module is used to modify the implementation mode corresponding to the target method function to the implementation mode corresponding to the method function identifier to be tested, so as to obtain the test code.
8. An electronic device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the method for generating test codes according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method for generating test codes according to any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device is enabled to execute the method for generating test codes as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Interface testing method, related equipment, storage medium and program product
CN115827417A
Test data generation method and device, computer equipment and storage medium
CN116775499A
Software Quality Assessment based on Semantic Similarities
US20090319833A1
Efficient sharing of test fixtures and ordering of test suites
US9201763B1
Method and computer-readable recording medium for unit test reuse
WO2024053772A1
