Software Testing Method and Apparatus, Electronic Device, and Computer-Readable Storage Medium

The method of injecting a target hook function during compilation for software testing allows for efficient and flexible function-level testing by dynamically modifying parameters and return values, addressing the inefficiencies of manual modification in existing methods.

CN114356745BActive Publication Date: 2025-07-15TENPAY PAID TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011091071.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-13
Publication Date
2025-07-15
Estimated Expiration
2040-10-13

AI Technical Summary

Technical Problem

In the function-level exception testing, the function parameter value or return value needs to be modified through static declarations, resulting in extended test cycles and waste of resources, which may affect the product launch time.

Method used

By injecting the target hook function into the source code to be tested, the target call relationship code is used in the target hook function to determine the target call relationship, and dynamically tamper with the function parameter value based on the target tamper information, a fast and convenient test is achieved.

Benefits of technology

Shorten the test cycle and improve the testing efficiency. It does not require static declaration of function parameters, and completes software testing of different parameter values flexibly and conveniently.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114356745B_ABST
    Figure CN114356745B_ABST
Patent Text Reader

Abstract

The present disclosure provides a software testing method, apparatus, electronic device, and computer-readable storage medium. The method includes: obtaining source code to be tested, where the source code to be tested includes a function to be tested, and the function to be tested includes target parameters; compiling the source code to be tested to obtain an executable file, where during the compilation process, a target hook function for the function to be tested is injected into the source code to be tested, and the target hook function includes call relationship code; running the executable file to the function to be tested, and determining the target call relationship of the function to be tested according to the call relationship code; determining target tampering information according to the target call relationship; performing tampering assignment on the values of the target parameters of the function to be tested according to the target tampering information; and completing the testing of the source code to be tested according to the values of the tampered target parameters.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of testing technologies, and in particular, to a software testing method, an apparatus, an electronic device, and a computer-readable storage medium. Background Art

[0002] With the progress of computer science and technology and the rapid development of the software industry, software testing work has attracted more and more attention.

[0003] In function-level exception testing, testers usually need to tamper with specific parameter values of a function or the return value of the function to verify the service fault tolerance ability. In actual work, testers usually need to modify the specific parameter values or return values of the function in the source code in the form of static declarations, and then compile and run to complete the test. The above testing method not only prolongs the testing cycle, but also greatly wastes manpower and material resources, and in serious cases, it may delay the product launch.

[0004] Therefore, a testing method that can quickly and conveniently test functions is very important for software testing.

[0005] It should be noted that the information disclosed in the above background art section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to those of ordinary skill in the art. Summary of the Invention

[0006] Embodiments of the present disclosure provide a software testing method, an apparatus, an electronic device, and a computer-readable storage medium, which can conveniently complete the testing of the source code to be tested based on the target hook function and the target tampering information.

[0007] Other features and advantages of the present disclosure will become apparent through the following detailed description, or be learned in part through the practice of the present disclosure.

[0008] An embodiment of the present disclosure proposes a software testing method, which includes: obtaining the source code to be tested, where the source code to be tested includes a function to be tested, and the function to be tested includes target parameters; compiling the source code to be tested to obtain an executable file, where a target hook function for the function to be tested is injected into the source code to be tested during the compilation process, and the target hook function includes call relationship code; running the executable file to the function to be tested, and determining the target call relationship of the function to be tested according to the call relationship code; determining target tampering information according to the target call relationship; performing a tampering assignment on the value of the target parameter of the function to be tested according to the target tampering information; and completing the testing of the source code to be tested according to the tampered value of the target parameter.

[0009] An embodiment of the present disclosure provides a software testing device, which includes a test source code acquisition module, a compilation module, a call relationship determination module, a target tampering information acquisition module, a tampering assignment module, and a test module.

[0010] Among them, the test source code acquisition module can be configured to acquire the source code to be tested, where the source code to be tested includes functions to be tested, and the functions to be tested include target parameters. The compilation module can be configured to compile the source code to be tested to obtain an executable file, and during the compilation process, inject a target hook function for the function to be tested into the source code to be tested, where the target hook function includes call relationship code. The call relationship determination module can be configured to run the executable file to the function to be tested and determine the target call relationship of the function to be tested according to the call relationship code. The target tampering information acquisition module can be configured to determine target tampering information according to the target call relationship. The tampering assignment module can be configured to tamper with and assign the value of the target parameter of the function to be tested according to the target tampering information. The test module can be configured to complete the test of the source code to be tested according to the tampered value of the target parameter.

[0011] In some embodiments, the target parameter includes a target formal parameter, and the target tampering information includes formal parameter tampering information for the target formal parameter.

[0012] In some embodiments, the tampering assignment module may include: a formal parameter tampering unit and a formal parameter test unit.

[0013] Among them, the formal parameter tampering unit can be configured to tamper with and assign the value of the target formal parameter according to the formal parameter tampering information. The formal parameter test unit can be configured to run the function to be tested according to the tampered value of the target formal parameter and complete the test of the source code to be tested.

[0014] In some embodiments, the compilation module may include: a first syntax parsing unit, a first declaration unit, and a first assignment unit, and the formal parameter tampering unit may include: a first value tampering subunit and a value passing-in unit.

[0015] Among them, the first syntax parsing unit can be configured to perform syntax parsing on the function to be tested to obtain the target formal parameters of the function to be tested and the parameter types of the target formal parameters. The first declaration unit can be configured to declare a target formal parameter structure according to the parameter types of the target formal parameters, and the target formal parameter structure includes formal parameter objects corresponding one-to-one to the target formal parameters. The first assignment unit can be configured to perform initial assignment on the formal parameter objects. The first value tampering subunit can be configured to perform tampering assignment on the values of the formal parameter objects according to the formal parameter tampering information. The value passing-in unit can be configured to pass the tampered values of the formal parameter objects into the target formal parameters to tamper with the values of the target formal parameters.

[0016] In some embodiments, the target parameter includes a target return parameter, and the target tampering information includes return parameter tampering information for the target return parameter.

[0017] In some embodiments, the tampering assignment module may include: a true return value acquisition unit and a return value tampering unit.

[0018] Among them, the true return value acquisition unit can be configured to run the function to be tested to obtain the true return value of the target return parameter. The return value tampering unit can be configured to perform tampering assignment on the true return value of the target return parameter according to the return parameter tampering information.

[0019] In some embodiments, the compilation module may include: a second syntax parsing unit and a second declaration unit, and the return value tampering unit may include: a second assignment unit, a second value tampering unit, and a target return value determination unit.

[0020] Among them, the second syntax parsing unit can be configured to perform syntax parsing on the function to be tested to obtain the target return parameter of the function to be tested and the parameter type of the target return parameter. The second declaration unit can be configured to declare a target return parameter structure according to the parameter type of the target return parameter, and the target return parameter structure includes return parameter objects corresponding one-to-one to the target return parameters.

[0021] Among them, the second assignment unit can be configured to assign values to the return parameter objects according to the true return values of the target return parameters. The second value tampering unit can be configured to perform tampering assignment on the true return values of the return parameter objects according to the return parameter tampering information to obtain the tampered return values of the return parameter objects. The target return value determination unit can be configured to use the tampered return values of the return parameter objects as the target return values of the function to be tested.

[0022] In some embodiments, the target parameter includes a first parameter, the target tampering information includes first target tampering information for the first parameter, and the first target tampering information includes a first tampering value for the first parameter and first confirmation information indicating that the first parameter is of a first parameter type.

[0023] In some embodiments, the tampering assignment module may include: a first parameter determination unit and a first type judgment unit.

[0024] Among them, the first parameter determination unit may be configured to obtain the first parameter of the function to be tested and the parameter type of the first parameter through a reflection mechanism. The first type judgment unit may be configured to, if the parameter type of the first parameter is the first parameter type in the first confirmation information, perform tampering assignment on the first parameter with the first tampering value.

[0025] In some embodiments, the target parameter includes a second parameter, the second parameter includes a target parameter object, the target tampering information includes second target tampering information for the second parameter, the second target tampering information includes target sub-tampering information for the target parameter object, the second target tampering information includes second confirmation information indicating that the second parameter is of a second parameter type, and the target sub-tampering information includes third confirmation information indicating that the target parameter object is of a string type and a second tampering value for the target parameter object.

[0026] In some embodiments, the tampering assignment module may include: a second parameter determination unit, a target parameter object acquisition unit, and a second type determination unit.

[0027] Among them, the second parameter determination unit may be configured to obtain the second parameter of the function to be tested and the parameter type of the second parameter through a reflection mechanism. The target parameter object acquisition unit may be configured to, if the parameter type of the second parameter is the second parameter type, obtain the target parameter object and the parameter type of the target parameter object from the second parameter. The second type determination unit may be configured to, if the parameter type of the target parameter object is the string type in the target sub-tampering information, perform tampering assignment on the target parameter object with the second tampering value.

[0028] In some embodiments, the second parameter type is a key-value pair set map type.

[0029] In some embodiments, the target parameter object acquisition unit may include: a first sub-unit for acquiring the target parameter object, and the second type determination unit may include: a first judgment sub-unit, a first reflection sub-unit, and a third value tampering sub-unit.

[0030] Among them, the first sub-unit for obtaining the target parameter object can be configured to obtain the target parameter object from the second parameter according to the key mapIndex of the second parameter.

[0031] Among them, the first judgment sub-unit can be configured that if the parameter type of the target parameter object is not the string type in the target sub-tampering information, the target parameter object includes a first sub-parameter object, and the target sub-tampering information includes a first grandchild tampering information, the first grandchild tampering information includes a fourth confirmation information that the first sub-parameter object is of string type and a third tampering value for the first sub-parameter object. The first reflection sub-unit can be configured to obtain the first sub-parameter object and the parameter type of the first sub-parameter object from the target parameter object through a reflection mechanism. The third value tampering sub-unit can be configured to, if the parameter type of the first sub-parameter object is the string type in the fourth confirmation information, perform a tampering assignment on the first sub-parameter object through the third tampering value.

[0032] In some embodiments, the target parameter object obtaining unit may include: an initialization sub-unit, a parameter obtaining sub-unit after initialization.

[0033] Among them, the initialization sub-unit can be configured to perform an initialization operation on the second parameter if the second parameter does not have a key value. The parameter obtaining sub-unit after initialization can be configured to obtain the target parameter object and the parameter type of the target parameter object from the initialized second parameter.

[0034] In some embodiments, the second parameter type is a structure type.

[0035] In some embodiments, the target parameter object obtaining unit may include: a second sub-unit for obtaining the target object, and the second type determining unit may include: a second judgment sub-unit, a second reflection sub-unit, and a fourth value tampering sub-unit.

[0036] Among them, the second sub-unit for obtaining the target object can be configured to obtain the target parameter object from the second parameter according to the field name of the second parameter.

[0037] Wherein, the second determination subunit may be configured such that if the parameter type of the target parameter object is not the string type in the target sub-tampering information, the target parameter object includes a second sub-parameter object, and the target sub-tampering information includes a second grandchild tampering information, the second grandchild tampering information includes a fifth confirmation information that the second sub-parameter object is of the string type and a fourth tampering value for the second sub-parameter object. The second reflection subunit may be configured to obtain the second sub-parameter object and the parameter type of the second sub-parameter object from the target parameter object through a reflection mechanism. The fourth value tampering subunit may be configured to, if the parameter type of the second sub-parameter object is the string type in the fifth confirmation information, perform a tampering assignment on the second sub-parameter object through the fourth tampering value.

[0038] An embodiment of the present disclosure provides an electronic device, which includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the software testing method described in any one of the above.

[0039] An embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the software testing method described in any one of the above.

[0040] An embodiment of the present disclosure provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above software testing method.

[0041] The software testing method, device, electronic device and computer-readable storage medium provided by some embodiments of the present disclosure, on the one hand, inject a target hook function into a function to be tested in the source code to be tested, so as to be able to modify the value of the target parameter of the function to be tested when the source code to be tested is run; on the other hand, the value of the target parameter of the function to be tested can be dynamically tampered with through the target tampering information. Through the above method for software testing, the value of the target parameter in the function to be tested can be tampered with through the target tampering information according to the target hook function, and software testing with different parameter values can be completed flexibly and conveniently.

[0042] It should be understood that the above general description and the following detailed description are only exemplary and do not limit the present disclosure. Description of the Drawings

[0043] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure. The accompanying drawings described below are only some embodiments of the present disclosure, and those of ordinary skill in the art can obtain other accompanying drawings based on these accompanying drawings without creative efforts.

[0044] Figure 1 A schematic diagram showing an exemplary system architecture of a software testing method or a software testing device applied to an embodiment of the present disclosure.

[0045] Figure 2 A schematic structural diagram of a computer system applied to a software testing device shown according to an exemplary embodiment.

[0046] Figure 3 A flowchart of a software testing method shown according to an exemplary embodiment.

[0047] Figure 4 A schematic diagram of a compilation process shown according to an exemplary embodiment.

[0048] Figure 5 is Figure 3 A flowchart of step S5 in an exemplary embodiment in

[0049] Figure 6 A flowchart of a software testing method shown according to an exemplary embodiment.

[0050] Figure 7 is Figure 3 A flowchart of step S5 in an exemplary embodiment in

[0051] Figure 8 A flowchart of a software testing method shown according to an exemplary embodiment.

[0052] Figure 9 is Figure 3 A flowchart of step S5 in an exemplary embodiment in

[0053] Figure 10 is Figure 3 A flowchart of step S5 in an exemplary embodiment in

[0054] Figure 11 An architecture diagram of a software testing shown according to an exemplary embodiment.

[0055] Figure 12 A structural diagram of target tampering information shown according to an exemplary embodiment.

[0056] Figure 13It is a schematic structural diagram showing the processing of target tampering information according to an exemplary embodiment.

[0057] Figure 14 It is a block diagram of a software testing device shown according to an exemplary embodiment. Detailed implementation manners

[0058] Example embodiments will now be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art. Identical reference numerals in the figures denote the same or similar parts, and thus their repeated description will be omitted.

[0059] The features, structures, or characteristics described in this disclosure can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of the embodiments of this disclosure. However, those skilled in the art will realize that the technical solutions of this disclosure can be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, well-known methods, devices, implementations, or operations are not shown or described in detail to avoid obscuring aspects of this disclosure.

[0060] The accompanying drawings are only schematic illustrations of this disclosure, and identical reference numerals in the figures denote the same or similar parts, and thus their repeated description will be omitted. Some of the block diagrams shown in the drawings do not necessarily have to correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0061] The flowcharts shown in the accompanying drawings are only exemplary illustrations, not necessarily including all the contents and steps, nor necessarily executed in the described order. For example, some steps can be decomposed, and some steps can be combined or partially combined, so the actual execution order may change according to the actual situation.

[0062] In this specification, the terms "a", "one", "the", "said", and "at least one" are used to indicate the existence of one or more elements / components / etc.; the terms "comprising", "including", and "having" are used to mean an open inclusion and mean that there can be additional elements / components / etc. in addition to the listed elements / components / etc.; the terms "first", "second", and "third", etc. are only used as labels and are not a limitation on the quantity of their objects.

[0063] The following describes the exemplary embodiments of the present disclosure in detail with reference to the accompanying drawings.

[0064] Figure 1 A schematic diagram of an exemplary system architecture to which the software testing method or software testing apparatus according to the embodiments of the present disclosure can be applied is shown.

[0065] As Figure 1 shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0066] Users can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Among them, the terminal devices 101, 102, 103 may be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, wearable devices, virtual reality devices, smart homes, etc.

[0067] The server 105 may be a server that provides various services, such as a background management server that supports the devices operated by users using the terminal devices 101, 102, 103. The background management server may analyze and process data such as received requests, and feedback the processing results to the terminal devices.

[0068] The server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The present disclosure does not limit this.

[0069] Server 105 may, for example, obtain the source code to be tested, where the source code to be tested includes functions to be tested, and the functions to be tested include target parameters; Server 105 may, for example, compile the source code to be tested to obtain an executable file, where a target hook function for the function to be tested is injected into the source code to be tested during the compilation process, and the target hook function includes call relationship code; Server 105 may, for example, run the executable file to the function to be tested, and determine the target call relationship of the function to be tested according to the call relationship code; Server 105 determines target tampering information according to the target call relationship; Server 105 performs a tampering assignment on the value of the target parameter of the function to be tested according to the target tampering information; Server 105 completes the test of the source code to be tested according to the value of the target parameter after tampering.

[0070] It should be understood that Figure 1 the numbers of the terminal devices, networks, and servers in are merely illustrative. Server 105 may be a physical server or may be composed of multiple servers. According to actual needs, there may be any number of terminal devices, networks, and servers.

[0071] The following refers to Figure 2 , which shows a schematic structural diagram of a computer system 200 of a terminal device suitable for implementing the embodiments of the present application. Figure 2 The terminal device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of the present application.

[0072] As Figure 2 shown, the computer system 200 includes a central processing unit (CPU) 201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 202 or the program loaded from the storage section 208 into the random access memory (RAM) 203. In the RAM 203, various programs and data required for the operation of the system 200 are also stored. The CPU 201, ROM 202, and RAM 203 are connected to each other through a bus 204. The input / output (I / O) interface 205 is also connected to the bus 204.

[0073] The following components are connected to the I / O interface 205: an input section 206 including a keyboard, a mouse, etc.; an output section 207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, a modem, etc. The communication section 209 performs communication processing via a network such as the Internet. A drive 210 is also connected to the I / O interface 205 as required. A removable medium 211 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is installed on the drive 210 as required so that a computer program read therefrom is installed into the storage section 208 as required.

[0074] Specifically, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a computer-readable storage medium, and the computer program includes program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 209, and / or installed from the removable medium 211. When the computer program is executed by a central processing unit (CPU) 201, the above-described functions defined in the system of the present application are executed.

[0075] It should be noted that the computer-readable storage medium shown in this application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this application, the computer-readable storage medium can be any tangible medium that contains or stores a program, which can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable storage medium other than the computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0076] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0077] The modules and / or units and / or subunits involved in the embodiments of the present application can be implemented in software or in hardware. The described modules and / or units and / or subunits can also be provided in a processor. For example, it can be described as: a processor includes a sending unit, an obtaining unit, a determining unit, and a first processing unit. Among them, the names of these modules and / or units and / or subunits do not constitute a limitation on the modules and / or units and / or subunits themselves in some cases.

[0078] As another aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium can be included in the device described in the above embodiments; it can also exist alone without being assembled into the device. The above computer-readable storage medium carries one or more programs. When the above one or more programs are executed by the device, the functions that the device can implement include: obtaining the source code to be tested, where the source code to be tested includes the function to be tested, and the function to be tested includes target parameters; compiling the source code to be tested to obtain an executable file, where a target hook function for the function to be tested is injected into the source code to be tested during the compilation process, and the target hook function includes call relationship code; running the executable file to the function to be tested, determining the target call relationship of the function to be tested according to the call relationship code; determining target tampering information according to the target call relationship; tampering and assigning values to the values of the target parameters of the function to be tested according to the target tampering information; and completing the test of the source code to be tested according to the tampered values of the target parameters.

[0079] Figure 3 is a flowchart of a software testing method shown according to an exemplary embodiment. The method provided by the embodiments of the present disclosure can be executed by any electronic device with computing and processing capabilities. For example, the method can be executed by the server or terminal device in the above Figure 1 embodiments, or can be jointly executed by the server and the terminal device. In the following embodiments, the server is taken as an example of the execution subject for illustration, but the present disclosure is not limited thereto.

[0080] Referring to Figure 3 , the software testing method provided by the embodiments of the present disclosure may include the following steps.

[0081] In step S1, obtain the source code to be tested, where the source code to be tested includes the function to be tested, and the function to be tested includes target parameters.

[0082] In some embodiments, the source code to be tested may include multiple functions. During software testing, the multiple functions may be tested, for example, by modifying the values of multiple function parameters or the return values of multiple functions to test the fault tolerance of the source code to be tested, etc.

[0083] Embodiments of the present disclosure will take a certain function in the source code to be tested (which can be called the function to be tested) as an example to explain how to modify the parameter values or return values in the function to be tested. However, the present disclosure is not limited thereto. That is, those skilled in the art can modify the parameter values or return values of one or more functions in the source code to be tested according to the technical solutions provided by the embodiments of the present disclosure.

[0084] In some embodiments, the function to be tested may include multiple target parameters. The target parameter can be a formal parameter or a return parameter, and the present disclosure does not limit this.

[0085] In some embodiments, the source code to be tested can be a program written in the Go language, or a program written in the Java language, etc., or a program written in the C language, etc. The present disclosure does not limit the language for writing the source code to be tested.

[0086] In step S2, the source code to be tested is compiled to obtain an executable file, wherein a target hook function for the function to be tested is injected into the source code to be tested during the compilation process, and the target hook function includes call relationship code.

[0087] In some embodiments, the above-mentioned source code to be tested can be compiled by a target hook compilation tool (which can be a custom compilation tool according to requirements) to inject a target hook function for the function to be tested into the source code to be tested.

[0088] Next, an example of a function to be tested written in the Go language will be used to explain how to inject a target hook function for the function to be tested into the source code to be tested.

[0089] package main

[0090] import “fmt”

[0091] func testHook(name string) string { / / Has a formal parameter of type string: name

[0092] name = “hello” + name

[0093] return name; / / The number of return parameters is 1, and the type is string

[0094] }

[0095] func main(){

[0096] Fmt.Println(testHook("test"))

[0097] } / / Function to be tested

[0098] After being compiled by the target hook compilation tool, the function to be tested can be repeatedly mounted into the anonymous function of the code injected into the target hook function, and during the mounting process, the code logic of the function to be tested is guaranteed not to change, and the corresponding AST structure is added before and after the anonymous function. After decompiling the implanted AST structure, the following function to be tested with a hook can be obtained:

[0099] package main

[0100] import( / / Import file

[0101] "atenhance / toolbox"

[0102] "fmt" )

[0104] functestHook(name string)string{

[0105] var ps struct{ / / declare the target parameter structure ps

[0106] P0 string / / Declare multiple parameter objects according to the number of parameters and parameter types of the target parameter, and rename them to Pn in sequence (n is an integer starting from 0)

[0107] }

[0108] ps.P0 = name / / Assign the parameter object in the target parameter structure diagram and set the input parameter value

[0109] var rs struct{ / / Declare the target return parameter structure rs

[0110] R0 string / / Declare multiple parameter objects according to the number and type of the target return parameters in the function to be tested, and rename them to Rn in sequence (n is an integer starting from 0)

[0111] }

[0112] innerFunc:=fun(name string)string{ / / Mount the function to be tested in the anonymous function

[0113] name = "hello" + name / / Ensure that the code logic of the function to be tested remains unchanged return name

[0114] }

[0115] funCall := toolbox.NewFunCall().AnchorIn() / / Inject the target tampering information

[0116] defer funCall.AnchorOut()

[0117] expInjectSet := toolbox.NewExpInjectSet(funCall, &innerFunc, &ps, &rs) / / Determine the target call relationship

[0118] expInjectSet.Before() / / Pre-operation for exception injection (i.e., execute the function parameter value tampering logic before executing the anonymous function)

[0119] expInjectSet.Do() / / Execute the anonymous function (i.e., execute the logic of the function to be tested)

[0120] expInjectSet.After() / / Post-operation for exception injection (i.e., execute the function return value tampering logic after executing the anonymous function)

[0121] return rs.R0

[0122] }

[0123] func main() {

[0124] fmt.Println(testHook("test"))

[0125] }

[0126] As shown above, when compiling the source code to be tested, the function to be tested can be repeatedly mounted in an anonymous function, and it is ensured that the code logic of the function to be tested remains unchanged.

[0127] Among them, an anonymous function is a function that is not directly named when defined. It can be understood that when a non-anonymous function is defined, a function object and a scope object are created. Therefore, even if it is not called, the non-anonymous function will occupy memory. However, the anonymous function provided in this embodiment only temporarily creates a function object and a scope chain object when it is called, and immediately releases them after the call ends. Therefore, by mounting the function to be tested with an anonymous function in this embodiment, the memory space can be saved to a great extent.

[0128] It can be understood that when implementing this embodiment, the function to be tested can be mounted not only in an anonymous function but also in a non-anonymous function, and the present disclosure does not limit this.

[0129] In some embodiments, when compiling the source code to be tested, the target parameter structure and the target return parameter structure can be declared before the anonymous function.

[0130] Among them, the target parameter structure can be declared according to the number and parameter types of the parameters in the function to be tested. For example, parameter objects with the same number and corresponding types as the parameters in the function to be tested can be declared in the target parameter structure. For example, assume that a function to be tested includes two formal parameters, the first formal parameter is an integer type, and the second formal parameter is a string type. Then two parameters can be declared in the target parameter structure. The first parameter object corresponds to the parameter type of the first formal parameter in the function to be tested and can be declared as an integer type. The second parameter object corresponds to the parameter type of the second formal parameter in the function to be tested and can be declared as a string type.

[0131] In some embodiments, the target return parameter structure can also be declared according to the number and parameter types of the return parameters in the source code to be tested when compiling the source code to be tested. For example, parameter objects with the same number and corresponding types as the return parameters in the function to be tested can be declared in the target return parameter structure. For example, assume that a function to be tested includes two return parameters, the first return parameter is an integer type, and the second return parameter is a string type. Then two parameters can be declared in the target return parameter structure. The first parameter object corresponds to the parameter type of the first return parameter in the function to be tested and can be declared as an integer type. The second parameter object corresponds to the parameter type object of the second return parameter in the function to be tested and can be declared as a string type.

[0132] In some embodiments, during the process of compiling the source code to be tested, hook enhancement code can also be injected based on the source code to be tested, such as funCall:=toolbox.NewFunCall().AnchorIn(), defer funCall.AnchorOut(), expInjectSet:=toolbox.NewExpInjectSet(funCall,&innerFunc,&ps,&rs), expInjectSet.Before(), expInjectSet.Do(), expInjectSet.After(), return rs.R0 in the above example.

[0133] In some embodiments, the above compilation process can be summarized as Figure 4 the process shown.

[0134] In step S401, obtain the source code to be tested written in the Go language;

[0135] In step S402, perform code parsing on the source code to be tested through an Abstract Syntax Tree (AST) to obtain the AST structure of the source code to be tested.

[0136] In step S403, convert the AST structure of the source code to be tested.

[0137] In the above conversion process, on the one hand, it is necessary to mount the function to be tested into a certain function (such as an anonymous function); on the other hand, it is necessary to declare the target parameter structure according to the number and type of the formal parameters of the function to be tested before the anonymous function, and declare the target return parameter structure according to the number and type of the return parameters of the function to be tested; in addition, it is also necessary to inject some hook enhancement codes after the anonymous function.

[0138] In step S404, generate SSA (i.e., Static Single Assignment).

[0139] In step S405, generate machine code.

[0140] According to the above method, the compilation of the source code to be tested can be completed to obtain an executable file.

[0141] In step S3, run the executable file to the function to be tested, and determine the target call relationship of the function to be tested according to the call relationship code.

[0142] In some embodiments, when running the executable file to the function to be tested including enhancement codes, the target call relationship of the current function to be tested can be obtained.

[0143] It can be understood that the above target call relationship is only used to determine the injection point of the target hook function, and other messages such as a certain special output statement, a certain special parameter, etc. can also be used to determine the injection point of the hook function, and the present disclosure does not limit this.

[0144] In step S4, determine the target tampering information according to the target call relationship.

[0145] In some embodiments, the target tampering information can be obtained from the target database according to the target call relationship. It should be noted that the target database stores the tampering rules for each function of the target code to be tested, and the target tampering information applicable to the function to be tested can be determined from the target database according to the target call relationship.

[0146] In step S5, the value of the target parameter of the function to be tested is tampered and assigned according to the target tampering information.

[0147] In some embodiments, the target tampering information may include the tampering value for the specified parameter value. For example, the tampering value for modifying the first formal parameter in the function to be tested, etc.

[0148] In step S6, the test of the source code to be tested is completed according to the value of the target parameter after tampering.

[0149] In some embodiments, the value of the target parameter in the function to be tested can be tampered according to the information in the target tampering information, and then the test is performed according to the tampered parameter value to complete the test of the source code to be tested.

[0150] The software testing method provided by the embodiments of the present disclosure, on the one hand, injects a target hook function for the function to be tested in the source code to be tested, so as to be able to modify the value of the target parameter of the function to be tested when the source code to be tested is run; on the other hand, the value of the target parameter of the function to be tested can be dynamically tampered through the target tampering information. Through the above method for software testing, the value of the target parameter in the function to be tested can be tampered through the target tampering information by the target hook function, and the software testing with different parameter values can be completed flexibly and conveniently.

[0151] Figure 5 Yes Figure 3 It is the flowchart of step S5 in an exemplary embodiment. In this embodiment, the tampering logic of the function parameter value executed before the anonymous function is executed will be described.

[0152] In some embodiments, the target parameter of the function to be tested includes the target formal parameter, and the target tampering information may include the formal parameter tampering information for the target formal parameter.

[0153] Among them, the formal parameter tampering information for the target formal parameter can be defined in the following form:

[0154] call_func_name:called_func_name#tamper.params1.params2.

[0155] Among them, call_func_name represents the name of the calling function, called_func_name represents the name of the called function (such as the function to be tested), tamper represents that the abnormal injection operation is tampering, and params represents the parameters set for the abnormal injection, which can represent the probability of abnormal occurrence, the timing of abnormal occurrence, the tampering value corresponding to the abnormal occurrence, etc.

[0156] For example, the parameter tampering information of the target formal parameter may include: main.main:main.testHook#tamper.before, which is an instruction used to indicate that the parameter value tampering behavior is executed before the main.testHook function is called in the main.main function. That is, before the main.main calls the main.testHook function, the value of the target formal parameter of the function to be tested is tampered with.

[0157] For another example, the parameter tampering information of the target formal parameter may also include: main.main:main.testHook#tamper.probability, which is an instruction used to indicate the probability of the tampering behavior occurring; the parameter tampering information of the target formal parameter may also include main.main:main.testHook#tamper.P0, which is an instruction used to indicate tampering with the first parameter P0 in the target formal parameter structure; the parameter tampering information of the target formal parameter may include main.main:main.testHook#tamper.P1.Name, which is an instruction used to indicate tampering with the member variable Name of the second parameter P1 in the target formal parameter structure, and so on.

[0158] Reference Figure 5 , the above step S5 may include the following process.

[0159] In step S511, the value of the target formal parameter is tampered with and assigned according to the parameter tampering information.

[0160] In some embodiments, if the target tampering information includes the above instruction information for executing the injection parameter value tampering behavior before the function call, then the target tampering information will also include the parameter tampering information for the target formal parameter.

[0161] For example, the above parameter tampering information may include the following information:

[0162] main.main:main.testHook#tamper.probability / / indicates the probability of the parameter tampering behavior occurring.

[0163] main.main:main.testHook#tamper.P0 / / indicates tampering with the parameter value P0 (i.e., the first parameter in the formal parameter structure)

[0164] main.main:main.testHook#tamper.P1.Name / / indicates tampering with the member variable Name of the structure parameter P1 (i.e., the second parameter in the formal parameter structure).

[0165] main.main:main.testHook#tamper.P2.Learnmap.xiaoxue means to tamper with the value of the key xiaoxue in the key-value pair set map type parameter P2 (i.e., the third parameter in the formal parameter structure).

[0166] In some embodiments, the formal parameter tampering information may include not only the information specifying the parameter to be tampered with, but also the tampering value set for the formal parameter to be tampered with. For example, the formal parameter tampering information may include the information of tampering the above P0 parameter to 5, and the present disclosure does not limit this.

[0167] It can be understood that the above formal parameter tampering information is only for illustrative purposes, and those skilled in the art can easily set different tampering information for each source code to be tested through the technical solution provided by this embodiment, and the present disclosure does not limit this.

[0168] In some embodiments, the value of the target formal parameter can be modified according to the above formal parameter tampering information.

[0169] In step S512, the function to be tested is run according to the value of the target formal parameter after tampering, and the testing of the source code to be tested is completed.

[0170] In some embodiments, the function to be tested can be run according to the value of the formal parameter after tampering to complete the testing of the source code to be tested.

[0171] The technical solution provided by this embodiment can complete the testing of the source code to be tested according to the external formal parameter tampering information. In some embodiments, only by tampering with the formal parameter tampering information can different tests of the source code to be tested be completed, without statically declaring the formal parameters in the function and without recompiling the source code to be tested, which greatly reduces the testing cycle and improves the testing efficiency.

[0172] Figure 6 is a flowchart of a software testing method shown according to an exemplary embodiment. Refer to Figure 6 , the above software testing method may include the following steps.

[0173] In step S1, the source code to be tested is obtained, and the source code to be tested includes the function to be tested, and the function to be tested includes target parameters.

[0174] In some embodiments, Figure 3 Step S2 in may include steps S211 to S213, specifically as follows.

[0175] In step S211, perform syntax parsing on the function to be tested to obtain the target formal parameters of the function to be tested and the parameter types of the target formal parameters.

[0176] In some embodiments, when compiling the source code to be tested, it is necessary to perform AST syntax parsing on the source code to be tested. During the AST parsing process, the target formal parameters in the function to be tested and the parameter types of the target formal parameters can be obtained.

[0177] In step S212, declare a target formal parameter structure according to the parameter types of the target formal parameters. The target formal parameter structure includes formal parameter objects corresponding one by one to the target formal parameters.

[0178] In some embodiments, after obtaining the target formal parameters of the function to be tested and the parameter types of the target formal parameters, a target formal parameter structure can be determined according to the number and parameter types of the target formal parameters.

[0179] For example, parameter objects with the same number and corresponding types as the formal parameters in the function to be tested can be declared in the target formal parameter structure. For example, assume that a function to be tested includes two formal parameters. The first formal parameter is of integer type, and the second formal parameter is of string type. Then two parameters can be declared in the target formal parameter structure. The first parameter object corresponds to the parameter type of the first formal parameter in the function to be tested and can be declared as an integer. The second parameter object corresponds to the parameter type of the second formal parameter in the function to be tested and can be declared as a string.

[0180] In step S211, perform initial assignment to the formal parameter objects.

[0181] In some embodiments, after completing the declaration of the target formal parameter structure, it is also necessary to perform initial assignment to the formal parameter objects in the target formal parameter structure.

[0182] In step S3, run the executable file to the function to be tested, and determine the target call relationship of the function to be tested according to the call relationship code.

[0183] In step S4, determine the target tampering information according to the target call relationship.

[0184] In some embodiments, Figure 3 Step S5 in can include steps S5111 to S5112, specifically as follows.

[0185] In step S5111, perform tampering assignment to the values of the formal parameter objects according to the formal parameter tampering information.

[0186] In some embodiments, in the above formal parameter tampering information, the parameter to be tampered with in the target formal parameter can be specified. For example, the member variable Name of the structure parameter P1 (i.e., the second parameter in the target formal parameter structure) can be specified to have its value tampered with through the instruction main.main:main.testHook#tamper.P1.Name.

[0187] In some embodiments, in the above formal parameter tampering information, the tampered value after tampering the parameter to be tampered with can also be specified. For example, in the formal parameter tampering information, it can be specified that the value of the second parameter P1 in the target formal parameter structure is modified to the tampered value N (the type of N needs to be the same as the type of P1).

[0188] In step S5112, the value of the tampered formal parameter object is passed into the target formal parameter to tamper the value of the target formal parameter.

[0189] In some embodiments, the value of the tampered formal parameter object can be correspondingly passed into the target formal parameter as the input parameter of the function to be tested.

[0190] In step S512, the function to be tested is run according to the value of the tampered target formal parameter, and the testing of the source code to be tested is completed.

[0191] Figure 7 Yes Figure 3 It is the flowchart of step S5 in an exemplary embodiment. In this embodiment, the tampering logic of the function return value executed after the anonymous function is executed will be described.

[0192] In some embodiments, the target parameter of the function to be tested can include the target return parameter, and the target tampering information can include the return parameter tampering information for the target return parameter.

[0193] Among them, the return parameter tampering information of the target return parameter can be defined in the following form.

[0194] call_func_name:called_func_name#tamper.params1.params2.

[0195] Among them, call_func_name represents the name of the calling function, called_func_name represents the name of the called function (such as the function to be tested), tamper represents that the abnormal injection operation is tampering, and params represents the parameters set for the abnormal injection, which can represent the probability of abnormal occurrence, the timing of abnormal occurrence, the tampered value corresponding to the abnormal occurrence, etc.

[0196] For example, the return parameter tampering information of the target return parameter may further include: main.main:main.testHook#tamper.after, which is an instruction used to indicate that the parameter value tampering behavior is executed after the main.testHook function is called in the main.main function. That is, after the main.main calls the main.testHook function, the target return value of the function to be tested is tampered with.

[0197] For another example, the return parameter tampering information of the target return parameter may include: main.main:main.testHook#tamper.probability, which is an instruction used to indicate the probability of the tampering behavior occurring; the return parameter tampering information of the target return parameter may further include main.main:main.testHook#tamper.P0, which is an instruction used to indicate tampering with the first parameter P0 in the target return parameter structure; the return parameter tampering information of the target return parameter may further include main.main:main.testHook#tamper.P1.Name, which is an instruction used to indicate tampering with the member variable Name of the second parameter P1 in the target return parameter structure, and so on.

[0198] Reference Figure 7 , the above step S5 may include the following steps.

[0199] In step S521, run the function to be tested to obtain the true return value of the target return parameter.

[0200] In some embodiments, the function to be tested may be run to obtain the true return value. It can be understood that the function to be tested may be run according to the parameter values before tampering or according to the parameter values after tampering, and the present disclosure does not limit this.

[0201] In step S522, perform a tampering assignment on the true return value of the target return parameter according to the return parameter tampering information.

[0202] In some embodiments, if the target tampering information includes the information on executing the parameter value tampering behavior after a function call as described above, then the target tampering information will further include the return parameter tampering information for the target return parameter.

[0203] For example, the return parameter tampering information may include the following information:

[0204] main.main:main.testHook#tamper.probability / / Indicates the probability of the return value tampering behavior occurring.

[0205] main.main:main.testHook#tamper.R0 / / Indicates value tampering of the value of parameter R0 (i.e., the first return parameter in the target return parameter structure).

[0206] main.main:main.testHook#tamper.R1.Name / / Indicates value tampering of the member variable Name of parameter R1 (i.e., the second return parameter in the target return parameter structure).

[0207] main.main:main.testHook#tamper.P2.Learnmap.xiaoxue / / Indicates value tampering of the value of the key-value pair xiaoxue in the map-type return parameter R2 (i.e., the third return parameter in the target return parameter structure).

[0208] In some embodiments, the return parameter tampering information may include not only information specifying the return parameter to be tampered with, but also the tampered value set for the return parameter to be tampered with. For example, the return parameter tampering information may include information that tampers the above R0 parameter to 5.

[0209] It can be understood that the above return parameter tampering information is only for illustrative purposes. Those skilled in the art can easily set different tampering information for each source code to be tested through the technical solution provided in this embodiment, and the present disclosure places no restrictions thereon.

[0210] In some embodiments, the value of the target return parameter can be tampered with according to the above return parameter tampering information.

[0211] The technical solution provided in this embodiment can complete the test of the source code to be tested according to the external return parameter tampering information. In some embodiments, only by tampering with the return parameter tampering information can different tests of the source code to be tested be completed, without statically declaring the return parameters in the function and without recompiling the source code to be tested, which greatly reduces the test cycle and improves the test efficiency.

[0212] Figure 8 It is a flowchart of a software testing method shown according to an exemplary embodiment. Refer to Figure 8 , the above software testing method may include the following steps.

[0213] In step S1, obtain the source code to be tested, where the source code to be tested includes a function to be tested, and the function to be tested includes target parameters.

[0214] In some embodiments, Figure 3Step S2 may include steps S221 to S222, and the specific process is as follows.

[0215] In step S221, perform syntax parsing on the function to be tested to obtain the target return parameter of the function to be tested and the parameter type of the target return parameter.

[0216] In some embodiments, when compiling the source code to be tested, it is necessary to perform AST syntax parsing on the source code to be tested, and the target return parameter and the parameter type of the target return parameter in the function to be tested can be obtained during the parsing process.

[0217] In step S222, declare a target return parameter structure according to the parameter type of the target return parameter, and the target return parameter structure includes return parameter objects corresponding one-to-one to the target return parameter.

[0218] In some embodiments, after obtaining the target return parameter and the parameter type of the target return parameter of the function to be tested, a target return parameter structure can be declared according to the number and parameter type of the target return parameter.

[0219] For example, parameter objects with the same number and corresponding types as the return parameters in the function to be tested can be declared in the target return parameter structure. For example, assume that a function to be tested includes two return parameters, the first return parameter is an integer type, and the second return parameter is a string type. Then two parameters can be declared in the target return parameter structure. The first parameter object corresponds to the parameter type of the first return parameter in the function to be tested and can be declared as an integer type. The second parameter object corresponds to the parameter type object of the second return parameter in the function to be tested and can be declared as a string type.

[0220] In step S3, run the executable file to the function to be tested, and determine the target call relationship of the function to be tested according to the call relationship code.

[0221] In step S4, determine the target tampering information according to the target call relationship.

[0222] In some embodiments, Figure 3 Step S5 in may include the following steps S5221 to S5223, as follows.

[0223] In step S5221, assign values to the return parameter objects according to the actual return values of the target return parameters.

[0224] In some embodiments, an instruction for a parameter to be tampered with in the return parameter can be specified in the above return parameter tampering information. For example, the instruction main.main:main.testHook#tamper.P1.Name can be used to specify value tampering for the member variable Name of the parameter R1 (i.e., the second return parameter in the target return parameter structure).

[0225] In some embodiments, a tampered value after tampering the return parameter to be tampered with can also be specified in the above return parameter tampering information. For example, in the return parameter tampering information, it can be specified that the value of the second parameter R0 in the return parameter structure is modified to the tampered value N (the type of N needs to be the same as the type of R0).

[0226] In step S5222, the true return value of the return parameter object is tampered and assigned according to the return parameter tampering information to obtain the tampered return value of the return parameter object.

[0227] In step S5223, the tampered return value of the return parameter object is used as the target return value of the function to be tested.

[0228] In some embodiments, the tampered return value can be used as the return value of the function to be tested to run the source code to be tested.

[0229] In step S512, the function to be tested is run according to the value of the target formal parameter after tampering to complete the test of the source code to be tested.

[0230] Figure 9 Yes Figure 3 The flowchart of step S5 in an exemplary embodiment.

[0231] In some embodiments, the target parameter in the function to be tested in the source code to be tested may include a first parameter, the first parameter is of a first parameter type, and the first parameter type may be a parameter that cannot be nested and can be directly assigned and tampered with, such as a string, an integer, an unsigned integer, a floating point number, a character, a boolean, etc.

[0232] In some embodiments, the target tampering information can be a test rule set in advance according to the source code to be tested. For example, it is assumed that the tester knows that the function to be tested in the source code to be tested includes a parameter P0, and the parameter type of P0 is a string. Then the tester can set tampering information for the parameter P0 in the target tampering information. For example, it can be set to "tamper the value of the string-type parameter P0 to name".

[0233] In some embodiments, the target tampering information may include first target tampering information for a first parameter, and the first target tampering information may include a first tampering value for the first parameter and first confirmation information indicating that the first parameter is of a first parameter type.

[0234] Reference Figure 9 , the above step S3 may include the following steps.

[0235] In step S531, the first parameter of the function to be tested and the parameter type of the first parameter are obtained through the reflection mechanism.

[0236] In some embodiments, if the target tampering information includes first target tampering information for a first parameter, and the first target tampering information may include a first tampering value for the first parameter and first confirmation information indicating that the first parameter is of a first parameter type, then when the function to be tested is run, the parameter type of the first parameter can be obtained from the function to be tested through the reflection mechanism.

[0237] For example, when the source code to be tested is compiled, parameters such as P0 and P1 are declared for the target formal parameters of the function to be tested, and the first confirmation information in the target tampering information includes the information that "P0 is a string", then when the function to be tested is executed, the P0 parameter and the parameter type of the P0 parameter need to be obtained from the function to be tested through the reflection mechanism.

[0238] In step S532, if the parameter type of the first parameter is the first parameter type in the first confirmation information, the first parameter is tampered with and assigned a value using the first tampering value.

[0239] In some embodiments, if it is determined that the parameter type of the first parameter obtained from the currently running function to be tested is the same as the parameter type of the first parameter in the first confirmation information and both are of the first parameter type, then the first parameter is directly assigned a value using the first tampering value; if it is determined that the parameter type of the first parameter obtained from the currently running function to be tested is different from the parameter type of the first parameter in the first confirmation information, then the first parameter is not tampered with.

[0240] Figure 10 Yes Figure 3 The flowchart of step S5 in an exemplary embodiment.

[0241] In some embodiments, the target parameter in the function to be tested in the source code to be tested may include a second parameter, and the second parameter is of a second parameter type, and the second parameter type may be a parameter type that can be nested, such as a structure type or a key-value pair set map type.

[0242] In some embodiments, the second parameter in the function to be tested of the source code to be tested may be a nestable parameter type (such as a struct structure type or a key-value pair set map type), and the second parameter may include a target parameter object. Then, when setting the test rule for the second parameter, the tester may set the second target tampering information for the second parameter in the target tampering information. The second target tampering information may include the target sub-tampering information for the target parameter object, and the second target tampering information may include the second confirmation information that the second parameter is of the second parameter type. The target sub-tampering information includes the third confirmation information that the target parameter object is of the string type and the second tampering value for the target parameter object.

[0243] For example, assume that the second parameter in the function to be tested is the structure diagram parameter P1, and the target parameter object in the second parameter is P1.name, and this target parameter object is of the string type. Then, the target tampering information may include the second confirmation information determining that the second parameter is of the structure type, and should also include the target sub-tampering information for the target parameter object. The target sub-tampering information should include the third confirmation information determining that the target parameter object is of the string type, and the second tampering value for the target parameter object.

[0244] Reference Figure 10 , the above step S5 may include the following steps.

[0245] In step S541, the second parameter of the function to be tested and the parameter type of the second parameter are obtained through the reflection mechanism.

[0246] In some embodiments, when running the function to be tested, the parameter type of the second parameter can be obtained from the function to be tested through the reflection mechanism.

[0247] In step S542, if the parameter type of the second parameter is the second parameter type, the target parameter object and the parameter type of the target parameter object are obtained from the second parameter.

[0248] In some embodiments, if the parameter type of the second parameter is the same as the second parameter type in the second confirmation information in the target tampering information, the target parameter object and the parameter type of the target parameter object are continuously obtained from the second parameter.

[0249] In step S543, if the parameter type of the target parameter object is the string type in the target sub-tampering information, the target parameter object is tampered with and assigned a value through the second tampering value.

[0250] In some embodiments, if the parameter type of the target parameter object is the same as the string type in the third confirmation information, the target parameter object can be directly tampered with using the second tampering value. If the parameter type of the target parameter object is not the same as the string type in the third confirmation information, no tampering operation is performed on the target parameter object.

[0251] In some embodiments, the function to be tested can include both target formal parameters and a target return parameter. The target formal parameters can include a first target parameter, a second target parameter, and a third target parameter. The first target parameter is of string type, the second target parameter is of struct type, and the third target parameter is of map type (a set of key-value pairs). The second target parameter also includes member variables Name and Age, and the third target parameter can include member variables xiaoxue and daxue.

[0252] This embodiment will illustrate software testing by taking the tampering of target formal parameters as an example. Since the operation of tampering with the target return parameter is similar to the operation of tampering with the value of the target formal parameter, the present disclosure does not limit this.

[0253] In some embodiments, when compiling the function to be tested, a target formal parameter structure can be declared for the target formal parameters of the function to be tested. The target formal parameter structure includes a first parameter object P0, a second parameter object P1, and a third parameter object P3. Among them, the first parameter object P0 can be declared as the parameter type of the first target parameter (i.e., string type), the second parameter object P1 can be declared as the parameter type of the second target parameter (i.e., struct type), and the third parameter object P2 can be declared as the parameter type of the third target parameter (i.e., map type). Among them, the second parameter object P1 can also include member variables P1.Name and P1.Age corresponding to the types and numbers of the member variables of the second target parameter, and the third parameter object can also include member variables P2.xiaoxue and P2.daxue corresponding to the types and numbers of the member variables of the third parameter.

[0254] In some embodiments, before software testing, testers can set tampering information according to the function to be tested. As Figure 11 shown, tester 124 can set the target tampering information through target platform 123 to specify the tampering value of the parameter to be tampered with in the function to be tested and the corresponding tampering value for the parameter to be tampered with. In some embodiments, after the tester completes setting the target tampering information, the target tampering information is stored in cache database 112 so that executable file 111 can obtain it.

[0255] For the above function to be tested, the tester can set the target tampering information as a map type of key-value pair set, or as a struct type or other types that allow nested information setting. The present disclosure places no restrictions on this.

[0256] In this embodiment, it will be described by setting the target tampering information as a map type of key-value pair set. As Figure 12 shown, each layer of information in the target tampering information may include formal parameter tampering information 120.

[0257] Among them, 120 is the root node, and in this root node, it may include:

[0258] 1. main.main:main.testHook#tamper.before; / / Formal parameter tampering instruction for tampering the target formal parameter before function call.

[0259] 2. main.main:main.testHook#tamper.P. / / Formal parameter tampering instruction for tampering parameter Pn corresponding to the target formal parameter (n can be 0, 1, 2).

[0260] Child nodes 121, 122, and 123 are the first-layer tampering information, and their specific content is:

[0261] 121. main.main:main.testHook#tamper.P0; / / Formal parameter tampering information for tampering parameter P0

[0262] 122. main.main:main.testHook#tamper.P1; / / Formal parameter tampering information for tampering parameter P1

[0263] 123. main.main:main.testHook#tamper.P2. / / Formal parameter tampering information for tampering parameter P1

[0264] Grandchild nodes 1221, 1222, 1231, and 1232 are the second-layer tampering information, and their specific content is:

[0265] 1221. main.main:main.testHook#tamper.P1.Name; / / Formal parameter tampering information for modifying parameter P1.Name in parameter P1

[0266] 1222. main.main: main.testHook#tamper.P1.Age; / / Tampering information for formal parameters to modify the member variable P1.Age in parameter P1

[0267] 1231. main.main: main.testHook#tamper.P2.xiaoxue; / / Tampering information for formal parameters to modify the member variable P2.xiaoxu in parameter P2

[0268] 1232. main.main: main.testHook#tamper.P2.daxue. / / Tampering information for formal parameters to modify the member variable P2.daxue in parameter P2

[0269] It can be understood that each piece of tampering information for formal parameters can include confirmation information for type judgment of the corresponding parameter. For example, in the tampering information for formal parameters main.main: main.testHook#tamper.P1, it can include confirmation information that parameter P1 is a structure parameter, and in the tampering information for formal parameters main.main: main.testHook#tamper.P2, it can include confirmation information that parameter P2 is a key-value pair set map type parameter.

[0270] Next, this embodiment will be combined with Figure 12 、 Figure 13 to illustrate the software testing method.

[0271] Figure 13 is a schematic structural diagram showing the processing of target tampering information according to an exemplary embodiment.

[0272] In some embodiments, when the compilation of the function to be tested is completed (the injection of the target hook function for the function to be tested has been completed), and the executable file is run to the function to be tested, the target call relationship of the function to be tested can be determined according to the call relationship code in the function to be tested, and then the value tampering of the target formal parameters of the software to be tested can be completed according to the following steps.

[0273] In step S1301, the target tampering information 120 is obtained from the cache database 130 according to the target call relationship.

[0274] In step S1302, if there is a formal parameter tampering instruction (main.main:main.testHook#tamper.before) in the target tampering information that tampers with the value of the target formal parameter, then obtain the formal parameter tampering rules 121, 122, and 123 for the formal parameter Pn (n is 0, 1, 2) from the target tampering information.

[0275] Through the processing of step S1303 and step S1304, the current value of n becomes 0.

[0276] In step S1306, obtain the formal parameter tampering rule corresponding to the parameter Pn. Since the current n is 0, it is necessary to obtain the formal parameter tampering rule 121 corresponding to the parameter P0.

[0277] In some embodiments, since the current formal parameter tampering rule 121 is data of string type, steps S1306 to S1307 can be executed to obtain the parameter object in the formal parameter tampering rule 121.

[0278] In steps S1308 to S1309, since the parameter object in the formal parameter tampering rule 121 is of string type, the value of P0 can be tampered with according to the tampering value corresponding to the parameter in the formal parameter tampering rule 121.

[0279] In some embodiments, after completing the tampering of the parameter P0, steps S1304 and S1305 need to be executed to continue obtaining the formal parameter tampering rule 122 corresponding to the parameter P1.

[0280] In some embodiments, since the current formal parameter tampering information 122 is a rule set for the second target parameter of the structure type, the formal parameter tampering information 122 should be set as a nestable key-value pair set map type data. Therefore, steps S1310 to S1311 can be executed to obtain the corresponding parameter object in the formal parameter tampering rule 122.

[0281] In step S1311, obtain the parameter object according to the key mapIndex.

[0282] In some embodiments, since the parameter type of the parameter object in the formal parameter tampering information 122 is a key-value pair set map type, steps S1313 and S1305 need to be continued to obtain the formal parameter tampering information 1221 and 1222 from the formal parameter tampering information 122, and then according to Figure 13 Continue to make a judgment until the formal parameter tampering information is of string type, and then perform a value tampering operation on the corresponding parameter Pn according to the tampering value in the formal parameter tampering information.

[0283] It can be understood that after processing the formal parameter tampering rule 122, it is also necessary to process the formal parameter tampering rule 123. The processing process is similar to that of the formal parameter tampering rule 122, and the present disclosure does not limit this.

[0284] Figure 14 is a block diagram of a software testing device shown according to an exemplary embodiment. Refer to Figure 14 The software testing device 1400 provided by the embodiments of the present disclosure may include: a test source code acquisition module 1401, a compilation module 1402, a call relationship determination module 1403, a target tampering information acquisition module 1404, a tampering assignment module 1405, and a test module 1406.

[0285] Among them, the test source code acquisition module 1401 may be configured to acquire the source code to be tested, and the source code to be tested includes the function to be tested, and the function to be tested includes target parameters. The compilation module 1402 may be configured to compile the source code to be tested to obtain an executable file, and during the compilation process, inject a target hook function for the function to be tested into the source code to be tested, and the target hook function includes call relationship code. The call relationship determination module 1403 may be configured to run the executable file to the function to be tested, and determine the target call relationship of the function to be tested according to the call relationship code. The target tampering information acquisition module 1404 may be configured to determine target tampering information according to the target call relationship. The tampering assignment module 1405 may be configured to perform tampering assignment on the values of the target parameters of the function to be tested according to the target tampering information. The test module 1406 is configured to complete the test of the source code to be tested according to the values of the tampered target parameters.

[0286] In some embodiments, the target parameters include target formal parameters, and the target tampering information includes formal parameter tampering information for the target formal parameters.

[0287] In some embodiments, the tampering assignment module 1405 may include: a formal parameter tampering unit and a formal parameter test unit.

[0288] Among them, the formal parameter tampering unit may be configured to perform tampering assignment on the values of the target formal parameters according to the formal parameter tampering information. The formal parameter test unit may be configured to run the function to be tested according to the values of the tampered target formal parameters to complete the test of the source code to be tested.

[0289] In some embodiments, the compilation module 1402 may include: a first syntax parsing unit, a first declaration unit, and a first assignment unit, and the formal parameter tampering unit may include: a first value tampering subunit and a value passing unit.

[0290] Among them, the first syntax parsing unit can be configured to perform syntax parsing on the function to be tested, so as to obtain the target formal parameters of the function to be tested and the parameter types of the target formal parameters. The first declaration unit can be configured to declare a target formal parameter structure according to the parameter types of the target formal parameters, and the target formal parameter structure includes formal parameter objects corresponding one-to-one to the target formal parameters. The first assignment unit can be configured to perform initial assignment on the formal parameter objects. The first value tampering subunit can be configured to perform tampering assignment on the values of the formal parameter objects according to the formal parameter tampering information. The value passing-in unit can be configured to pass the tampered values of the formal parameter objects into the target formal parameters, so as to tamper the values of the target formal parameters.

[0291] In some embodiments, the target parameter includes a target return parameter, and the target tampering information includes return parameter tampering information for the target return parameter.

[0292] In some embodiments, the tampering assignment module 1405 may include: a true return value acquisition unit and a return value tampering unit.

[0293] Among them, the true return value acquisition unit can be configured to run the function to be tested to obtain the true return value of the target return parameter. The return value tampering unit can be configured to perform tampering assignment on the true return value of the target return parameter according to the return parameter tampering information.

[0294] In some embodiments, the compilation module 1402 may include: a second syntax parsing unit and a second declaration unit, and the return value tampering unit may include: a second assignment unit, a second value tampering unit, and a target return value determination unit.

[0295] Among them, the second syntax parsing unit can be configured to perform syntax parsing on the function to be tested, so as to obtain the target return parameter of the function to be tested and the parameter type of the target return parameter. The second declaration unit can be configured to declare a target return parameter structure according to the parameter type of the target return parameter, and the target return parameter structure includes return parameter objects corresponding one-to-one to the target return parameters.

[0296] Among them, the second assignment unit can be configured to assign values to the return parameter objects according to the true return values of the target return parameters. The second value tampering unit can be configured to perform tampering assignment on the true return values of the return parameter objects according to the return parameter tampering information to obtain the tampered return values of the return parameter objects. The target return value determination unit can be configured to use the tampered return values of the return parameter objects as the target return values of the function to be tested.

[0297] In some embodiments, the target parameter includes a first parameter, the target tampering information includes first target tampering information for the first parameter, and the first target tampering information includes a first tampering value for the first parameter and first confirmation information indicating that the first parameter is of a first parameter type.

[0298] In some embodiments, the tampering assignment module 1405 may include: a first parameter determination unit and a first type determination unit.

[0299] Among them, the first parameter determination unit may be configured to obtain the first parameter of the function to be tested and the parameter type of the first parameter through a reflection mechanism. The first type determination unit may be configured to, if the parameter type of the first parameter is the first parameter type in the first confirmation information, assign a tampering value to the first parameter through the first tampering value.

[0300] In some embodiments, the target parameter includes a second parameter, the second parameter includes a target parameter object, the target tampering information includes second target tampering information for the second parameter, the second target tampering information includes target sub-tampering information for the target parameter object, the second target tampering information includes second confirmation information indicating that the second parameter is of a second parameter type, and the target sub-tampering information includes third confirmation information indicating that the target parameter object is of a string type and a second tampering value for the target parameter object.

[0301] In some embodiments, the tampering assignment module 1405 may include: a second parameter determination unit, a target parameter object acquisition unit, and a second type determination unit.

[0302] Among them, the second parameter determination unit may be configured to obtain the second parameter of the function to be tested and the parameter type of the second parameter through a reflection mechanism. The target parameter object acquisition unit may be configured to, if the parameter type of the second parameter is the second parameter type, obtain the target parameter object and the parameter type of the target parameter object from the second parameter. The second type determination unit may be configured to, if the parameter type of the target parameter object is the string type in the target sub-tampering information, assign a tampering value to the target parameter object through the second tampering value.

[0303] In some embodiments, the second parameter type is a key-value pair set map type.

[0304] In some embodiments, the target parameter object acquisition unit may include: a first sub-unit for acquiring a target parameter object, and the second type determination unit may include: a first judgment sub-unit, a first reflection sub-unit, and a third value tampering sub-unit.

[0305] Among them, the target parameter object obtaining the first subunit can be configured to obtain the target parameter object from the second parameter according to the key mapIndex of the second parameter.

[0306] Among them, the first determination subunit can be configured to if the parameter type of the target parameter object is not the string type in the target sub-tampering information, the target parameter object includes a first sub-parameter object, and the target sub-tampering information includes a first grandchild tampering information, the first grandchild tampering information includes a fourth confirmation information that the first sub-parameter object is of the string type and a third tampering value for the first sub-parameter object. The first reflection subunit can be configured to obtain the first sub-parameter object and the parameter type of the first sub-parameter object from the target parameter object through a reflection mechanism. The third value tampering subunit can be configured to if the parameter type of the first sub-parameter object is the string type in the fourth confirmation information, then perform a tampering assignment on the first sub-parameter object through the third tampering value.

[0307] In some embodiments, the target parameter object obtaining unit may include: an initialization subunit, a parameter obtaining subunit after initialization.

[0308] Among them, the initialization subunit can be configured to perform an initialization operation on the second parameter if the second parameter does not have a key value. The parameter obtaining subunit after initialization can be configured to obtain the target parameter object and the parameter type of the target parameter object from the initialized second parameter.

[0309] In some embodiments, the second parameter type is a structure type.

[0310] In some embodiments, the target parameter object obtaining unit may include: a second target object obtaining subunit, and the second type determining unit may include: a second determination subunit, a second reflection subunit, and a fourth value tampering subunit.

[0311] Among them, the second target object obtaining subunit can be configured to obtain the target parameter object from the second parameter according to the field name of the second parameter.

[0312] Among them, the second determination subunit may be configured such that if the parameter type of the target parameter object is not the string type in the target sub-tampering information, the target parameter object includes a second sub-parameter object, and the target sub-tampering information includes a second grandchild tampering information, the second grandchild tampering information includes a fifth confirmation information that the second sub-parameter object is of the string type and a fourth tampering value for the second sub-parameter object. The second reflection subunit may be configured to obtain the second sub-parameter object and the parameter type of the second sub-parameter object from the target parameter object through a reflection mechanism. The fourth value tampering subunit may be configured to, if the parameter type of the second sub-parameter object is the string type in the fifth confirmation information, perform a tampering assignment on the second sub-parameter object through the fourth tampering value.

[0313] Since each functional module of the software testing apparatus 1400 according to the exemplary embodiments of the present disclosure corresponds to the steps of the exemplary embodiments of the above software testing method, they will not be described in detail herein.

[0314] Through the description of the above embodiments, those skilled in the art can easily understand that the exemplary embodiments described herein can be implemented by software or by a combination of software and necessary hardware. Therefore, the technical solutions of the embodiments of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including several instructions for causing a computing device (such as a personal computer, a server, a mobile terminal, or a smart device, etc.) to execute the method according to the embodiments of the present disclosure, such as Figure 3 one or more of the steps shown.

[0315] In addition, the above drawings are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, rather than for limiting purposes. It is easy to understand that the processes shown in the above drawings do not indicate or limit the time sequence of these processes. Additionally, it is also easy to understand that these processes can be executed synchronously or asynchronously in, for example, multiple modules.

[0316] Those skilled in the art will readily think of other embodiments of the present disclosure after considering the specification and practicing the disclosure herein. The present disclosure aims to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common general knowledge or conventional technical means in the technical field not claimed in the present disclosure. The specification and embodiments are only regarded as exemplary, and the true scope and spirit of the present disclosure are pointed out by the claims.

[0317] It should be understood that the present disclosure is not limited to the detailed structures, drawing methods, or implementation methods shown herein. On the contrary, the present disclosure is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

Claims

1. A software testing method, characterized in that, Including: Obtain the source code to be tested, which includes the function to be tested. The function to be tested includes target parameters, and the target parameters include target formal parameters or target return parameters; Compile the source code to be tested to obtain an executable file. During the compilation process, inject a target hook function for the function to be tested into the source code to be tested and mount the function to be tested into an anonymous function. Before the anonymous function, declare a target formal parameter structure according to the number and parameter types of the target formal parameters in the function to be tested, or, before the anonymous function, declare a target return parameter structure according to the number and parameter types of the target return parameters in the function to be tested. The target hook function includes call relationship code; Run the executable file to the function to be tested, and determine the target call relationship of the function to be tested according to the call relationship code; Determine the target tampering information according to the target call relationship; Tamper with and assign values to the values of the target parameters of the function to be tested according to the target tampering information; Complete the test of the source code to be tested according to the values of the target parameters after tampering.

2. The method according to claim 1, wherein The target tampering information includes formal parameter tampering information for the target formal parameters; wherein, tampering with and assigning values to the values of the target parameters of the function to be tested according to the target tampering information includes: Tamper with and assign values to the values of the target formal parameters according to the formal parameter tampering information; Run the function to be tested according to the values of the target formal parameters after tampering, and complete the test of the source code to be tested.

3. The method according to claim 2, wherein Compile the source code to be tested to obtain an executable file. During the compilation process, injecting a target hook function for the function to be tested into the source code to be tested includes: Perform syntax parsing on the function to be tested to obtain the target formal parameters of the function to be tested and the parameter types of the target formal parameters; Declare a target formal parameter structure according to the parameter types of the target formal parameters. The target formal parameter structure includes formal parameter objects corresponding one-to-one to the target formal parameters; Perform initial assignment to the formal parameter objects; Wherein, tampering with and assigning values to the values of the target formal parameters according to the formal parameter tampering information includes: Tamper with and assign values to the values of the formal parameter objects according to the formal parameter tampering information; Pass the values of the formal parameter objects after tampering into the target formal parameters to tamper with the values of the target formal parameters.

4. The method according to claim 1, wherein The target tampering information includes return parameter tampering information for the target return parameters; wherein, tampering with and assigning values to the values of the target parameters of the function to be tested according to the target tampering information includes: Run the function to be tested to obtain the true return value of the target return parameter; Tamper with and assign values to the true return value of the target return parameter according to the return parameter tampering information.

5. The method according to claim 4, wherein Compile the source code to be tested to obtain an executable file. During the compilation process, injecting a target hook function for the function to be tested into the source code to be tested includes: Perform syntax parsing on the function to be tested to obtain the target return parameter of the function to be tested and the parameter type of the target return parameter; Declare a target return parameter structure according to the parameter type of the target return parameter, where the target return parameter structure includes return parameter objects corresponding one-to-one to the target return parameters; Among them, tampering and assigning the true return value of the target return parameter according to the return parameter tampering information includes: Assign a value to the return parameter object according to the true return value of the target return parameter; Tamper and assign the true return value of the return parameter object according to the return parameter tampering information to obtain the tampered return value of the return parameter object; Use the tampered return value of the return parameter object as the target return value of the function to be tested.

6. The method according to claim 1, wherein The target parameter includes a first parameter, the target tampering information includes first target tampering information for the first parameter, and the first target tampering information includes a first tampering value for the first parameter and first confirmation information that the first parameter is of a first parameter type; among them, tampering and assigning the value of the target parameter of the function to be tested according to the target tampering information includes: Obtain the first parameter of the function to be tested and the parameter type of the first parameter through the reflection mechanism; If the parameter type of the first parameter is the first parameter type in the first confirmation information, then tamper and assign the first parameter with the first tampering value.

7. The method according to claim 1, wherein The target parameter includes a second parameter, the second parameter includes a target parameter object, the target tampering information includes second target tampering information for the second parameter, the second target tampering information includes target sub-tampering information for the target parameter object, the second target tampering information includes second confirmation information that the second parameter is of a second parameter type, and the target sub-tampering information includes third confirmation information that the target parameter object is of a string type and a second tampering value for the target parameter object; among them, tampering and assigning the value of the target parameter of the function to be tested according to the target tampering information includes: Obtain the second parameter of the function to be tested and the parameter type of the second parameter through the reflection mechanism; If the parameter type of the second parameter is the second parameter type, then obtain the target parameter object and the parameter type of the target parameter object from the second parameter; If the parameter type of the target parameter object is the string type in the target sub-tampering information, then tamper and assign the target parameter object with the second tampering value.

8. The method according to claim 7, wherein The second parameter type is a key-value pair set map type; among them, obtaining the target parameter object and the parameter type of the target parameter object from the second parameter includes: Obtain the target parameter object from the second parameter according to the key mapIndex of the second parameter; Among them, if the parameter type of the target parameter object is the string type in the target sub-tampering information, tampering and assigning the target parameter object with the second tampering value includes: If the parameter type of the target parameter object is not the string type in the target sub-tampering information, the target parameter object includes a first sub-parameter object, and the target sub-tampering information includes a first grandchild tampering information, the first grandchild tampering information includes a fourth confirmation information that the first sub-parameter object is of string type and a third tampering value for the first sub-parameter object; Obtaining the first sub-parameter object and the parameter type of the first sub-parameter object from the target parameter object through the reflection mechanism; If the parameter type of the first sub-parameter object is the string type in the fourth confirmation information, tampering and assigning the first sub-parameter object with the third tampering value.

9. The method according to claim 8, wherein If the parameter type of the second parameter is the second parameter type, obtaining the target parameter object and the parameter type of the target parameter object from the second parameter includes: If the second parameter does not have a key value, performing an initialization operation on the second parameter; Obtaining the target parameter object and the parameter type of the target parameter object from the initialized second parameter.

10. The method according to claim 7, wherein The second parameter type is a structure type; among them, obtaining the target parameter object and the parameter type of the target parameter object from the second parameter includes: Obtaining the target parameter object from the second parameter according to the field name of the second parameter; Among them, if the parameter type of the target parameter object is the string type in the target sub-tampering information, tampering and assigning the target parameter object with the second tampering value includes: If the parameter type of the target parameter object is not the string type in the target sub-tampering information, the target parameter object includes a second sub-parameter object, and the target sub-tampering information includes a second grandchild tampering information, the second grandchild tampering information includes a fifth confirmation information that the second sub-parameter object is of string type and a fourth tampering value for the second sub-parameter object; Obtaining the second sub-parameter object and the parameter type of the second sub-parameter object from the target parameter object through the reflection mechanism; If the parameter type of the second sub-parameter object is the string type in the fifth confirmation information, tampering and assigning the second sub-parameter object with the fourth tampering value.

11. A software testing device, characterized in that, Including: A test source code acquisition module, configured to acquire a source code to be tested, the source code to be tested includes a function to be tested, the function to be tested includes a target parameter, and the target parameter includes a target formal parameter or a target return parameter; A compilation module, configured to compile the source code to be tested to obtain an executable file, wherein during the compilation process, a target hook function for the function to be tested is injected into the source code to be tested and the function to be tested is mounted into an anonymous function, and before the anonymous function, a target formal parameter structure is declared according to the number and parameter types of the target formal parameters in the function to be tested, or, before the anonymous function, a target return parameter structure is declared according to the number and parameter types of the target return parameters in the function to be tested, and the target hook function includes call relationship code; A call relationship determination module, configured to run the executable file to the function to be tested and determine the target call relationship of the function to be tested according to the call relationship code; A target tampering information acquisition module, configured to determine target tampering information according to the target call relationship; A tampering assignment module, configured to perform tampering assignment on the values of the target parameters of the function to be tested according to the target tampering information; A testing module, configured to complete the testing of the source code to be tested according to the values of the tampered target parameters.

12. An electronic device, characterized in that, Comprising: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-10.

13. A computer-readable storage medium having a computer program stored thereon, characterized in that, The program, when executed by a processor, implements the method according to any one of claims 1-10.

14. A computer program product, the computer program product comprising computer instructions, characterized in that, Execute the computer instruction to implement the method according to any one of claims 1-10.

Citation Information

Patent Citations

  • Software test method and system

    CN104834590A

  • A hook method and a terminal device

    CN106407800A