Code testing method and device, equipment, storage medium and program product

By determining the upper calling link of the feature method in the project code and finding the target protection structure, the problem that traditional code testing methods cannot cover all operation paths that may cause application crashes is solved, and a higher code testing accuracy is achieved.

CN119718882AActive Publication Date: 2025-03-28TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411691927.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-03-28
Estimated Expiration
2044-11-25

AI Technical Summary

Technical Problem

Traditional code testing methods, such as monkey testing, cannot cover all operation paths that may cause the feature method to enter the parameter object to be null, resulting in low code testing accuracy.

Method used

By determining the upper-layer call link of the feature method in the project code to be tested and looking for the target protection structure in the link, we can determine whether the feature structure has the risk of causing the application to crash.

Benefits of technology

This method can cover all operation paths that may cause the feature method to enter the parameter object to be null, which significantly improves the accuracy of code testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718882A_ABST
    Figure CN119718882A_ABST
Patent Text Reader

Abstract

The invention relates to a code testing method and device, equipment, a storage medium and a program product, and relates to the technical field of computers. The method comprises the following steps: determining at least one feature method contained in a to-be-tested item code; for each feature method, determining a feature structure for calling the feature method in the project code; if the target protection structure for the feature parameters of the feature method does not exist in the declaration method where the feature method is located, searching for an upper layer calling link of the feature method in the project code; and if the upper-layer calling link is not found or the target protection structure does not exist in the found upper-layer calling link, judging that the feature structure has a risk of causing the application program corresponding to the item code to crash. By adopting the method, the code testing accuracy can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code testing method, device, equipment, storage medium and program product. Background Art

[0002] A feature method is any method in the code that cannot take nil (null value) as an input parameter object. If the input parameter object of a feature method is null, the corresponding application of the code will crash. To prevent the program from crashing due to null values ​​of the input parameter object of a feature method, it is necessary to test the application code before the application is officially launched to locate the feature structure in the code where the input parameter object of the feature method may be null, so as to optimize the code and improve the stability of the application after it is officially launched.

[0003] Traditional code testing methods mainly use monkey testing tools to test the code. However, monkey testing is a random testing method that simulates random operations of users to test the stability of the application corresponding to the code. It cannot cover all operation paths that may cause the object inserted into the feature method to be null, resulting in low code testing accuracy. Summary of the invention

[0004] Based on this, it is necessary to provide a code testing method, device, equipment, storage medium and program product that can improve the accuracy of code testing in response to the above technical problems.

[0005] In a first aspect, the present application provides a code testing method, the method comprising:

[0006] Determine at least one characteristic method contained in the project code to be tested;

[0007] For each of the feature methods, determining a feature structure for calling the feature method in the project code;

[0008] If there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, searching for the upper layer call link of the characteristic method in the project code;

[0009] If the upper-layer call link is not found or the target protection structure does not exist in the found upper-layer call link, it is determined that the characteristic structure has a risk of causing the application corresponding to the project code to crash.

[0010] In a second aspect, the present application provides a code testing device, the device comprising:

[0011] A determination module, used to determine at least one characteristic method contained in the project code to be tested; for each characteristic method, determining a characteristic structure for calling the characteristic method in the project code;

[0012] A search module is used to search for an upper-level call link of the feature method in the project code if there is no target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located; if the upper-level call link is not found or the target protection structure does not exist in the upper-level call link found, it is determined that the feature structure has a risk of causing the application corresponding to the project code to crash.

[0013] In a third aspect, the present application provides a computer device including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps in the method embodiments of the present application are implemented.

[0014] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in the method embodiments of the present application.

[0015] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the steps in the method embodiments of the present application when the computer program is executed by a processor.

[0016] The above-mentioned code testing method, device, equipment, storage medium and program product, by determining at least one characteristic method contained in the project code to be tested; for each characteristic method, determining the characteristic structure of calling the characteristic method in the project code; if there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, then searching the upper-level call link of the characteristic method in the project code; if the upper-level call link is not found or the target protection structure does not exist in the found upper-level call link, it is determined that the characteristic structure has the risk of causing the application corresponding to the project code to crash. Compared with the traditional method of testing project code through monkey testing tools, the present application proposes a deterministic testing method, by searching for the target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, and searching for the target protection structure for the characteristic parameters of the characteristic method in the upper-level call link of the characteristic method. If the target protection structure for the characteristic parameters of the characteristic method is not found inside the declaration method where the characteristic method is located, and the target protection structure for the characteristic parameters of the characteristic method is not found in the upper-level call link of the characteristic method, it can be directly determined that the characteristic structure of calling the characteristic method has the risk of causing the application corresponding to the project code to crash. The code testing method of the present application can cover all operation paths that may cause the object inserted into the feature method to be null, thereby improving the testing accuracy of the code. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 An application environment diagram of a code testing method in an embodiment;

[0018] Figure 2 A schematic diagram of a flow chart of a code testing method in an embodiment;

[0019] Figure 3 A schematic diagram of the determination principle of a feature method in one embodiment;

[0020] Figure 4 A flowchart of a code testing method in another embodiment;

[0021] Figure 5 A schematic diagram of a code testing principle in an embodiment;

[0022] Figure 6 is a structural block diagram of a code testing device in an embodiment;

[0023] Figure 7 is an internal structure diagram of a computer device in one embodiment;

[0024] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in another embodiment. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0026] The code testing method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can be set up separately and can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other servers. Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablet computers, vehicle-mounted terminals, intelligent voice interaction devices, aircraft, smart home appliances and portable wearable devices. Smart home appliances can be smart speakers, smart TVs and smart air conditioners. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, cloud security, host security and other network security services, CDN, and basic cloud computing services such as big data and artificial intelligence platforms. The terminal 102 and the server 104 can be directly or indirectly connected by wired or wireless communication, and this application is not limited here.

[0027] Terminal 102 can submit the project code to server 104, and server 104 can determine at least one feature method contained in the project code to be tested. For each feature method, server 104 can determine the feature structure that calls the feature method in the project code. If there is no target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located, the upper-level call link of the feature method is searched in the project code. If the upper-level call link is not found or the target protection structure does not exist in the found upper-level call link, server 104 can determine that the feature structure has a risk of causing the application corresponding to the project code to crash. It is understandable that this embodiment does not limit this. It is understandable that Figure 1 The application scenarios are only for illustration and are not limited to this.

[0028] In one embodiment, Figure 2As shown, a code testing method is provided, which can be applied to a computer device, and the computer device can be a terminal or a server, that is, the method can be executed by the terminal or the server alone, or can be implemented through interaction between the terminal and the server. This embodiment takes the method applied to a computer device as an example for explanation, and includes the following steps:

[0029] Step 202: determine at least one characteristic method included in the project code to be tested.

[0030] Among them, the characteristic method refers to the method in the project code that cannot take nil (null value) as the input parameter object. If the input parameter object of the characteristic method is null value, it will cause the application corresponding to the project code to crash. It can be understood that the input parameter object of the characteristic method is the characteristic parameter of the characteristic method.

[0031] In one embodiment, the computer device may obtain at least one preset candidate feature method, search for the preset candidate feature method in the project code to be tested, and determine the found candidate feature method as the feature method included in the project code.

[0032] Step 204: for each feature method, determine the feature structure that calls the feature method in the project code.

[0033] Among them, the feature structure is a section of code in the project code. It can be understood that the feature structure that calls the feature method contains the feature method. It can be understood that the feature structure that calls the feature method is essentially the line of code where the feature method is located.

[0034] Step 206: If there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, then the upper-level call link of the characteristic method is searched in the project code.

[0035] The upper-level call link is the operation path that calls the feature method and is located before the feature method in the execution order in the project code. The feature parameter of the feature method is the input parameter object of the feature method. The protection structure is a code structure located before the feature method and used to determine whether the feature parameter (i.e., the input parameter object) of the feature method is not a null value. It can be understood that the protection structure is also a part of the code in the project code.

[0036] In one embodiment, the computer device may search for a target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located. If there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, the computer device may use the characteristic method as a starting point, search for an operation path in the project code that is located before the characteristic method in the execution order and calls the characteristic method, and use the searched operation path as the upper-level call link of the characteristic method.

[0037] Step 208: If the upper-layer call link is not found or the target protection structure does not exist in the found upper-layer call link, it is determined that the characteristic structure has a risk of causing the application corresponding to the project code to crash.

[0038] In one embodiment, if the upper-level call link of the feature method is not found in the project code, or the target protection structure does not exist in the upper-level call link of the feature method found in the project code, the computer device may determine that the feature structure of calling the feature method has the risk of causing the application corresponding to the project code to crash. It is understandable that the computer device can locate the risky feature structure in the project code so that the tester can optimize the code based on the located feature structure.

[0039] In the above code testing method, at least one feature method contained in the project code to be tested is determined; for each feature method, the feature structure of calling the feature method is determined in the project code; if there is no target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located, then the upper call link of the feature method is searched in the project code; if the upper call link is not found or the target protection structure does not exist in the upper call link found, it is determined that the feature structure has the risk of causing the application corresponding to the project code to crash. Compared with the traditional method of testing project code through monkey testing tools, the present application proposes a deterministic testing method, by searching for the target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located, and searching for the target protection structure for the feature parameters of the feature method in the upper call link of the feature method. If the target protection structure for the feature parameters of the feature method is not found inside the declaration method where the feature method is located, and the target protection structure for the feature parameters of the feature method is not found in the upper call link of the feature method, it can be directly determined that the feature structure of calling the feature method has the risk of causing the application corresponding to the project code to crash. The code testing method of the present application can cover all operation paths that may cause the object inserted into the feature method to be null, thereby improving the testing accuracy of the code.

[0040] In one embodiment, the method further includes: if there is a target protection structure for a feature parameter of the feature method inside the declaring method where the feature method is located, determining that the feature structure does not have a risk of causing the application corresponding to the project code to crash.

[0041] Specifically, the computer device can determine at least one characteristic method contained in the project code to be tested. For each characteristic method, the computer device can determine the characteristic structure that calls the characteristic method in the project code. If there is a target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, the computer device can determine that the characteristic structure does not have the risk of causing the application corresponding to the project code to crash. If there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, the computer device can search for the upper-level call link of the characteristic method in the project code. If the upper-level call link is not found or the target protection structure does not exist in the found upper-level call link, the computer device can determine that the characteristic structure has the risk of causing the application corresponding to the project code to crash.

[0042] In the above embodiment, as long as it is determined that there exists a target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located, it can be directly determined that there is no risk of causing the application corresponding to the project code to crash by calling the feature structure of the feature method. There is no need to determine whether there is a target protection structure for the feature parameters of the feature method in the upper-level calling link of the feature method. This improves the testing efficiency of the project code while ensuring the accuracy of code testing.

[0043] In one embodiment, determining at least one characteristic method contained in the project code to be tested includes: obtaining at least one candidate program error record generated when an application corresponding to the project code to be tested runs into an error; each candidate program error record includes an error type and an error method; from at least one candidate program error record, selecting a target program error record whose error type indicates that a method input parameter object cannot be a null value; and determining the error method contained in the target program error record as a characteristic method contained in the project code.

[0044] The error type is used to indicate the reason why the application corresponding to the project code runs wrong. The error method is the method in the project code that causes the application corresponding to the project code to run wrong. The method input parameter object is the input parameter object of the method contained in the project code.

[0045] Specifically, the computer device can run the application corresponding to the project code to be tested, and obtain at least one candidate program error record generated when the application corresponding to the project code fails to run. Each candidate program error record includes an error type and an error method. The computer device can select a target program error record whose error type indicates that the method input parameter object cannot be a null value from at least one candidate program error record, and directly determine the error method contained in the target program error record as the feature method contained in the project code. It can be understood that if the input parameter object (i.e., the feature parameter) of the feature method is a null value, it will cause the application corresponding to the project code to run incorrectly, that is, the application corresponding to the project code will crash.

[0046] In one embodiment, Figure 3 As shown, each candidate program error record includes not only the error type and error method, but also a data type, which is used to indicate the type of the object in the project code that causes the application corresponding to the project code to run incorrectly. Figure 3 The error types shown all contain information indicating that the method input object cannot be null, so Figure 3 What is shown are all target program error records, and the error reporting methods contained in these target program error records are all feature methods in the project code.

[0047] In the above embodiment, by running the application corresponding to the project code to be tested to obtain the program error record generated when the operation fails, and based on the error type in the program error record, determining the feature method contained in the project code, the accuracy of obtaining the feature method can be improved.

[0048] In one embodiment, the method also includes: if there is a first candidate protection structure for the characteristic parameters of the characteristic method inside the declaring method where the characteristic method is located, the characteristic parameters are compared with the first protection parameters in the first candidate protection structure for consistency, and the first line number of the code line where the characteristic parameters are located is compared with the second line number of the code line where the first protection parameter is located; if the characteristic parameters are consistent with the first protection parameter, and the first line number is greater than the second line number, the first candidate protection structure is determined as the target protection structure for the characteristic parameters of the characteristic method.

[0049] Specifically, the computer device can determine at least one feature method contained in the project code to be tested. For each feature method, the first candidate protection structure for the feature parameters of the feature method is searched inside the declaration method where the feature method is located. If there is a first candidate protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located, the computer device can compare the feature parameters with the first protection parameter in the first candidate protection structure for consistency, and compare the first line number of the code line where the feature parameter is located with the second line number of the code line where the first protection parameter is located. If the feature parameter is consistent with the first protection parameter, and the first line number is greater than the second line number, the computer device can determine the first candidate protection structure as the target protection structure for the feature parameters of the feature method, that is, there is a target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located.

[0050] In the above embodiment, the first candidate protection structure will be determined as the target protection structure for the characteristic parameters of the characteristic method only when there is a first candidate protection structure for the characteristic parameters of the characteristic method inside the declaring method where the characteristic method is located, and the characteristic parameters are consistent with the first protection parameters in the first candidate protection structure, and the first line number of the code line where the characteristic parameters are located is greater than the second line number of the code line where the first protection parameters are located, thereby improving the accuracy of determining the target protection structure and further improving the testing accuracy of the project code.

[0051] In one embodiment, a consistency comparison is performed between a characteristic parameter and a first protection parameter in a first candidate protection structure, including: determining a parameter identifier of the characteristic parameter in the declaration method to which it belongs; based on the parameter identifier, determining a first candidate protection structure to be compared from a first candidate protection structure existing inside the declaration method where the characteristic method is located; and a consistency comparison is performed between the characteristic parameter and the first protection parameter in the first candidate protection structure to be compared.

[0052] Specifically, the parameter identifier of the feature parameter in the declaration method to which it belongs is unique, and the parameter identifier can be used to uniquely locate the parameter in the declaration method to which it belongs. Since there may be multiple first candidate protection structures inside the declaration method where the feature method is located, the first candidate protection structure to be compared can be determined from the first candidate protection structures existing inside the declaration method where the feature method is located based on the parameter identifier, and then the feature parameter is compared with the first protection parameter in the determined first candidate protection structure to be compared for consistency. In this way, parameter offside can be avoided, and the accuracy of determining the target protection structure can be improved, thereby further improving the test accuracy of the project code. In one embodiment, the method also includes: if there is no first candidate protection structure for the feature parameter of the feature method inside the declaration method where the feature method is located, or the feature parameter is inconsistent with the first protection parameter, or the first line number is less than or equal to the second line number, then it is determined that there is no target protection structure for the feature parameter of the feature method inside the declaration method where the feature method is located.

[0053] Specifically, the computer device may determine at least one characteristic method contained in the project code to be tested. For each characteristic method, a first candidate protection structure for the characteristic parameters of the characteristic method is searched inside the declaration method where the characteristic method is located. If the first candidate protection structure for the characteristic parameters of the characteristic method does not exist inside the declaration method where the characteristic method is located, it is directly determined that there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, that is, there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located. If there is a first candidate protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, the computer device may compare the characteristic parameters with the first protection parameter in the first candidate protection structure for consistency, and compare the first line number of the code line where the characteristic parameter is located with the second line number of the code line where the first protection parameter is located. If the characteristic parameter is consistent with the first protection parameter, and the first line number is greater than the second line number, the computer device may determine the first candidate protection structure as the target protection structure for the characteristic parameters of the characteristic method, that is, there is a target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located. If the characteristic parameter is inconsistent with the first protection parameter, or the first row number is less than or equal to the second row number, it can be directly determined that there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, that is, there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located.

[0054] In the above embodiment, as long as the first candidate protection structure for the characteristic parameters of the characteristic method does not exist inside the declaration method where the characteristic method is located, or the characteristic parameters are inconsistent with the first protection parameters in the first candidate protection structure, or the first line number of the code line where the characteristic parameters are located is less than or equal to the second line number of the code line where the first protection parameters are located, it can be determined that the target protection structure for the characteristic parameters of the characteristic method does not exist inside the declaration method where the characteristic method is located, which improves the search efficiency of the target protection structure and avoids the missed detection of characteristic structures that may be risky.

[0055] In one embodiment, searching for an upper-level call link of a feature method in a project code includes: obtaining a calling method name of a calling method contained in the project code; obtaining a declared method name of a declared method contained in the project code; the feature method is contained in at least a part of the declared method; obtaining a class inheritance relationship between classes contained in the project code, and obtaining a protocol compliance relationship between a class contained in the project code and a protocol contained in the project code; based on the calling method name, the declared method name, the class inheritance relationship and the protocol compliance relationship, searching for an upper-level call link of the feature method in the project code.

[0056] Among them, the calling method is the method used to call the method contained in the project code. The declaring method is the method used to define the method. It can be understood that a method must be defined (i.e. declared) before it can be called.

[0057] In one embodiment, a computer device may obtain the calling method name and the calling object type of the calling method contained in the project code, wherein the calling object type refers to the type of the calling object of the calling method. The computer device may obtain the declared method name and the type of the class where the declared method is contained in the project code, wherein the feature method is contained in at least a part of the declared method. The computer device may also obtain the class inheritance relationship between the classes contained in the project code, and obtain the protocol compliance relationship between the class contained in the project code and the protocol contained in the project code. Furthermore, for each feature method, the computer device may search for the upper-level call link of the feature method in the project code based on the calling method name, the declared method name, the class inheritance relationship, and the protocol compliance relationship.

[0058] In the above embodiment, the upper-level call link of the feature method can be quickly found in the project code through the calling method name and the declared method name of the calling method contained in the project code, the class inheritance relationship between the classes contained in the project code, and the protocol compliance relationship between the classes contained in the project code and the protocols contained in the project code. This can improve the search efficiency of the upper-level call link of the feature method and avoid the upper-level call link of the feature method from being missed, thereby improving the search accuracy of the upper-level call link of the feature method.

[0059] In one embodiment, based on the calling method name, the declared method name, the class inheritance relationship and the protocol compliance relationship, the upper-level calling link of the feature method is searched in the project code, including: for each calling method name and each declared method name, if the calling method name is consistent with the declared method name, and the type of the class where the declared method corresponding to the declared method name is located is equal to the type of the object of the calling method corresponding to the calling method name or there is a type matching relationship, then it is determined that there is a called relationship between the declared method corresponding to the declared method name and the calling method corresponding to the calling method name; wherein, the type matching relationship refers to the class where the declared method corresponding to the declared method name is located, and the object of the calling method corresponding to the calling method name has a class inheritance relationship or a protocol compliance relationship; based on the called relationship between each declared method and each calling method, the upper-level calling link of the feature method is determined in the project code.

[0060] Specifically, for each calling method name and each declaring method name, if the calling method name is consistent with the declaring method name, and the type of the class where the declaring method corresponding to the declaring method name is located is equal to the type of the object of the calling method corresponding to the calling method name or there is a type matching relationship, then the computer device can determine that there is a called relationship between the declared method corresponding to the declaring method name and the calling method corresponding to the calling method name. Among them, the type matching relationship refers to the existence of a class inheritance relationship or a protocol compliance relationship between the class where the declared method corresponding to the declaring method name is located and the object of the calling method corresponding to the calling method name. Furthermore, for each feature method, the computer device can determine the upper-level calling link of the feature method in the project code based on the called relationship between each declaring method and each calling method.

[0061] In the above embodiment, by determining the upper-level calling link of the feature method in the project code based on the called relationship between each declared method and each calling method, it is possible to further avoid missing the upper-level calling link of the feature method, thereby further improving the search accuracy of the upper-level calling link of the feature method.

[0062] In one embodiment, the method also includes: if a second candidate protection structure for the characteristic parameters of the characteristic method exists in the upper-level call link found, the characteristic parameters are compared with the second protection parameters in the second candidate protection structure for consistency; if the characteristic parameters are consistent with the second protection parameters, the second candidate protection structure is determined as the target protection structure; if the characteristic parameters are inconsistent with the second protection parameters, it is determined that the target protection structure does not exist in the upper-level call link.

[0063] Specifically, the computer device can determine at least one feature method contained in the project code to be tested. For each feature method, if there is no target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located, the upper-level call link of the feature method is searched in the project code. If there is a second candidate protection structure for the feature parameters of the feature method in the found upper-level call link, the computer device can compare the feature parameters with the second protection parameters in the second candidate protection structure for consistency. If the feature parameters are consistent with the second protection parameters, the computer device can determine the second candidate protection structure as the target protection structure, that is, the target protection structure exists in the upper-level call link of the feature method. If the feature parameters are inconsistent with the second protection parameters, the computer device can determine that the target protection structure does not exist in the upper-level call link of the feature method.

[0064] In the above embodiment, when searching for a target protection structure for characteristic parameters of a characteristic method in an upper-level call link, the second candidate protection structure is determined as the target protection structure for the characteristic parameters of the characteristic method only when the characteristic parameters of the characteristic method are consistent with the second protection parameters in the second candidate protection structure; otherwise, it is determined that the target protection structure does not exist in the upper-level call link, thereby improving the accuracy of searching for the target protection structure.

[0065] In one embodiment, a consistency comparison is performed between the characteristic parameter and the second protection parameter in the second candidate protection structure, including: determining the parameter identifier and parameter position of the characteristic parameter in the declaration method to which it belongs; based on the parameter identifier and parameter position, determining the second candidate protection structure to be compared from the second candidate protection structure existing in the upper-layer call link; and performing a consistency comparison between the characteristic parameter and the second protection parameter in the second candidate protection structure to be compared.

[0066] Specifically, the parameter identifier of the feature parameter in the declaration method to which it belongs is unique, and the parameter identifier can be used to uniquely locate the parameter in the declaration method to which it belongs. However, the feature parameter may not be unique outside the declaration method to which it belongs, and there may be multiple second candidate protection structures in the upper-level call link of the feature method. Therefore, it is necessary to determine the second candidate protection structure to be compared from the second candidate protection structures existing in the upper-level call link of the feature method based on the parameter identifier and the parameter position of the feature parameter in the declaration method to which it belongs, and then perform a consistency comparison between the feature parameter and the second protection parameter in the determined second candidate protection structure to be compared. In this way, parameter offside can be effectively avoided, and the accuracy of determining the target protection structure can be improved, thereby further improving the test accuracy of the project code.

[0067] In one embodiment, the method further includes: if the target protection structure exists in the found upper-level call link, determining that the characteristic structure does not have a risk of causing the application corresponding to the project code to crash.

[0068] Specifically, the computer device may determine at least one characteristic method contained in the project code to be tested. For each characteristic method, the computer device may determine the characteristic structure that calls the characteristic method in the project code. If there is a target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, the computer device may determine that the characteristic structure does not have the risk of causing the application corresponding to the project code to crash. If there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, the computer device may search for the upper-level call link of the characteristic method in the project code. If the upper-level call link is not found or the target protection structure does not exist in the found upper-level call link, the computer device may determine that the characteristic structure has the risk of causing the application corresponding to the project code to crash. If the target protection structure exists in the found upper-level call link, the computer device may determine that the characteristic structure does not have the risk of causing the application corresponding to the project code to crash.

[0069] In the above embodiment, once it is determined that there is a target protection structure for the characteristic parameters of the characteristic method in the found upper-level call link, it can be directly determined that the characteristic structure does not have the risk of causing the application corresponding to the project code to crash, thereby improving the test accuracy and test efficiency of the project code.

[0070] In one embodiment, Figure 4 As shown, the computer device can upload the code testing method logic of the present application to the code management tool, and connect the Blue Shield pipeline to the code management tool. The Blue Shield pipeline can automatically obtain the project code build notification and automatically pull the project code. The computer device can run the project code and test the project code based on the code testing method logic of the present application, and output the test results and notify the tester after the operation is completed.

[0071] In one embodiment, Figure 5As shown, the computer device can determine at least one characteristic method contained in the project code to be tested. For each characteristic method, the computer device can determine the characteristic structure of calling the characteristic method in the project code. If there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, the computer device can obtain the calling method name of the calling method contained in the project code, and obtain the declaration method name of the declaration method contained in the project code; wherein the characteristic method is contained in at least a part of the declaration method. The computer device can also obtain the class inheritance relationship between the classes contained in the project code, and obtain the protocol compliance relationship between the class contained in the project code and the protocol contained in the project code. Furthermore, the computer device can search for the upper-level call link of the characteristic method in the project code based on the calling method name, the declaration method name, the class inheritance relationship and the protocol compliance relationship. If there is a second candidate protection structure for the characteristic parameters of the characteristic method in the upper-level call link found, the computer device can compare the characteristic parameters with the second protection parameters in the second candidate protection structure for consistency. If the characteristic parameters are inconsistent with the second protection parameters, the computer device can determine that there is no target protection structure in the upper-level call link. If the upper-level call link is not found or the target protection structure does not exist in the found upper-level call link, the computer device may determine that the characteristic structure has a risk of causing the application corresponding to the project code to crash.

[0072] It should be understood that, although each step in the flow chart of the above-mentioned embodiments is shown in order, these steps are not necessarily performed in order. Unless there is a clear explanation in this article, the execution of these steps does not have strict order restrictions, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the above-mentioned embodiments may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these sub-steps or stages is not necessarily performed in order, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.

[0073] In one embodiment, Figure 6 As shown, a code testing device 600 is provided, and the device specifically includes:

[0074] The determination module 602 is used to determine at least one characteristic method contained in the project code to be tested; for each characteristic method, determine a characteristic structure that calls the characteristic method in the project code;

[0075] Search module 604 is used to search for the upper-level call link of the feature method in the project code if there is no target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located; if the upper-level call link is not found or the target protection structure does not exist in the found upper-level call link, it is determined that the feature structure has the risk of causing the application corresponding to the project code to crash.

[0076] In one embodiment, the search module 604 is also used to determine that there is no risk of causing the application corresponding to the project code to crash if a target protection structure for the feature parameters of the feature method exists inside the declaration method where the feature method is located.

[0077] In one embodiment, the determination module 602 is also used to obtain at least one candidate program error record generated when an application corresponding to the project code to be tested runs into an error; each candidate program error record includes an error type and an error method; from at least one candidate program error record, a target program error record whose error type indicates that the method input parameter object cannot be a null value is selected; and the error method included in the target program error record is determined as a feature method included in the project code.

[0078] In one embodiment, the search module 604 is also used to compare the characteristic parameters with the first protection parameter in the first candidate protection structure for consistency if there is a first candidate protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, and to compare the first line number of the code line where the characteristic parameter is located with the second line number of the code line where the first protection parameter is located; if the characteristic parameter is consistent with the first protection parameter, and the first line number is greater than the second line number, the first candidate protection structure is determined as the target protection structure for the characteristic parameters of the characteristic method.

[0079] In one embodiment, the search module 604 is also used to determine the parameter identifier of the feature parameter in the declaration method to which it belongs; based on the parameter identifier, determine the first candidate protection structure to be compared from the first candidate protection structure existing inside the declaration method where the feature method is located; and perform a consistency comparison between the feature parameter and the first protection parameter in the first candidate protection structure to be compared.

[0080] In one embodiment, the search module 604 is also used to determine that there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located if there is no first candidate protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, or the characteristic parameters are inconsistent with the first protection parameters, or the first line number is less than or equal to the second line number.

[0081] In one embodiment, the search module 604 is also used to obtain the calling method name of the calling method contained in the project code; obtain the declared method name of the declared method contained in the project code; the feature method is contained in at least a part of the declared method; obtain the class inheritance relationship between the classes contained in the project code, and obtain the protocol compliance relationship between the class contained in the project code and the protocol contained in the project code; based on the calling method name, the declared method name, the class inheritance relationship and the protocol compliance relationship, search for the upper-level calling link of the feature method in the project code.

[0082] In one embodiment, the search module 604 is also used to determine, for each calling method name and each declared method name, that if the calling method name is consistent with the declared method name, and the type of the class in which the declared method corresponding to the declared method name is located is equal to the type of the object of the called method corresponding to the calling method name or there is a type matching relationship, then it is determined that there is a called relationship between the declared method corresponding to the declared method name and the calling method corresponding to the calling method name; wherein, the type matching relationship refers to the existence of a class inheritance relationship or a protocol compliance relationship between the class in which the declared method corresponding to the declared method name is located and the object of the called method corresponding to the calling method name; based on the called relationship between each declared method and each calling method, the upper-level calling link of the feature method is determined in the project code.

[0083] In one embodiment, the search module 604 is also used to compare the characteristic parameters with the second protection parameters in the second candidate protection structure if there is a second candidate protection structure for the characteristic parameters of the characteristic method in the found upper-level call link; if the characteristic parameters are consistent with the second protection parameters, the second candidate protection structure is determined as the target protection structure; if the characteristic parameters are inconsistent with the second protection parameters, it is determined that the target protection structure does not exist in the upper-level call link.

[0084] In one embodiment, the search module 604 is also used to determine the parameter identifier and parameter position of the characteristic parameter in the declaration method to which it belongs; based on the parameter identifier and parameter position, determine the second candidate protection structure to be compared from the second candidate protection structure existing in the upper-layer call link; and perform a consistency comparison between the characteristic parameter and the second protection parameter in the second candidate protection structure to be compared.

[0085] In one embodiment, the search module 604 is also used to determine that the characteristic structure does not have the risk of causing the application corresponding to the project code to crash if the target protection structure exists in the found upper-level call link.

[0086] The above-mentioned code testing device determines at least one characteristic method contained in the project code to be tested; for each characteristic method, determines the characteristic structure of calling the characteristic method in the project code; if there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, then the upper-level call link of the characteristic method is searched in the project code; if the upper-level call link is not found or the target protection structure does not exist in the upper-level call link found, it is determined that the characteristic structure has the risk of causing the application corresponding to the project code to crash. Compared with the traditional method of testing project code through monkey testing tools, the present application proposes a deterministic testing method, which searches for the target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, and searches for the target protection structure for the characteristic parameters of the characteristic method in the upper-level call link of the characteristic method. If the target protection structure for the characteristic parameters of the characteristic method is not found inside the declaration method where the characteristic method is located, and the target protection structure for the characteristic parameters of the characteristic method is not found in the upper-level call link of the characteristic method, it can be directly determined that the characteristic structure of calling the characteristic method has the risk of causing the application corresponding to the project code to crash. The code testing method of the present application can cover all operation paths that may cause the object inserted into the feature method to be null, thereby improving the testing accuracy of the code.

[0087] Each module in the above code testing device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.

[0088] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a code testing method is implemented.

[0089] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a code testing method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.

[0090] Those skilled in the art will understand that Figure 7 and Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0091] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.

[0092] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0093] In one embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0094] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0095] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0096] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0097] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A code testing method, characterized in that: The method comprises: Determine at least one characteristic method contained in the project code to be tested; For each of the feature methods, determining a feature structure for calling the feature method in the project code; If there is no target protection structure for the characteristic parameters of the characteristic method inside the declaration method where the characteristic method is located, searching for the upper layer call link of the characteristic method in the project code; If the upper-layer call link is not found or the target protection structure does not exist in the found upper-layer call link, it is determined that the characteristic structure has a risk of causing the application corresponding to the project code to crash.

2. The method according to claim 1, characterized in that The method further comprises: If a target protection structure for a characteristic parameter of the characteristic method exists inside the declaration method where the characteristic method is located, it is determined that the characteristic structure does not have a risk of causing the application corresponding to the project code to crash.

3. The method according to claim 1, characterized in that The method of determining at least one characteristic contained in the project code to be tested includes: Obtain at least one candidate program error report record generated when an application corresponding to the project code to be tested runs in error; each candidate program error report record includes an error type and an error reporting method; From the at least one candidate program error record, select a target program error record in which the error type indicating method input parameter object cannot be a null value; The error reporting method contained in the target program error reporting record is determined as a characteristic method contained in the project code.

4. The method according to claim 1, characterized in that The method further comprises: If a first candidate protection structure for a feature parameter of the feature method exists inside the declaration method where the feature method is located, the feature parameter is compared for consistency with the first protection parameter in the first candidate protection structure, and the first line number of the code line where the feature parameter is located is compared for size with the second line number of the code line where the first protection parameter is located; If the characteristic parameter is consistent with the first protection parameter, and the first row number is greater than the second row number, the first candidate protection structure is determined as a target protection structure for the characteristic parameter of the characteristic method.

5. The method according to claim 4, characterized in that The comparing the characteristic parameter with the first protection parameter in the first candidate protection structure for consistency includes: Determine the parameter identifier of the characteristic parameter in the declaration method to which it belongs; Based on the parameter identifier, determining a first candidate protection structure to be compared from first candidate protection structures existing inside the declaration method where the feature method is located; The characteristic parameter is compared with the first protection parameter in the first candidate protection structure to be compared for consistency.

6. The method according to claim 4, characterized in that The method further comprises: If there is no first candidate protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located, or the feature parameters are inconsistent with the first protection parameters, or the first line number is less than or equal to the second line number, it is determined that there is no target protection structure for the feature parameters of the feature method inside the declaration method where the feature method is located.

7. The method according to claim 1, characterized in that The step of searching the project code for the upper-layer call link of the feature method includes: Obtain the calling method name of the calling method contained in the project code; Obtaining the declaration method name of the declaration method contained in the project code; the feature method is contained in at least a part of the declaration method; Obtaining the class inheritance relationship between the classes contained in the project code, and obtaining the protocol compliance relationship between the classes contained in the project code and the protocols contained in the project code; Based on the calling method name, the declaring method name, the class inheritance relationship and the protocol compliance relationship, the upper-level calling link of the feature method is searched in the project code.

8. The method according to claim 7, characterized in that The searching for the upper-layer call link of the feature method in the project code based on the calling method name, the declaring method name, the class inheritance relationship and the protocol compliance relationship includes: For each of the calling method names and each of the declared method names, if the calling method name is consistent with the declared method name, and the type of the class in which the declared method corresponding to the declared method name is located is equal to the type of the object of the calling method corresponding to the calling method name or there is a type matching relationship, then it is determined that there is a called relationship between the declared method corresponding to the declared method name and the calling method corresponding to the calling method name; wherein the type matching relationship means that there is a class inheritance relationship or a protocol compliance relationship between the class in which the declared method corresponding to the declared method name is located and the object of the calling method corresponding to the calling method name; Based on the called relationship between each of the declared methods and each of the called methods, the upper-level calling link of the feature method is determined in the project code.

9. The method according to claim 1, characterized in that: The method further comprises: If a second candidate protection structure for the characteristic parameter of the characteristic method exists in the found upper-layer call link, a consistency comparison is performed between the characteristic parameter and the second protection parameter in the second candidate protection structure; If the characteristic parameter is consistent with the second protection parameter, determining the second candidate protection structure as the target protection structure; If the characteristic parameter is inconsistent with the second protection parameter, it is determined that the target protection structure does not exist in the upper layer call link.

10. The method according to claim 9, characterized in that The comparing the characteristic parameter with the second protection parameter in the second candidate protection structure for consistency includes: Determine the parameter identifier and parameter position of the characteristic parameter in the declaration method to which it belongs; Based on the parameter identifier and the parameter position, determining a second candidate protection structure to be compared from second candidate protection structures existing in the upper layer call link; The characteristic parameter is compared with the second protection parameter in the second candidate protection structure to be compared for consistency.

11. The method according to claim 1, characterized in that: The method further comprises: If the target protection structure exists in the upper-layer call link found, it is determined that the characteristic structure does not have the risk of causing the application corresponding to the project code to crash.

12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.

Citation Information

Patent Citations

  • Null pointer crash mining method and device

    CN105607990A

  • Method for constructing test scene and information processing equipment

    CN111831532A

  • Risk method troubleshooting method and device

    CN116541850A

  • Software exception risk detection method, computer equipment and storage medium

    CN117667670A

  • Crash risk detection method, computer equipment and computer storage medium

    CN117873894A