Method, apparatus, device, storage medium and program product for test code generation

By modifying the implementation of methods and functions in the test data package to generate test code, the software security problem caused by the diversity of test frameworks in existing technologies is solved, and more efficient and secure test code generation is achieved.

CN119002929BActive Publication Date: 2025-11-11CHINA CONSTRUCTION BANK +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411373716.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-11-11
Estimated Expiration
2044-09-29

AI Technical Summary

Technical Problem

Existing technologies require different code testing frameworks to be built for different methods and functions in software testing, which increases the possibility of vulnerabilities in the test code and reduces software security.

Method used

By obtaining the method function identifiers and implementation methods from the test data package, the implementation methods of the target methods can be modified to generate test code, avoiding the introduction of other testing frameworks and reducing the possibility of security vulnerabilities.

Benefits of technology

It improves software security, reduces the complexity of test code and the possibility of introducing vulnerabilities, and increases testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119002929B_ABST
    Figure CN119002929B_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, device, storage medium, and program product for generating test code, applied in the field of big data technology. The method includes: acquiring a test data package; responding to user input, acquiring a function identifier to be tested and its corresponding implementation, the implementation representing the method for testing the function to be tested corresponding to the function identifier; acquiring a target function corresponding to the function identifier in the test data package; and modifying the implementation of the target function to match the implementation of the function identifier to obtain test code. Thus, by modifying the implementation of the target function in the test framework corresponding to the test data package, test code targeting the target function can be generated, thereby reducing the possibility of introducing security vulnerabilities and improving the security of the software under test.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of big data technology, and in particular relates to a method, apparatus, device, storage medium and program product for generating test code. Background Technology

[0002] Before software feature updates or software launch, the software code needs to be tested. Currently, unit testing is used to test parts of the software code, thereby reducing testing costs.

[0003] However, when building test code, developers need to write resource code for the external resources used by the methods and functions to be tested, as well as complete test code, to build a complete code testing framework. Thus, different code testing frameworks need to be built for different methods and functions, and finally, the test code written by developers is included in the software's deployment package. Therefore, as the amount of test code increases, the possibility of vulnerabilities in the test code increases, reducing software security. Summary of the Invention

[0004] This application provides a method, apparatus, device, storage medium, and program product for generating test code, which can improve software security.

[0005] In a first aspect, embodiments of this application provide a method for generating test code, including:

[0006] Obtain a test data package, which includes method functions in the software to be tested;

[0007] In response to user input, the identifier of the method function to be tested and the corresponding implementation method of the method function to be tested are obtained. The implementation method is used to represent the method of testing the method function to be tested corresponding to the method function identifier.

[0008] Based on the identifier of the method function to be tested, obtain the target method function corresponding to the identifier of the method function to be tested from the test data packet;

[0009] The implementation of the target method function is modified to the implementation of the method function identifier to be tested, thus obtaining the test code.

[0010] In one possible implementation, obtaining the target method function corresponding to the method function identifier to be tested from the test data packet based on the method function identifier to be tested includes:

[0011] The test data packet is decompressed to obtain a bytecode file, which contains the access path of the test file;

[0012] The test file is obtained through the access path of the test file;

[0013] Parse the test file to obtain the corresponding method function;

[0014] Obtain the target method function corresponding to the identifier of the method function to be tested from the method function corresponding to the test file.

[0015] In one possible implementation, after modifying the implementation of the target method function to the implementation of the method function identifier 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.

[0017] Receive the return value returned by the baffle server;

[0018] The test result of the target method function is determined based on the return value.

[0019] In one possible implementation, determining the test result of the target method function based on the return value includes:

[0020] The data format of the returned value is converted according to a preset format conversion process to obtain the target format return value;

[0021] The test result of the target method function is determined based on the target return value.

[0022] In one possible implementation, before receiving the return value returned by the baffle server, the method further includes:

[0023] Configure the return value of the method function to be tested in the baffle server according to the implementation method of the method function to be tested.

[0024] In one possible implementation, before obtaining the function identifier of the method to be tested and the implementation method corresponding to the function identifier of the method to be tested in response to user input, the method further includes:

[0025] The system receives user input on the configuration interface, including the identifier of the method function to be tested and the corresponding implementation method of the method function identifier to be tested.

[0026] Secondly, embodiments of this application provide a test code generation apparatus, comprising:

[0027] The acquisition module is used to acquire a test data package, which includes all the methods and functions in the software under test.

[0028] The acquisition module is further configured to, in response to user input, acquire the identifier of the method function to be tested and the implementation method corresponding to the identifier of the method function to be tested, wherein the implementation method is used to represent the method for testing the method function to be tested corresponding to the identifier of the method function to be tested;

[0029] The acquisition module is further configured to acquire, based on the identifier of the method function to be tested, the target method function corresponding to the identifier of the method function to be tested in the test data packet;

[0030] The modification module is used to modify the implementation of the target method function to the implementation of the method function identifier to be tested, thereby obtaining the test code.

[0031] Thirdly, embodiments of this application provide an electronic device, the device comprising: a processor and a memory storing computer program instructions; the processor, when executing the computer program instructions, implements the test code generation method as described in any one of the first aspects.

[0032] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the test code generation method as described in any one of the first aspects.

[0033] Fifthly, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the test code generation method as described in any one of the first aspects.

[0034] This application discloses a method, apparatus, device, storage medium, and program product for generating test code. It obtains a test data package, a method function identifier to be tested, and the corresponding implementation method of the method function identifier. The test data package includes all method functions in the software under test. Then, it compares the method functions in the test data package with the method functions to be tested. For the target method function in the test data package that corresponds to the method function identifier, it modifies the implementation method of the target method function in the test data package according to the implementation method corresponding to the method function identifier, thus obtaining test code. Since the test data package includes method functions of the software under test, the target method function in the test data package is replaced by a preset implementation method of the method function to be tested. The generated test code can be used to perform unit testing on the method functions to be tested. Thus, within an existing test framework corresponding to a test data package, test code for the target method function can be generated by modifying the implementation of the target method function that needs to be unit tested. This avoids introducing other test frameworks, thereby reducing the possibility of introducing security vulnerabilities and improving the security of the software under test. Attached Figure Description

[0035] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0036] Figure 1 This is a flowchart illustrating a method for generating test code according to an embodiment of this application;

[0037] Figure 2 This is a flowchart illustrating a method for determining test results provided in one embodiment of this application;

[0038] Figure 3 This is an exemplary schematic diagram of a test code generation method provided in one embodiment of this application;

[0039] Figure 4 This is a schematic diagram of the structure of a bytecode replacement device provided in one embodiment of this application;

[0040] Figure 5 This is a schematic diagram of the structure of a test code generation device provided in another embodiment of this application;

[0041] Figure 6 This is a schematic diagram of the structure of an electronic device provided in another embodiment of this application. Detailed Implementation

[0042] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.

[0043] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.

[0044] It should be noted that the acquisition, storage, use, and processing of data in this application embodiment all comply with the relevant provisions of national laws and regulations.

[0045] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the solution.

[0046] Currently, for the Java language, the following two types of frameworks are commonly used for code testing:

[0047] The first type of framework is the unit testing framework, which provides organizational and management functions in the code testing process, as well as verification of test results. For example, a unit testing framework could be JUnit or TestNG. JUnit and TestNG are both testing frameworks for the Java programming language, primarily used for unit testing.

[0048] The second type of framework is the simulation framework, used to simulate external resources that methods, functions, or interfaces depend on. These external resources could be databases or interfaces. Examples of simulation frameworks include Mockito, PowerMock, or EasyMock.

[0049] Combining the two frameworks mentioned above, the testing process for the code is as follows:

[0050] Users write unit test environments and simulation frameworks in their code projects;

[0051] The scope of unit tests defined by the user can specifically include specific methods or interfaces.

[0052] For the test objects within the defined unit test scope, use a mock framework to write the code for the external resources corresponding to the test objects and simulate the return values ​​returned by the external resources.

[0053] Users write test code for the test objects in a unit testing environment, run the test code on the device, and judge the test results.

[0054] Using the above method to write test code, since the test code written during the code testing phase will be included in the software's production release package, and each time a user writes test code, due to different writing habits of each user, new vulnerabilities may be introduced into the test code. Therefore, as the number of test codes increases, the possibility of introducing vulnerabilities into the production release package increases, thereby reducing the software's security.

[0055] To address the problems of the prior art, embodiments of the present invention provide a method, apparatus, device, storage medium, and program product for generating test code.

[0056] The method for generating test code provided in the embodiments of the present invention will be described below.

[0057] Figure 1 A flowchart illustrating a test code generation method according to an embodiment of the present invention is shown. This method is applied to electronic devices, such as… Figure 1 As shown, the method may include the following steps:

[0058] S101. Obtain the test data packet.

[0059] The test data package includes all methods and functions in the software under test. The test data package is obtained by compiling and packaging the software source code written by the developers.

[0060] S102. In response to user input, obtain the identifier of the method to be tested and the implementation method corresponding to the identifier of the method to be tested.

[0061] Here, the test method function corresponding to the test method function identifier is the test object that the user has selected for unit testing. The implementation method is used to represent the method for testing the test method function corresponding to the test method function identifier. In this embodiment, the implementation method corresponding to the test method function is determined based on external resources configured by the developer. For example, if the external resources are generated based on a stencil server, the implementation method corresponding to the test method function can be configured to request the return value of the test method function from the stencil server.

[0062] S103. Based on the identifier of the method function to be tested, obtain the target method function corresponding to the identifier of the method function to be tested from the test data packet.

[0063] Specifically, the electronic device iterates through the method functions included in the test data packet and compares them with the method functions corresponding to the identifiers of the method functions to be tested to determine the target method function. There is at least one target method function.

[0064] S104. Modify the implementation of the target method function to the implementation of the method function identifier to be tested, and obtain the test code.

[0065] The implementation of the method function in the test data package usually includes the caller information and the callee information of the method function. By modifying the callee information, the electronic device can modify the implementation of the target method function.

[0066] Using the above method, a test data package, the identifier of the method function to be tested, and the corresponding implementation of the method function identifier are obtained. The test data package includes all method functions in the software under test. Then, the method functions in the test data package are compared with the method functions to be tested. For the target method function in the test data package that corresponds to the identifier of the method function to be tested, the implementation of the target method function in the test data package is modified according to the implementation of the method function to be tested, resulting in test code. Since the test data package includes the method functions of the software under test, the target method function in the test data package is replaced using a preset implementation of the method function to be tested. The generated test code can be used to perform unit testing on the method functions to be tested. Thus, within an existing test framework corresponding to the test data package, by modifying the implementation of the target method function that needs to be unit tested, test code for the target method function can be generated. This avoids introducing other test frameworks, thereby reducing the possibility of introducing security vulnerabilities and improving the security of the software under test.

[0067] It should be noted that the above-mentioned function identifier and corresponding implementation method of the method to be tested are obtained by the electronic device receiving user input in the configuration interface, which includes the function identifier and corresponding implementation method of the method to be tested.

[0068] The identifier for the method / function to be tested can be the name of the method / function to be tested.

[0069] In one possible implementation, the configuration interface includes a drop-down menu, which can include all method functions in the test data package. The user can select a method function to be tested by clicking the drop-down menu. The electronic device responds to the user's selected method function by obtaining its corresponding identifier. The configuration interface also includes an implementation configuration area, where the user configures the implementation method corresponding to the selected method function. The electronic device obtains the user's input on the configuration interface, thereby acquiring the identifier of the method function to be tested and its corresponding implementation method.

[0070] In another possible implementation, the configuration interface includes a configuration area for the method / function to be tested. Users can configure the method / function to be tested and its corresponding implementation in this area.

[0071] In this way, users can pre-configure the implementation of the methods to be tested and their corresponding methods based on their actual business needs, thereby enabling subsequent testing of the methods to be tested. This results in generated test code that is more closely aligned with the user's actual business requirements.

[0072] Regarding S102 above, based on the identifier of the method function to be tested, the target method function corresponding to the identifier of the method function to be tested is obtained from the test data packet, specifically including the following steps:

[0073] Step 1: Decompress the test data packet to obtain the bytecode file.

[0074] The bytecode file contains the access path to the test file.

[0075] Test data packages are generated by compiling and packaging software source code written by developers into electronic devices; therefore, they need to be decompressed. In one example, a test data package can be a JAR file or a WAR file.

[0076] Step 2: Obtain the test file through the access path of the test file.

[0077] Step 3: Parse the test file to obtain the corresponding method function.

[0078] The electronic device can use open-source bytecode analysis tools to parse the test files. By analyzing each test file individually, the caller and callee information for each method function in the test data package can be obtained.

[0079] For example, an open-source bytecode analysis tool could be (A Java bytecode manipulation and analysis framework, ASM). The parsed test data packet includes method function 1, the caller 1 corresponding to method function 1, callee 2, and communication protocol 1 used for data interaction with callee 2; method function 2, the 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 aforementioned callee identifier and the communication protocol used by the electronic device when interacting with the callee corresponding to the callee identifier.

[0080] Step 4: Obtain the target method function corresponding to the identifier of the method function to be tested from the method function corresponding to the test file.

[0081] In one implementation, the identifier of the method function to be tested is the name of the method function to be tested. The electronic device determines the corresponding name of the method function to be tested based on the identifier of the method function to be tested, and then iterates through the names of the method functions in the test file, and takes the method function whose name is consistent with the name of the method function to be tested as the target method function.

[0082] In another implementation, the electronic device pre-sets a mapping between the identifiers of the methods to be tested and the methods to be tested. After obtaining the user's input on the configuration interface, the electronic device searches locally for the method to be tested corresponding to the identifier of the method to be tested, according to the pre-set mapping. Then, it searches for a method function in the test file that is the same as the method to be tested, and uses the found method function as the target method function.

[0083] Using the method provided in this application embodiment, 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, facilitating the electronic device to compare the method function in the test file with the method function identifier to be tested, and thus determine the target method function. Comparing the method function in the test file and the method function to be tested through traversal can improve the accuracy of the search.

[0084] In some embodiments of this application, after generating test code, the test code is run to generate test results. Specifically, as shown below... Figure 2As shown, after modifying the implementation of the target method function to the implementation of the test method function in S104 above, and obtaining the test code, 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] In this context, the stencil server is a simulated external resource pre-configured by the user based on the function to be tested. In one example, the aforementioned call request could be a Hypertext Transfer Protocol (HTTP) request, and the stencil server can meet the stencil requirements for HTTP-type interface transactions, database calls, and internal function calls within the code.

[0087] S202, Receive the return value returned by the baffle server.

[0088] Before receiving the return value from the shield server, the return value of the method function to be tested can be configured in the shield server according to the implementation method of the method function to be tested.

[0089] In this way, by modifying the implementation of the target method function, the software's internal functions, external interfaces, and database calls are uniformly connected to the control panel server. The control panel server then provides return values ​​for the target method function, thereby achieving unified and standardized management of test cases. This avoids the need for users to write different test cases due to different external resources depended on by different method functions, reducing the complexity of the test code. Furthermore, for newly added target method functions, users only need to configure the corresponding return value on the control panel server, reducing the operational difficulty for users and thus improving testing efficiency.

[0090] S203. Determine the test results of the target method function based on the return value.

[0091] Using the method provided in this application embodiment, after generating test code, a call request is sent to a preset blocking server according to the modified implementation. The blocking server is preset based on the target method function; therefore, the blocking server can return the return value of the target method function to the electronic device. In this way, the blocking server can fulfill various blocking requirements of the target method function.

[0092] It should be noted that after the electronic device receives the return value from 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-mentioned 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 a preset format conversion process to obtain the target format return value. The test result of the target method function is determined based on the target return value.

[0094] The configuration interface also includes a format conversion configuration area, where users can configure the format conversion process. After receiving the user's input in the format conversion configuration area, the electronic device determines the preset format conversion process and converts the data format of the returned value according to the preset format conversion process.

[0095] By using the method provided in this application embodiment, 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, which makes the baffle server applicable to other target method functions and improves the versatility of the baffle server.

[0096] The following combination Figure 3 This application introduces a method for generating test code, as provided in its embodiments. Figure 3 As shown, the method includes:

[0097] S301. Obtain the source code of the project under test.

[0098] The source code of the tested project is the software source code written by the aforementioned developers.

[0099] S302. Compile and package the source code of the project under test.

[0100] S303, Package the compiled source code into a package.

[0101] The packaged output is the aforementioned test data package. Specifically, the test data package can be a JAR file or a WAR file.

[0102] S304. Analyze the generated product and perform bytecode replacement.

[0103] The analysis of the generated product is the process of analyzing the test file using the open-source bytecode analysis tool described above. For the specific method of analyzing the test file and modifying the implementation of the target method function, please refer to the relevant description in the above embodiments.

[0104] S305. Generate the packaged product after replacement.

[0105] Understandably, after modifying the implementation of the target method function corresponding to the test file as described above, the modified test file needs to be recompiled and packaged.

[0106] S306. Deploy services for the packaged products.

[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 under test, and it is pre-configured by the user based on the method function under test.

[0109] The electronic device runs the modified test data package described above and sends an HTTP request to the baffle server in accordance with the modified implementation method, requesting the return value of the method to be tested from the baffle server.

[0110] It should be noted that the above-mentioned actions of analyzing the generated product and performing bytecode replacement are performed by... Figure 4 The bytecode replacement device shown is complete. (As...) Figure 4 As shown, the device includes a file processing module, a code analysis module, a stub management module, a bytecode reading and writing module, and a message format conversion module.

[0111] The file processing module is used to decompress the test data package generated after compilation and packaging to obtain bytecode files, and then trigger the traversal logic for all bytecode files.

[0112] The code analysis module uses a built-in open-source bytecode analysis tool to analyze the test files corresponding to the bytecode files one by one, and obtains the caller information and callee information of each method function.

[0113] The stub management module provides the configuration interface described in the above embodiments. Users can configure the method function to be tested, its implementation method, and format conversion process within the stub management module. Figure 4 In the bytecode replacement device shown, the caller information of the method to be tested configured by the user in the stub management module includes the Redis database, the MyBatis platform, and the communication protocol HTTP.

[0114] The bytecode reading and writing module is used to modify the implementation of the target method function in the test file to the implementation 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 the modified test data package.

[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] Using the method provided in this application embodiment, when a user needs to test a specific method function, they can configure the method function to be tested and the corresponding implementation method of the method function identifier in the stub management module. There is no need to rewrite the software source code. That is, the test code generation method provided in this application embodiment does not depend on the source code of the project under test, thus it is non-intrusive to the project under test, thereby avoiding the introduction of new vulnerabilities in the production deployment package and improving software security. Furthermore, there is no need to expose the software source code to the user; the user only needs to configure the method function to be tested and the corresponding implementation method of the method function identifier in the stub management module, reducing the complexity of permission management. By modifying the implementation method of the method function, the software's internal functions, external interfaces, and database calls are uniformly connected to the stub server, which provides return values ​​for the method function to be tested. This achieves unified and standardized management of test cases, avoiding the need for users to write different test cases due to different external resources depended on by different method functions, thus reducing the complexity of the test code.

[0117] Based on the same concept, embodiments of this application also provide a test code generation apparatus, such as... Figure 5 As shown, the device includes:

[0118] The acquisition module 501 is used to acquire a test data package, which includes all the method functions in the software to be tested.

[0119] The acquisition module 501 is further configured to, in response to user input, acquire the identifier of the method function to be tested and the implementation method corresponding to the identifier of the method function to be tested, wherein the implementation method is used to represent the method of testing the method function to be tested corresponding to the identifier of the method function to be tested;

[0120] The acquisition module 501 is further configured to acquire, based on the identifier of the method function to be tested, the target method function corresponding to the identifier of the method function to be tested in the test data packet;

[0121] Modification module 502 is used to modify the implementation of the target method function to the implementation of the method function identifier to be tested, thereby obtaining test code.

[0122] In one possible implementation, module 501 is used for:

[0123] The test data packet is decompressed to obtain a bytecode file, which contains the access path of the test file;

[0124] The test data packet is decompressed to obtain a bytecode file, which contains the access path of the test file;

[0125] The test file is obtained through the access path of the test file;

[0126] Parse the test file to obtain the corresponding method function;

[0127] Obtain the target method function corresponding to the identifier of the method function to be tested from the method function corresponding to the test file.

[0128] In one possible implementation, the device further includes:

[0129] The execution module is used to run the test code and send a call request to the baffle server according to the modified implementation method.

[0130] A receiving module is used to receive the return value returned by the baffle server;

[0131] The determination module is used to determine the test result of the target method function based on the return value.

[0132] In one possible implementation, a module is defined, specifically for:

[0133] The data format of the returned value is converted according to a preset format conversion process to obtain the target format return value;

[0134] The test result of the target method function is determined based on the target return value.

[0135] In one possible implementation, the device further includes:

[0136] The configuration module is used to configure the return value of the target method function in the baffle server according to the implementation method of the method function to be tested.

[0137] In one possible implementation, the receiving module is further configured to receive user input on the configuration interface, the input including the identifier of the method function to be tested and the implementation method corresponding to the identifier of the method function to be tested.

[0138] The embodiments of this application provide various modules of a data transmission device, which can realize... Figure 1 The method provides the functionality of each step in the data transmission process and achieves the corresponding technical effects. For the sake of brevity, these details will not be elaborated here.

[0139] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this 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), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.

[0142] Memory 602 may include mass storage for data or instructions. For example, and not limitingly, memory 602 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 602 may include removable or non-removable (or fixed) media. Where appropriate, memory 602 may be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, memory 602 is non-volatile solid-state memory.

[0143] In certain embodiments, the memory may include read-only memory (ROM), random access memory (RAM), disk storage media devices, optical storage media devices, flash memory devices, and electrical, optical, or other physical / tangible memory storage devices. Thus, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) 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 this application.

[0144] The processor 601 implements any of the data transmission methods described in the above embodiments by reading and executing computer program instructions stored in the memory 602.

[0145] In some examples, electronic device 600 may also include communication interface 603 and bus 604. For example, Figure 6 As shown, the processor 601, memory 602, and communication interface 603 are connected through bus 604 and complete communication with each other.

[0146] The communication interface 603 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.

[0147] Bus 604 includes hardware, software, or both, that couples components of an online data traffic metering device together. For example, and not as a limitation, bus 604 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 604 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, any suitable bus or interconnect is contemplated herein.

[0148] For example, the electronic device 600 can be a mobile phone, tablet computer, laptop computer, handheld computer, in-vehicle electronic device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc.

[0149] The electronic device 600 can execute the test code generation method in the embodiments of this application, thereby achieving the combination Figure 1 and Figure 5 The methods and apparatus described are for generating test code.

[0150] In addition, in conjunction with the test code generation method in the above embodiments, this application also provides a computer-readable storage medium for implementation. This computer-readable storage medium stores computer program instructions; when executed by a processor, these computer program instructions implement any of the data transmission methods in the above embodiments. Examples of computer-readable storage media include non-transitory computer-readable storage media, such as portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, etc.

[0151] This 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, they implement any of the test code generation methods described in the above embodiments.

[0152] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.

[0153] The functional blocks shown in the above-described structural diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on 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, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.

[0154] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. 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 embodiments, or in a different order, or several steps can be performed simultaneously.

[0155] The aspects of this application have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. 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 is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by dedicated hardware performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0156] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.

Claims

1. A method for generating test code, characterized in that, include: Obtain a test data package, which includes method functions in the software to be tested; In response to user input, the identifier of the method function to be tested and the corresponding implementation method of the method function to be tested are obtained. The implementation method is used to represent the method of testing the method function to be tested corresponding to the method function identifier. Based on the identifier of the method function to be tested, obtain the target method function corresponding to the identifier of the method function to be tested from the test data packet; Modify the implementation of the target method function to the implementation of the method function identifier to be tested to obtain the test code; After modifying the implementation of the target method function to the implementation of the method function identifier to be tested, and obtaining 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. Receive the return value returned by the baffle server; The test result of the target method function is determined based on the return value; Before responding to user input and obtaining the function identifier of the method to be tested and the corresponding implementation method of the function identifier, the method further includes: The system receives user input on the configuration interface, including the identifier of the method function to be tested and the corresponding implementation method of the method function identifier to be tested.

2. The method according to claim 1, characterized in that, The step of obtaining the target method function corresponding to the method function identifier to be tested from the test data packet according to the method function identifier to be tested includes: The test data packet is decompressed to obtain a bytecode file, which contains the access path of the test file; The test file is obtained through the access path of the test file; Parse the test file to obtain the corresponding method function; Obtain the target method function corresponding to the identifier of the method function to be tested from the method function corresponding to the test file.

3. The method according to claim 1, characterized in that, The step of determining the test result of the target method function based on the return value includes: The data format of the returned value is converted according to a preset format conversion process to obtain the target format return value; The test result of the target method function is determined according to the return value in the target format.

4. The method according to claim 1, characterized in that, Before receiving the return value returned by the baffle server, the method further includes: Configure the return value of the method function to be tested in the baffle server according to the implementation method of the method function to be tested.

5. An apparatus for generating test code, characterized in that, include: The acquisition module is used to acquire a test data package, which includes all the methods and functions in the software under test. The acquisition module is further configured to, in response to user input, acquire the identifier of the method function to be tested and the implementation method corresponding to the identifier of the method function to be tested, wherein the implementation method is used to represent the method for testing the method function to be tested corresponding to the identifier of the method function to be tested; The acquisition module is further configured to acquire, based on the identifier of the method function to be tested, the target method function corresponding to the identifier of the method function to be tested in the test data packet; The modification module is used to modify the implementation of the target method function to the implementation of the method function identifier to be tested, thereby obtaining test code. The device further includes: The execution module is used to run the test code and send a call request to the baffle server according to the modified implementation method. A receiving module is used to receive the return value returned by the baffle server; A determination module is used to determine the test result of the target method function based on the return value; The receiving module is also used to receive user input on the configuration interface, the input including the function identifier of the method to be tested and the implementation method corresponding to the function identifier of the method to be tested.

6. An electronic device, characterized in that, The device includes: a processor and a memory storing computer program instructions; the processor, when executing the computer program instructions, implements the test code generation method as described in any one of claims 1-4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions that, when executed by a processor, implement the test code generation method as described in any one of claims 1-4.

8. A computer program product, characterized in that, When the instructions in the computer program product are executed by the processor of the electronic device, the electronic device is able to perform the test code generation method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Interface testing method, related equipment, storage medium and program product

    CN115827417A

  • Software Quality Assessment based on Semantic Similarities

    US20090319833A1