Code testing method and device, electronic device and storage medium

By using interface and function relationship storage and tree structure methods in code testing, the changing interfaces are determined and accurate test cases are generated, and the problem of high testing workload when code changes in the existing technology is solved, and efficient code is achieved test.

CN110147317BActive Publication Date: 2024-11-08BEIJING RUIZHONG TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910317815.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-04-19
Publication Date
2024-11-08
Estimated Expiration
2039-04-19

AI Technical Summary

Technical Problem

When the existing code test method changes, all interfaces need to be regressed through the full process, resulting in huge testing workload, increasing the cost of system testing and maintenance upgrades, and it is impossible to accurately locate the changed interfaces in the code.

Method used

Using the storage method that defines the relationship between interfaces and functions in the code, the interfaces and functions are stored, the interfaces corresponding to the changing functions are determined through the tree structure, and accurate tests are generated based on the preset mapping relationship between the interface and the test case. Use cases, narrow the scope of tests.

Benefits of technology

It realizes rapid positioning of changing interfaces, generates accurate test cases, reduces the testing workload, and improves the efficiency of code testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110147317B_ABST
    Figure CN110147317B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a code testing method and device, an electronic device, and a storage medium, and relates to the field of test management technology in software testing, and can be applied to the application scenario of code testing of software codes completed by developers. The code testing method includes storing interfaces and functions in a storage method that defines the relationship between interfaces and functions in the code; if a function in the code changes, the interface corresponding to the changed function is determined as the target interface; the test case corresponding to the target interface is determined according to the preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case. The present disclosure can accurately locate the interface corresponding to the changed function in the software code, and generate a test case based on the located interface to perform code testing.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] Code testing is an important task in software development. After developers complete the software code, testers are required to continuously test it to find some loopholes (i.e. bugs) in the code so that the code can be improved in time.

[0003] In the existing code testing process, when developers modify the code, testers need to perform full-process regression testing on all the codes to confirm that the modified code does not introduce new errors or cause errors in other codes.

[0004] When the code changes, all interfaces need to be regression tested, which results in a huge workload for testers and increases the cost of system testing and maintenance upgrades.

[0005] It should be noted that the information disclosed in the above background technology 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 ordinary technicians in the field. Summary of the invention

[0006] The purpose of the present disclosure is to provide a code testing method, a code testing device, an electronic device and a computer-readable storage medium, thereby overcoming the problem of being unable to accurately locate the changed interface in the code and perform code testing on the changed interface at least to a certain extent.

[0007] According to a first aspect of the present disclosure, a code testing method is provided, comprising: storing interfaces and functions in a storage manner that defines the relationship between interfaces and functions in the code; if a function in the code changes, determining the interface corresponding to the changed function as the target interface; determining the test case corresponding to the target interface according to a preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case.

[0008] Optionally, storing interfaces and functions in a storage method that defines the relationship between interfaces and functions in the code includes: determining multiple interfaces in the code and functions corresponding to each interface; storing multiple interfaces and functions corresponding to each interface in a tree structure; wherein the tree structure defines the relationship between multiple interfaces and functions corresponding to each interface.

[0009] Optionally, using a tree structure to store multiple interfaces and functions corresponding to each interface includes: using the interface as a root node in the tree structure, and using the function in the code as an intermediate node or leaf node in the tree structure.

[0010] Optionally, determining the interface corresponding to the changed function as the target interface includes: determining the changed function in the code as the target function; and traversing the tree structure from bottom to top based on the target function to determine the interface corresponding to the target function as the target interface.

[0011] Optionally, after determining the interface corresponding to the changed function as the target interface, the code testing method also includes: if there are multiple target interfaces, determining the associated weights between each target interface and the target function; judging the type of code change based on the determined associated weights between each target interface and the target function; wherein the type of code change includes good-intentioned modification and malicious tampering.

[0012] Optionally, determining the association weight of each target interface and the target function includes: determining a target interface as a target test interface; determining a version of the target test interface before being changed as a first version; determining a version of the target test interface after being changed as a second version; obtaining the running result of the code under the first version as a first test result; obtaining the running result of the code under the second version as a second test result; and if the difference between the second test result and the first test result is determined, determining the association weight of the target test interface and the target function.

[0013] Optionally, judging the type of code change based on the determined associated weights of each target interface and the target function includes: determining the execution result of the test case before the target function changes as the first execution result; determining the execution result of the test case after the target function changes as the second execution result; if the degree of correspondence between the difference between the second execution result and the first execution result and the associated weight is greater than a preset threshold, determining the type of code change to be a good-faith modification; if the degree of correspondence between the difference between the second execution result and the first execution result and the associated weight is less than or equal to a preset threshold, determining the type of code change to be a malicious tampering.

[0014] According to a second aspect of the present disclosure, a code testing device is provided, including: a relationship storage module, used to store interfaces and functions in a storage method that defines the relationship between interfaces and functions in the code; a target interface determination module, used to determine the interface corresponding to the changed function as the target interface if the function in the code changes; a test case generation module, used to determine the test case corresponding to the target interface according to a preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case.

[0015] Optionally, the relationship storage module includes a relationship storage unit, which is used to determine multiple interfaces in the code and the functions corresponding to each interface; a tree structure is used to store multiple interfaces and the functions corresponding to each interface; wherein the tree structure defines the relationship between multiple interfaces and the functions corresponding to each interface.

[0016] Optionally, the relationship storage unit includes a relationship storage sub-unit, which is used to use the interface as the root node in the tree structure and the function in the code as the intermediate node or leaf node in the tree structure.

[0017] Optionally, the target interface determination module includes a target interface determination unit, which is used to determine the function that has changed in the code as the target function; and traverse the tree structure from bottom to top based on the target function to determine the interface corresponding to the target function as the target interface.

[0018] Optionally, the code testing device also includes a code change type determination module, which is used to determine the association weight of each target interface and the target function if there are multiple target interfaces; judge the type of code change based on the determined association weight of each target interface and the target function; wherein the type of code change includes good-intentioned modification and malicious tampering.

[0019] Optionally, the code change type determination module includes an association weight determination unit, which is used to determine a target interface as a target test interface; determine the version of the target test interface before it is changed as a first version; determine the version of the target test interface after it is changed as a second version; obtain the running result of the code under the first version as a first test result; obtain the running result of the code under the second version as a second test result; and if the difference between the second test result and the first test result is, determine the association weight between the target test interface and the target function.

[0020] Optionally, the code change type determination module includes a code change type determination unit, which is used to determine the execution result of the test case before the target function changes as the first execution result; determine the execution result of the test case after the target function changes as the second execution result; if the correspondence between the difference between the second execution result and the first execution result and the associated weight is greater than a preset threshold, the code change type is determined to be a good-intentioned modification; if the difference between the second execution result and the first execution result and the correspondence between the associated weight is less than or equal to the preset threshold, the code change type is determined to be a malicious tampering.

[0021] According to a third aspect of the present disclosure, there is provided an electronic device, comprising: a processor; and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the method for code testing according to any one of the above items is implemented.

[0022] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the code testing method according to any one of the above items is implemented.

[0023] The code testing method in the exemplary embodiment of the present disclosure uses a storage method that defines the relationship between the interface and the function in the code to store the interface and the function; if the function in the code changes, the interface corresponding to the changed function is determined as the target interface; the test case corresponding to the target interface is determined according to the preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case. On the one hand, the present disclosure uses a storage method that defines the relationship between the interface and the function in the code to store the interface and the function, and when the function in the code changes, it can quickly locate the corresponding interface that has changed in the interface layer; on the other hand, after locating the changed interface, according to the mapping relationship between the interface and the test case that has been set in advance, the latest and accurate test case can be generated, and the test case can be executed, which narrows the scope of the test and thus reduces the workload.

[0024] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0026] Figure 1 A flowchart of a code testing method according to an exemplary embodiment of the present disclosure is schematically shown;

[0027] Figure 2 Schematically shows a first tree structure diagram constructed according to a code testing method according to an exemplary embodiment of the present disclosure;

[0028] Figure 3 Schematically shows a second tree structure diagram constructed according to the code testing method of an exemplary embodiment of the present disclosure;

[0029] Figure 4 A first block diagram schematically shows a code testing device according to an exemplary embodiment of the present disclosure;

[0030] Figure 5 Schematically shows a block diagram of a relationship storage module according to an exemplary embodiment of the present disclosure;

[0031] Figure 6 Schematically shows a block diagram of a relationship storage unit according to an exemplary embodiment of the present disclosure;

[0032] Figure 7 Schematically shows a block diagram of a target interface determination module according to an exemplary embodiment of the present disclosure;

[0033] Figure 8 A second block diagram schematically shows a code testing device according to an exemplary embodiment of the present disclosure;

[0034] Fig. 9 A first block diagram of a code change type determination module according to an exemplary embodiment of the present disclosure is schematically shown;

[0035] Fig.10 A second block diagram schematically illustrates a code change type determination module according to an exemplary embodiment of the present disclosure;

[0036] Fig.11 A block diagram schematically shows an electronic device according to an exemplary embodiment of the present disclosure; and

[0037] Fig.12 A schematic diagram of a computer-readable storage medium according to an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0038] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many 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 comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.

[0039] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known structures, methods, devices, implementations, materials or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.

[0040] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or these functional entities or parts of functional entities may be implemented in one or more software hardened modules, or these functional entities may be implemented in different networks and / or processor devices and / or microcontroller devices.

[0041] Before the software is put into use, it is usually necessary to test the code multiple times to find bugs in the code; or when the software is optimized and upgraded, and new functions are added based on the original code version, the code also needs to be tested. However, the current software testing method requires that all codes be tested as long as the code is changed to find bugs in the code, resulting in a very large testing workload.

[0042] Based on this, in this exemplary embodiment, a code testing method is first provided, which can be implemented by using a server, or by using a terminal device, wherein the terminal device can be, for example, a mobile phone, a computer, or other terminal devices. Figure 1 , the code testing method may include the following steps:

[0043] S110. The interfaces and functions are stored in a storage method that defines the relationship between the interfaces and functions in the code.

[0044] According to some exemplary embodiments of the present disclosure, the code may be a set of clear rules that represent information in discrete form by characters, symbols or signal code elements, and a source file written by a programmer in a language supported by a development tool. Generally, a complete set of codes may be a software system. An interface refers to a reference type that defines a protocol, and may include but is not limited to methods, properties, indexers, and events as members. The interfaces in the code may include but are not limited to interfaces for data to enter the system and interfaces for data to flow out of the system. The interfaces for data to enter the system are interfaces for test case execution calls, and these interfaces can be called by changing parameters to simulate external use; while the interfaces for data to flow out of the system are the actual verification parts of the test case, and the verification content may include: where the data flows out, what the state is when it flows out, and what the state of the system is at this time. A function in the code may be a section of code that implements an independent function. In addition, the function here may also refer to the term "method" in the software program.

[0045] Code identification tools can be used to determine all interfaces and all methods in the code. After all interfaces and functions in the code are determined, the interfaces and functions will be stored using a storage method that can define the relationship between the interfaces and functions. When storing them, only the interface name and function name can be used for storage, without storing the specific content of the interface and function, as long as the storage method can reflect the relationship between the interface and the function.

[0046] In some exemplary embodiments of the present disclosure, multiple interfaces in the code and functions corresponding to each interface are determined; a tree structure is used to store multiple interfaces and functions corresponding to each interface; wherein the tree structure defines the relationship between multiple interfaces and functions corresponding to each interface. A function in the code can correspond to one interface. In addition, since interfaces can implement multiple inheritance, a function can also correspond to multiple interfaces. When storing interfaces and functions, an identifier that can uniquely identify each interface and each function is used to facilitate the subsequent location of changed functions and interfaces.

[0047] In another exemplary embodiment of the present disclosure, the interface is used as the root node in the tree structure, and the function in the code is used as the intermediate node or leaf node in the tree structure. The tree structure is a hierarchical nested structure. The outer layer and the inner layer of a tree structure have similar structures. Therefore, the tree structure can be recursively represented. A tree can be simply represented as a root, a left subtree and a right subtree, and the left subtree and the right subtree have their own subtrees. The interface in the code is represented by a root node, and the child nodes of the root node corresponding to each interface can be functions in the code. The calling relationship between functions in the code may include but is not limited to: a child function inherits a parent function, then the child function is the next layer of the parent function, that is, the child function is the child node of the parent function; method A calls method B, then method B is in the next layer of method A, that is, method B is the child node of method A. The intermediate nodes or leaf nodes of the tree structure can be functions. The tree structure corresponding to the constructed code should be able to reflect the calling hierarchical relationship between the interface and the function in the code.

[0048] Based on the calling relationships between methods and between methods and interfaces, a tree structure corresponding to the code segment can be constructed. This can be stored in a database using data structures such as a stack, queue, or linked list, so that the constructed tree structure can be identified later. When storing, the root node, intermediate node, and leaf node have corresponding identification bits to distinguish different types of nodes. Figure 2 , Figure 2 It may be a tree structure corresponding to the interface 210, wherein the interface 210 may correspond to three functions, namely, function 1 (ie, function 220), function 2 and function 3, and the function 200 may correspond to sub-function 1 (ie, sub-function 230) and sub-function 2 (sub-function 240).

[0049] Furthermore, since there may be multiple interfaces in a piece of code, multiple tree structures can be constructed based on this code segment; in addition, a function can inherit multiple interfaces, so a function can correspond to multiple interfaces, and there may be cross-relationships between multiple trees.

[0050] S120. If a function in the code changes, determine the interface corresponding to the changed function as the target interface.

[0051] According to some exemplary embodiments of the present disclosure, the target interface may be an interface corresponding to a function that has changed in the code. When a function in the code has changed, these interfaces must be determined first in order to perform subsequent operations.

[0052] In some exemplary embodiments of the present disclosure, a function that has changed in the code is determined as a target function; based on the target function, a tree structure is traversed from bottom to top to determine an interface corresponding to the target function as a target interface. The target function may be a function that has changed in the code. When a function in the code changes, these target functions may be determined first, and the determined target functions may be one or more. After the target function is determined, the constructed tree structure may be identified from bottom to top based on the target function. The bottom-up method may be that when a function changes, the function corresponding to the node in the upper layer is recursively identified once. If the identified node in the upper layer is not the root node, the parent node of the node in the upper layer is continuously identified upward; recursively upward layer by layer until the interface corresponding to the changed function is found.

[0053] In another exemplary embodiment of the present disclosure, if there are multiple target interfaces, the association weights between each target interface and the target function are determined; the type of code change is determined based on the determined association weights between each target interface and the target function; wherein the type of code change includes good-intentioned modification and malicious tampering. In the code, a function may correspond to multiple interfaces, and the effects of these multiple interfaces on the running results of the function may also be different, that is, the degree of association is different. Therefore, determining the association weights between each interface and the target function helps to further accurately determine the interface that has the greatest impact on the running results and determine the changes in the code.

[0054] In another exemplary embodiment of the present disclosure, a target interface is determined as a target test interface; the version of the target test interface before being changed is determined as the first version; the version of the target test interface after being changed is determined as the second version; the running result of the code under the first version is obtained as the first test result; the running result of the code under the second version is obtained as the second test result; if the difference between the second test result and the first test result is determined, the association weight between the target test interface and the target function is determined. In code testing, each time a complete code is generated, a code version number will be defined for the code to distinguish different versions of the code formed after modification, and the test case execution result corresponding to the code version number can be recorded, that is, the test result. For example, the initial version of the code that implements a certain function can be the first version. After the first version is completed, the code can be tested once, and the test result is recorded as the first test result; when the initial version of the code needs to be updated, the updated code version can be the second version, and the test result of the second version of the code can be recorded as the second test result. After obtaining the first test result and the second test result, the two test results can be compared to determine the difference between the two test results, analyze the association relationship between the interface and the function in the interface corresponding to the target function, and determine the association weight according to the degree of association of the association relationship to make the next judgment.

[0055] refer to Figure 3 , function 340 corresponds to interface 310, interface 320 and interface 330 respectively, and the association weights between interface 310, interface 320 and interface 330 and function 340 are v1, v2 and v3 respectively, and v1, v2 and v3 can be determined based on the difference between the first test result and the second test result of the code. Interface 320 and interface 330 can also correspond to other tree structures, that is, there is an intersection between the tree structure corresponding to interface 310 and the tree structure corresponding to interface 330.

[0056] In another exemplary embodiment of the present disclosure, the execution result of the test case before the target function changes is determined as the first execution result; the execution result of the test case after the target function changes is determined as the second execution result; if the correspondence between the difference between the second execution result and the first execution result and the associated weight is greater than the preset threshold, the code change type is determined to be a good-faith modification; if the correspondence between the difference between the second execution result and the first execution result and the associated weight is less than or equal to the preset threshold, the code change type is determined to be malicious tampering. For example, when the function of a test case is to obtain some resources on the network, the acquisition time corresponding to the first execution result of executing the test case before the code changes is 2s, and the acquisition time corresponding to the second execution result of executing the test case after the code changes is 0.8s, then the code can be considered to be artificially modified in good faith. In addition, the first execution result of the test case before the code changes can be a table, and the second execution result of the test case after the code changes becomes a number, then the difference between the second execution result and the first execution result is large, then the code change type can be determined as malicious tampering first, and then the next step can be determined, whether to manually detect the rationality of the code or use other test cases to test the code.

[0057] S130. Determine the test case corresponding to the target interface according to the preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case.

[0058] According to some exemplary embodiments of the present disclosure, the preset mapping relationship between the interface and the test case can be some test cases set in advance by humans. After the corresponding interface is determined by the target function that has changed, new test cases can be generated for these interfaces. The content of the test case may include but is not limited to the main test function points, test environment, test data, execution operations and expected results, etc. After the new test case is generated, an automated testing method can be used for testing, such as writing a script program, and calling and executing the script program to complete the test, and no human participation is required. In addition, the device that executes the test case can be the same as the device that runs the code testing method of the present disclosure, or it can be different. When the devices corresponding to the two are different, after determining the interface corresponding to the target function and generating the test case, these test cases can be run on a device specifically used to execute the test case to complete the code test.

[0059] It should be noted that the terms "first", "second", etc. used in the present disclosure are only for distinguishing different versions of the code or different execution results of the code, and should not impose any limitations on the present disclosure.

[0060] In summary, the code testing method disclosed in the present invention adopts a storage method that defines the relationship between the interface and the function in the code to store the interface and the function; if the function in the code changes, the interface corresponding to the changed function is determined as the target interface; the test case corresponding to the target interface is determined according to the preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case. On the one hand, when the function in the code changes, the interface corresponding to the changed function can be determined based on the constructed tree structure, so as to accurately generate test cases for the interface. On the other hand, after the test case is generated based on the interface, only these test cases can be tested without testing the entire code, reducing the workload of code testing. On the other hand, when executing the test case, a pre-written script program can be called, and the automated testing method can be applied to perform the corresponding interface test without manual participation, further reducing the testing workload.

[0061] In addition, in this exemplary embodiment, a code testing device is also provided. Figure 4 The code testing device 400 may include a relationship storage module 410 , a target interface determination module 420 , and a test case generation module 430 .

[0062] Specifically, the relationship storage module 410 can be used to store interfaces and functions in a storage method that defines the relationship between interfaces and functions in the code; the target interface determination module 420 can be used to determine the interface corresponding to the changed function as the target interface if the function in the code changes; the test case generation module 430 can be used to determine the test case corresponding to the target interface according to the preset mapping relationship between the interface and the test case, so as to test the code with changed functions based on the test case.

[0063] The code testing device 400 uses a storage structure that can define the relationship between the interface and the function in the code to store the interface and the function. When a function in the code changes, the interface corresponding to the function will be accurately located, and a test case will be generated for the determined interface to test the code. There is no need to test the entire code, which reduces the workload of code testing. It is an effective code testing device.

[0064] According to some exemplary embodiments of the present disclosure, Figure 5 , the relationship storage module 410 includes a relationship storage unit 510.

[0065] Specifically, the relationship storage unit 510 can be used to determine multiple interfaces in the code and the functions corresponding to each interface; a tree structure is used to store multiple interfaces and the functions corresponding to each interface; wherein the tree structure defines the relationship between multiple interfaces and the functions corresponding to each interface.

[0066] The relationship storage unit 510 uses a tree structure to store interfaces and functions in the code, so that when a function in the code changes, the interface corresponding to the changed function can be accurately located based on the tree structure.

[0067] According to another exemplary embodiment of the present disclosure, referring to Figure 6 , the relationship storage unit 510 may include a relationship storage sub-unit 620.

[0068] Specifically, the relationship storage subunit 620 can be used to use the interface as the root node in the tree structure and the function in the code as the intermediate node or leaf node in the tree structure.

[0069] The relationship storage subunit 620 defines a node relationship of a tree structure, and uses the interface in the code as a root node, so that the corresponding interface can be determined according to the function.

[0070] According to another exemplary embodiment of the present disclosure, referring to Figure 7 , the target interface determination module 420 may include a target interface determination unit 710 .

[0071] Specifically, the target interface determination module 710 may include a target interface determination unit, which is used to determine a function that has changed in the code as a target function; and traverse the tree structure from bottom to top based on the target function to determine an interface corresponding to the target function as the target interface.

[0072] The target interface determination module 710 may determine the interface corresponding to the function that has changed in the code by identifying the tree structure from the bottom up.

[0073] In another exemplary embodiment of the present disclosure, a code testing device 800 is also provided. Figure 8 Compared with the code testing device 400 , the code testing device 800 may include a code change type determination module 810 in addition to the relationship storage module 410 , the target interface determination module 420 and the test case generation module 430 .

[0074] Specifically, the code change type determination module 810 can be used to determine the associated weights of each target interface and the target function if there are multiple target interfaces; judge the type of code change based on the determined associated weights of each target interface and the target function; wherein the type of code change includes good-intentioned modification and malicious tampering.

[0075] When the changed function corresponds to multiple interfaces, the code change type determination module 810 may determine different weights corresponding to different interfaces based on the degree of influence of different interfaces on the code result, so as to determine the code change type.

[0076] According to some exemplary embodiments of the present disclosure, Fig. 9 , the code change type determination module 810 may include an association weight determination unit 910 .

[0077] Specifically, the association weight determination unit 910 can be used to determine a target interface as a target test interface; determine the version of the target test interface before it is changed as a first version; determine the version of the target test interface after it is changed as a second version; obtain the running result of the code under the first version as a first test result; obtain the running result of the code under the second version as a second test result; if the difference between the second test result and the first test result is, determine the association weight between the target test interface and the target function.

[0078] The association weight determination unit 910 provides a method for determining association weights corresponding to different interfaces.

[0079] According to another exemplary embodiment of the present disclosure, referring to Fig.10 , the code change type determination module 1010 may include a code change type determination unit 1020.

[0080] Specifically, the code change type determination unit 1020 can be used to determine the execution result of the test case before the target function changes as the first execution result; determine the execution result of the test case after the target function changes as the second execution result; if the correspondence between the difference between the second execution result and the first execution result and the associated weight is greater than a preset threshold, the code change type is determined to be a good-intentioned modification; if the difference between the second execution result and the first execution result and the correspondence between the associated weight is less than or equal to the preset threshold, the code change type is determined to be a malicious tampering.

[0081] The code change type determining unit 1020 determines the code change type according to different execution results before and after the function changes.

[0082] The specific details of each virtual code testing device module mentioned above have been described in detail in the corresponding code testing method, so they will not be repeated here.

[0083] It should be noted that, although several modules or units of the code testing device are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.

[0084] In addition, in an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.

[0085] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as systems, methods or program products. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: complete hardware embodiments, complete software embodiments (including firmware, microcode, etc.), or embodiments combining hardware and software aspects, which may be collectively referred to herein as "circuits", "modules" or "systems".

[0086] Refer to the following Fig.11 1100 according to this embodiment of the present invention will be described. Fig.11 The electronic device 1100 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0087] like Fig.11 As shown, the electronic device 1100 is in the form of a general computing device. The components of the electronic device 1100 may include, but are not limited to: the at least one processing unit 1110, the at least one storage unit 1120, a bus 1130 connecting different system components (including the storage unit 1120 and the processing unit 1110), and a display unit 1140.

[0088] The storage unit stores program codes, which can be executed by the processing unit 1110, so that the processing unit 1110 executes the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification.

[0089] The storage unit 1120 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 1121 and / or a cache memory unit 1122 , and may further include a read-only memory unit (ROM) 1123 .

[0090] The storage unit 1120 may also include a program / utility 1124 having a set (at least one) of program modules 1125, such program modules 1125 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0091] Bus 1130 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0092] The electronic device 1100 may also communicate with one or more external devices 1170 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1100, and / or communicate with any device that enables the electronic device 1100 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1150. Furthermore, the electronic device 1100 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 1160. As shown, the network adapter 1160 communicates with other modules of the electronic device 1100 via a bus 1130. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1100, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0093] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.

[0094] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible embodiments, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to perform the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.

[0095] refer to Fig.12 As shown, a program product 1200 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0096] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable 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.

[0097] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0098] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.

[0099] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0100] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0101] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.

[0102] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A code testing method used to improve the test process in test management. It is characterized in that include: The interface and the function are stored in a storage method that defines the relationship between the interface and the function in the code; If a function in the code changes, determining an interface corresponding to the changed function as a target interface; Determine the test case corresponding to the target interface according to the preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case; The code testing method also includes: After determining the interface corresponding to the changed function as the target interface, if there are multiple target interfaces, determining the association weights between each target interface and the target function; Determine the execution result of the test case before the objective function changes as the first execution result; Determine an execution result of the test case after the objective function changes as a second execution result; If the degree of correspondence between the difference between the second execution result and the first execution result and the association weight is greater than a preset threshold, determining that the code change type is a good-faith modification; If the degree of correspondence between the difference between the second execution result and the first execution result and the association weight is less than or equal to a preset threshold, the code change type is determined to be malicious tampering.

2. The code testing method according to claim 1, It is characterized in that Storing the interface and the function in a storage manner that defines the relationship between the interface and the function in the code includes: Determine multiple interfaces in the code and functions corresponding to each of the interfaces; A tree structure is used to store the multiple interfaces and the functions corresponding to each of the interfaces; wherein the tree structure defines the relationship between the multiple interfaces and the functions corresponding to each of the interfaces.

3. The code testing method according to claim 2, It is characterized in that Using a tree structure to store the multiple interfaces and the functions corresponding to each of the interfaces includes: The interface is used as the root node in the tree structure, and the functions in the code are used as the intermediate nodes or leaf nodes in the tree structure.

4. The code testing method according to claim 2, It is characterized in that Determining the interface corresponding to the changed function as the target interface includes: Determine the function that has been changed in the code as the target function; The tree structure is traversed from bottom to top based on the target function to determine an interface corresponding to the target function as a target interface.

5. The code testing method according to claim 1, It is characterized in that Determining the association weight between each of the target interfaces and the target function includes: Determine a target interface as a target test interface; Determine a version of the target test interface before it is modified as the first version; Determine the modified version of the target test interface as the second version; Obtaining a running result of the code under the first version as a first test result; Obtaining a running result of the code under the second version as a second test result; If the difference between the second test result and the first test result is determined, the association weight between the target test interface and the target function is determined.

6. A code testing device, It is characterized in that include: A relationship storage module, used to store the interface and the function in a storage manner that defines the relationship between the interface and the function in the code; A target interface determination module, used for determining an interface corresponding to the changed function as a target interface if a function in the code changes; A test case generation module, used to determine the test case corresponding to the target interface according to a preset mapping relationship between the interface and the test case, so as to test the code with the changed function based on the test case; A code change type determination module, configured to, after determining the interface corresponding to the changed function as the target interface, determine the association weights of each of the target interfaces with the target function if there are multiple target interfaces; Determine the execution result of the test case before the objective function changes as the first execution result; Determine an execution result of the test case after the objective function changes as a second execution result; If the degree of correspondence between the difference between the second execution result and the first execution result and the association weight is greater than a preset threshold, determining that the code change type is a good-faith modification; If the degree of correspondence between the difference between the second execution result and the first execution result and the association weight is less than or equal to a preset threshold, the code change type is determined to be malicious tampering.

7. An electronic device, It is characterized in that include: processor; as well as A memory having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by the processor, implement the code testing method according to any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the code testing method according to any one of claims 1 to 5.