A method and apparatus for code detection

By constructing an interface call chain set and selecting target chains based on weights for code detection, the problems of excessively long detection time and insufficient accuracy in existing technologies are solved, achieving more efficient and accurate code detection.

CN115017041BActive Publication Date: 2026-11-06BEIJING SANKUAI ONLINE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210609981.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-31
Publication Date
2026-11-06
Estimated Expiration
2042-05-31

AI Technical Summary

Technical Problem

Existing technologies, when performing full regression testing after code iteration, suffer from problems such as excessively long testing time and insufficient detection accuracy, and are prone to missing interfaces that need to be tested.

Method used

By constructing an interface call link set, the weights of the target interface and its candidate links are determined, and the target links are selected for detection. The detection accuracy is improved by utilizing the weight information in the pre-constructed interface call link set.

Benefits of technology

It improves the accuracy of code detection, reduces detection time, and avoids missing interfaces.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115017041B_ABST
    Figure CN115017041B_ABST
Patent Text Reader

Abstract

This specification discloses a method and apparatus for code detection. Specifically, it discloses that the interface corresponding to the code to be tested is identified as the target interface. Then, based on the target interface, interface call chains containing the target interface are identified from a pre-built set of interface call chains as candidate chains. Next, the target chain is selected from the candidate chains according to the weights corresponding to each candidate chain. Finally, the code to be tested is detected based on the target interface and the target chain. For each candidate chain, the weight corresponding to that candidate chain represents the number of times each interface in that candidate chain has been called within a past period. In this way, by determining the weight of each interface call chain based on the actual call data of each interface call chain in the pre-built set over a past period, and then selecting the target chain based on this weight, the accuracy of code detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of computer technology, and in particular to a method and apparatus for code detection. Background Technology

[0002] Currently, after code updates and iterations in online applications, the iterated code is often tested to ensure it can fulfill the corresponding business requirements. In actual business scenarios, after code iteration, a full regression test can be performed directly on the updated code to ensure it meets actual business needs.

[0003] However, with the expansion of online business, continuing to use full regression testing for code inspection would lead to excessively long testing times due to the large codebase. To avoid this, technical personnel typically use their experience to determine the API call chain containing the APIs that need to be tested, and then identify the APIs to be inspected. However, identifying APIs in this way often suffers from poor accuracy due to over-reliance on the individual skills and familiarity of technical personnel with the business, easily overlooking APIs that need to be tested, resulting in missed tests. Summary of the Invention

[0004] This specification provides a method and apparatus for code detection, which partially solves the aforementioned problems existing in the prior art.

[0005] The following technical solution is adopted in this specification:

[0006] This manual provides a method for code detection, including:

[0007] Identify the interface corresponding to the code to be tested, and designate it as the target interface;

[0008] Based on the target interface, identify the interface call chains containing the target interface from the pre-built set of interface call chains, and use them as candidate chains;

[0009] Based on the weights corresponding to each candidate link, the target link is selected from the candidate links. For each candidate link, the weight corresponding to the candidate link is used to characterize the number of times each interface in the candidate link has been called in the past period of time.

[0010] The code to be tested is detected based on the target interface and the target link.

[0011] Optionally, an interface call chain set is constructed, specifically including:

[0012] The acquired historical log data is deduplicated to obtain the deduplicated historical log data.

[0013] For each deduplicated historical log data, an interface call chain corresponding to that historical log data is generated based on the interfaces called during business execution and the order in which those interfaces are called.

[0014] Based on the API call chain corresponding to each deduplicated historical log data, construct an API call chain set.

[0015] Optionally, an interface call chain set is constructed, specifically including:

[0016] For each historical log data obtained, an interface call chain corresponding to that historical log data is generated based on the interfaces called during business execution and the order in which those interfaces are called.

[0017] For each interface call chain, if it is determined that there exists another interface call chain that contains all the interfaces within that interface call chain and whose call order is the same as that interface call chain, then that interface call chain will not be added to the interface call chain set, and the number of times each interface contained in that interface call chain has been called in the past period will be added to the number of times each interface contained in the other interface call chain has been called in the past period.

[0018] Optionally, an interface call chain set is constructed, specifically including:

[0019] For each historical log data obtained, an interface call chain corresponding to that historical log data is generated based on the interfaces called during business execution and the order in which those interfaces are called.

[0020] For two call chains containing interfaces that are not completely identical, if it is determined that the number of interfaces in the same part meets the preset quantity condition, and the interfaces in the same part are consistent in the calling order, then the number of times the interfaces in the same part of these two call chains have been called in the past period of time will be merged, so as to adjust the number of times the interfaces contained in these two call chains have been called in the past period of time.

[0021] Based on the adjusted call chain for each interface, construct an interface call chain set.

[0022] Optionally, the weights corresponding to each candidate link are determined, specifically including:

[0023] For each candidate link, the attenuation coefficient corresponding to each time period is determined based on the time coefficient corresponding to the number of time periods contained in the past period. The larger the number of time periods contained in the past period, the smaller the time coefficient. For each time period, the further away the time period is from the current time, the smaller the attenuation coefficient corresponding to the time period.

[0024] The weight of a candidate link is determined based on the attenuation coefficient corresponding to each time period and the number of times each interface in the candidate link is called within each time period.

[0025] Optionally, after constructing the interface call chain set, it also includes:

[0026] For each interface call chain in the interface call chain set, determine the code corresponding to each interface contained in the interface call chain, and determine the code sequence corresponding to the interface call chain according to the call order of each interface contained in the interface call chain;

[0027] Save the encoding sequence corresponding to each interface call link in the interface call link set.

[0028] Optionally, based on the target interface, interface call chains containing the target interface are determined from a pre-built set of interface call chains as candidate chains, specifically including:

[0029] Determine the encoding corresponding to the target interface;

[0030] From the saved encoding sequences, determine the encoding sequence that contains the encoding corresponding to the target interface, and use it as a candidate encoding sequence;

[0031] Based on the candidate encoding sequence, an interface call chain containing the target interface is determined as a candidate chain.

[0032] Optionally, the code to be tested is detected based on the target interface and the target link, specifically including:

[0033] Obtain test cases for the target interface and the target link. The test cases include: preset test cases and test cases for replaying the target link using pre-recorded online business data of the target link.

[0034] The code to be tested is examined according to the test cases.

[0035] Optionally, obtaining test cases set for the target interface and the target link specifically includes:

[0036] Based on the position of the target interface in the target link, determine the interface that is called before the target interface as the upstream interface corresponding to the target interface, and the interface that is called after the target interface as the downstream interface corresponding to the target interface.

[0037] Test cases that can call the target interface, the upstream interface, and the downstream interface are identified.

[0038] Optionally, the method further includes:

[0039] Based on the obtained test results, the interface information of the interfaces called in the target link during the testing of the code to be tested is marked on the display interface.

[0040] This specification provides a code detection device, comprising:

[0041] The interface determination module is used to determine the interface corresponding to the code to be tested, which is then used as the target interface.

[0042] The candidate link determination module is used to determine, based on the target interface, an interface call link containing the target interface from a pre-built set of interface call links, as a candidate link;

[0043] The target link determination module is used to select the target link from the candidate links according to the weights corresponding to each candidate link. For each candidate link, the weight corresponding to the candidate link is used to characterize the number of times each interface in the candidate link has been called in the past period of time.

[0044] The code detection module is used to detect the code to be tested based on the target interface and the target link.

[0045] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described code detection method.

[0046] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described code detection method.

[0047] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:

[0048] In the code detection method provided in this specification, the interface corresponding to the code to be tested is determined as the target interface. Then, based on the target interface, the interface call chains containing the target interface are determined from the pre-built interface call chain set as candidate chains. Then, based on the weights corresponding to each candidate chain, the target chain is selected from the candidate chains. Finally, the code to be tested is detected based on the target interface and the target chain. For each candidate chain, the weight corresponding to the candidate chain is used to characterize the number of times each interface in the candidate chain has been called in the past period of time.

[0049] As can be seen from the above method, this method can determine the weight of each interface call chain based on the actual call status of each interface call chain in the pre-built interface call chain set over a period of time, and then select the target chain based on the weight to detect the code to be tested, thereby improving the accuracy of code detection. Attached Figure Description

[0050] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and are used to explain this specification, but do not constitute an undue limitation thereof. In the drawings:

[0051] Figure 1 This is a flowchart illustrating one of the code detection methods described in this specification;

[0052] Figure 2A This is a schematic diagram of the system structure for code detection in this specification;

[0053] Figure 2B This is a schematic diagram of an interface call chain in one of the embodiments provided in this specification;

[0054] Figure 3 A schematic diagram of a code detection device provided in this specification;

[0055] Figure 4 The corresponding information provided in this specification Figure 1 A schematic diagram of an electronic device. Detailed Implementation

[0056] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.

[0057] The code detection scheme provided in this specification will be described in detail below with reference to the embodiments.

[0058] Figure 1 This is a flowchart illustrating one of the code detection methods described in this specification, which specifically includes the following steps:

[0059] Step S100: Determine the interface corresponding to the code to be tested, and use it as the target interface.

[0060] In internet businesses, after online services are deployed and launched, the business code often needs to be continuously adjusted and iterated based on business requirements to adapt to new needs. In actual business operations, after code updates and iterations, code testing is required to determine whether the iterated code can stably implement the corresponding business requirements.

[0061] With the rapid development of internet technology, more and more online businesses are adopting distributed systems to ensure business execution efficiency. In this case, testing the iterated code often relies on the experience of technical personnel and their understanding of the business they are responsible for to identify the API code that needs to be tested. However, this testing method suffers from over-reliance on the business experience of technical personnel, making it prone to missed detections.

[0062] To address this issue, this specification provides a code detection method. This method first identifies the interface corresponding to the code to be tested as the target interface. Then, based on the target interface, it identifies interface call chains containing the target interface from a pre-built set of interface call chains as candidate chains. Next, based on the weights of each candidate chain, it selects the target chain. Finally, it detects the code to be tested based on the target interface and the target chain. In this way, by determining the weights of each interface call chain in the pre-built set based on their actual call behavior over a past period, and then selecting the target chain based on these weights to detect the code to be tested, the accuracy of code detection is improved.

[0063] In practice, after detecting a test command, the terminal device scans the iterated code, identifies the modified code to be tested, and then, based on a pre-defined mapping between code implementations and interfaces, determines the interface corresponding to the code under test and uses that interface as the target interface. In a distributed system, the terminal device first determines the business system to which the code under test belongs, and then queries the mapping between each code implementation and each interface within that system to determine the interface corresponding to the code under test. This business system refers to systems responsible for different business functions, such as the chat system, customer service system, and intelligent question-and-answer system within a food delivery business platform. Furthermore, the interface corresponding to the code under test can be an Application Programming Interface (API).

[0064] It should be noted that the execution entity for code testing in this manual can be either the terminal devices mentioned above, such as desktop computers and laptops, or a server. In actual business scenarios, a dedicated testing system can be pre-built and then deployed to the terminal device or server to test the code to be tested in the iterated code. For ease of description, this manual will only use the example of the testing system being deployed on a terminal device.

[0065] In actual business operations, see Figure 2A The testing system may include: an environment configuration module, a data acquisition module, an interface call chain set construction module, a chain encoding module, a code to be tested determination module, a test case determination module, an automated testing module, and a display module.

[0066] The environment configuration module is used to configure the business systems that need to be monitored, as well as the business environments that need to be detected (such as online business environments and offline business environments).

[0067] The data acquisition module is used to monitor the call status of interfaces in the configured business modules and between business modules when a business request is executed, including the name of the interface called and the order of interface calls, as historical log data.

[0068] The interface call chain set construction module is used to generate a set of interface call chains that can represent the number of times the interface was called in the past period of time based on historical log data and the interface call situation corresponding to historical business requests, and to determine the scope of the detection during interface detection.

[0069] The link encoding module is used to encode the sequence corresponding to each interface call link in the interface call link set after obtaining the interface call link set.

[0070] The code module to be tested is used to scan the iterated code during code inspection, identify the interfaces to be tested, and obtain the corresponding target interfaces.

[0071] The test case determination module is used to determine the test cases set for the target interface and the target link corresponding to the target interface.

[0072] The automated testing module is used to test the code to be tested based on the identified test cases.

[0073] The display module is used to display the target link in the display interface based on the determined test results, and mark the interface information of the interface called in the target link during the testing of the code under test.

[0074] Step S102: Based on the target interface, determine the interface call links containing the target interface from the pre-built set of interface call links, and use them as candidate links.

[0075] In practice, after obtaining the target interface, the terminal device determines the code corresponding to the target interface. Then, it selects the code sequence containing the code corresponding to the target interface from the saved code sequences as candidate code sequences. Based on the candidate code sequences, it determines the interface call chain containing the target interface as a candidate chain.

[0076] The interface call chain set is pre-built. When storing each interface call chain in the interface call chain set, it is necessary to determine the code corresponding to each interface in the interface call chain for each interface call chain in the interface call chain set, and determine the code sequence corresponding to the interface call chain according to the calling order of each interface in the interface call chain. Then, the code sequence corresponding to each interface call chain in the interface call chain set is saved.

[0077] The following sections will explain how to construct an API call chain set and how to determine the encoding sequence corresponding to the API call chain.

[0078] In practice, when constructing the interface call chain set, the terminal device can obtain historical log data of each business system when executing business in the past, and then determine the interface call chain used to construct the interface call chain set from the historical log data.

[0079] In actual business operations, corresponding interface monitoring points will be pre-set for all interfaces contained in all business modules involved in the distributed system and for all interfaces between business modules. Through these interface monitoring points, the interfaces called in the distributed system and the order in which the interfaces are called when business requests are executed can be monitored as historical log data.

[0080] Then, after the terminal device detects that the set period has been reached, it determines the business module to be monitored as the target module according to the pre-set environment configuration parameters. Then, it obtains the historical log data corresponding to the target module. For each historical log data, it generates the interface call chain corresponding to the historical log data based on the interfaces called during the execution of the business and the call order of each interface contained in the historical log data. Based on the generated interface call chains corresponding to each historical log data, an interface call chain set is constructed.

[0081] If each historical log data has a corresponding collection time, when obtaining the historical log data corresponding to the target module, the historical log data can be divided according to the collection time of each historical log data according to the set time interval to obtain several historical log data segments. Then, for each historical log data segment obtained after division, a set number of historical log data are extracted from it. Finally, for each extracted historical log data, the corresponding interface call chain is generated.

[0082] During this process, if the historical log data does not record the corresponding collection time, the historical log data corresponding to the target module acquired by the terminal device each time includes all historical log data collected within the current log collection period. Thus, when it is impossible to distinguish each historical log data based on its corresponding collection time, a set number of historical log data can be extracted from the historical log data corresponding to the target module each time it is acquired. Then, for each extracted historical log data, it is compared with each previously extracted historical log data. If they match, it indicates that an interface call chain has already existed based on that historical log data, so the historical log data is discarded. If they do not match, it indicates that an interface call chain has not existed based on that historical log data, so the historical log data is retained, resulting in deduplicated historical log data.

[0083] Then, when constructing an interface call chain set based on the interface call chain generated from historical log data, for each interface call chain, if it is determined that there are other interface call chains that contain all the interfaces in that interface call chain and have the same call order as that interface call chain, then that interface call chain will not be added to the interface call chain set, and the number of times each interface contained in that interface call chain has been called in the past period will be added to the number of times each interface contained in other interface call chains has been called in the past period.

[0084] For example, there is an interface call chain 1: Interface A—Interface B—Interface C—Interface D—Interface E—Interface F, which is called 1000 times in total;

[0085] Interface call chain 2: Interface B—Interface C—Interface D, a total of 500 calls;

[0086] Interface call chain 3: Interface A—Interface B—Interface C—Interface D—Interface E, a total of 300 calls;

[0087] For interface call chain 2, if interface call chain 1 contains all the interfaces in interface call chain 2, and the calling order of each interface in interface call chain 1 is the same as that in interface call chain 2, then interface call chain 2 does not need to be added to the interface call chain set. Instead, the number of times each interface in interface call chain 2 has been called in the past period is added to the number of times each interface in interface call chain 1 has been called in the past period.

[0088] Similarly, for interface call chain 3, if interface call chain 1 contains all the interfaces in interface call chain 3, and the calling order of each interface in interface call chain 1 is the same as that of interface call chain 3, then interface call chain 3 does not need to be added to the interface call chain set, and the number of times each interface contained in interface call chain 3 has been called in the past period is added to the number of times each interface contained in interface call chain 1 has been called in the past period.

[0089] In this way, the number of times each interface in interface call chain 2 and interface call chain 3 has been called in the past period is simultaneously added to the number of times each interface in interface call chain 1 has been called in the past period.

[0090] It should be noted that, in this specification, when adding the number of times each interface in one interface call chain has been called over a past period to the number of times each interface in another interface call chain has been called over a past period, the number of times the corresponding interfaces in the two interface call chains have been called over a past period can be directly added together. Continuing with the previous example, when adding the number of times each interface in interface call chain 2 has been called over a past period to the number of times each interface in interface call chain 1 has been called over a past period, the number of calls to interfaces B, C, and D in interface call chain 1 becomes 1000 + 500 = 1500.

[0091] Alternatively, one could first determine the sum of the number of calls to each interface in both call chains, and then sum the sums of the number of calls to each interface in both call chains. Continuing with the previous example, when the number of calls to each interface in call chain 2 over a past period is added to the number of calls to each interface in call chain 1 over a past period, the total number of calls to interfaces B, C, and D in call chain 1 becomes 1000×3 + 500×3 = 4500.

[0092] It should be noted that, for ease of calculation in actual business applications, the interface call chain can be treated as a whole. When the number of times each interface in interface call chain 2 was called over a past period is added to the number of times each interface in interface call chain 1 was called over a past period, the call count for each interface in interface call chain 1 (including interfaces A, B, C, D, E, and F) can be changed to 1000 + 500 = 1500. Alternatively, the total call count for each interface in interface call chain 1 (including interfaces A, B, C, D, E, and F) can be changed to 1000 × 6 + 500 × 3 = 7500.

[0093] By performing the above operations and filtering the interface call chains generated from historical log data, the number of each interface call chain in the interface call chain set can be further reduced, thereby reducing data redundancy.

[0094] In addition, this specification can also address two interface call chains that contain interfaces that are not completely identical. If it is determined that the number of interfaces in the same part meets a preset quantity condition, and the interfaces in the same part are consistent in the calling order, then the number of times the interfaces in the same part of these two interface call chains have been called in the past period of time will be merged to adjust the number of times the interfaces contained in these two interface call chains have been called in the past period of time. Then, based on each adjusted interface call chain, an interface call chain set will be constructed.

[0095] In this way, by merging the number of times the same part of the interface in the call chain of two interfaces that are not completely the same, the call situation of each interface during the actual business execution can be restored to the greatest extent. This allows the final selected target chain to better reflect the actual call situation of the interface, thereby improving the accuracy of code detection.

[0096] It should be noted that in this specification, redundancy screening can be performed first, and then the number of times the interfaces with the same part in two interface call chains that are not completely identical can be merged over a period of time. Alternatively, the number of times the interfaces with the same part in two interface call chains that are not completely identical can be merged over a period of time, and then redundancy screening can be performed to ensure that each interface call chain in the interface call chain set cannot be deleted.

[0097] It should also be noted that, in this specification, when merging the number of times the interfaces in the same part of the two interface call chains have been called in the past period, you can either directly add up the number of times the corresponding interfaces in the two interface call chains have been called in the past period, or you can first determine the sum of the number of times each interface in the two interface call chains has been called, and then add up the sum of the number of times each interface in the two interface call chains has been called.

[0098] After obtaining the set of interface call chains, directly storing each interface call chain in the database might lead to excessive data volume and wasted system resources. Therefore, this specification determines the code corresponding to each interface in each interface call chain within the set, and determines the code sequence corresponding to the interface call chain according to the call order of the interfaces in the set. The code sequence corresponding to each interface call chain in the set is then saved to reduce the system resources consumed.

[0099] The following section will explain in detail how to encode the interfaces in the API call chain to obtain the corresponding encoding sequence of the API call chain.

[0100] In practice, the terminal device first needs to determine the interface information of each interface in the interface call chain set, and then encode the interface information of the interface according to the preset encoding rules to obtain the corresponding encoding of the interface.

[0101] The interface information includes different types of data such as: the business module to which the interface belongs, the position of the interface in its own interface call chain, the fully qualified class name of the interface, the method name of the interface, and the method parameters of the interface. Then, for each type of data, the possible values ​​of that type of data are encoded and combined to obtain the corresponding code for the interface.

[0102] For example, there are three business modules: business module A, business module B, and business module C. The coding rules for the business modules to which the interfaces belong are as follows: business module A—1, business module B—2, and business module C—3.

[0103] For interface information that specifies the position of an interface within its own call chain, it can be recorded in the format of "the interface's level in the call chain—which branch of the call chain the interface belongs to." For example, the call chain might look like this: Figure 2B As shown, the position of interface A in this interface call chain can be encoded as 1-1, the position of interface B in this interface call chain can be encoded as 2-1, the position of interface C in this interface call chain can be encoded as 3-1, the position of interface D in this interface call chain can be encoded as 4-1, the position of interface E in this interface call chain can be encoded as 4-2, the position of interface F in this interface call chain can be encoded as 5-1-1, the position of interface G in this interface call chain can be encoded as 5-1-2, and the position of interface H in this interface call chain can be encoded as 6-1-1.

[0104] Furthermore, since each interface within the same business module is unique, within a business module, if a matching interface can be identified based on its fully qualified class name, method name, and method parameters, then there is one and only one interface corresponding to this information. Thus, in this specification, one-hot encoding can be performed on the interface information contained within each service. For example, suppose a business module contains three interfaces: Interface A, Interface B, and Interface C; Interface A: Interface information for Interface A (fully qualified class name, method name, method parameters) — 1; Interface B: Interface information for Interface B (fully qualified class name, method name, method parameters) — 2; Interface C: Interface information for Interface C (fully qualified class name, method name, method parameters) — 3; ..., Interface information for Interface H (fully qualified class name, method name, method parameters) — 8.

[0105] Thus, if the above encoding rules are followed, for Figure 2B The interface B in the business module C in the interface call chain shown is encoded, and the encoding of interface B can be (3, 2-1, 2).

[0106] Ultimately, if Figure 2BWhen all the interface call chains shown belong to business module C, the encoding sequence corresponding to the interface call chain is: (3, 1-1, 1) — (3, 2-1, 2) — (3, 3-1, 3) — (3, 4-1, 4) — (3, 4-2, 5) — (3, 5-1-1, 6) — (3, 5-1-2, 7) — (3, 6-1-1, 8).

[0107] Thus, by using the encoding method described in the above embodiments to determine the encoding sequence corresponding to each interface call link in the interface call link set, the encoding sequence corresponding to each interface call link can be saved to the database so as to determine the target link during subsequent code testing.

[0108] In practice, after determining the target interface, the terminal device will first determine the code corresponding to the target interface. Then, from the saved code sequences, it will determine the code sequence containing the code corresponding to the target interface as a candidate code sequence. Then, based on the candidate code sequence, it will determine the interface call chain containing the target interface as a candidate chain.

[0109] Specifically, after identifying the target interface, the terminal device can determine the corresponding interface information (including the business module to which the interface belongs, and the fully qualified class name, method name, and method parameters of the interface) for that target interface. Then, based on the aforementioned encoding rules, the terminal device can determine the first sub-code corresponding to the business module to which the interface belongs, and the second sub-code corresponding to the fully qualified class name, method name, and method parameters of the interface. Next, based on the first and second codes, the device queries each encoding sequence to identify codes that simultaneously contain both the first and second sub-codes. Then, the encoding sequence containing the identified codes is used as a candidate encoding sequence. For each candidate encoding sequence, each code in the candidate encoding sequence is de-encoded according to preset encoding rules to obtain each interface contained in the interface call chain corresponding to that encoding sequence. Finally, based on the interface positions indicated by each code in the candidate encoding sequence and the de-encoded interfaces, the interface call chain corresponding to that encoding sequence is constructed, and the constructed interface call chains corresponding to each candidate encoding sequence are used as candidate chains.

[0110] Step S104: Based on the weights corresponding to each candidate link, select the target link from the candidate links. For each candidate link, the weight corresponding to the candidate link is used to characterize the number of times each interface in the candidate link has been called in the past period of time.

[0111] In practice, the terminal device first determines the weight of each candidate link. Specifically, for each candidate link, the terminal device determines the attenuation coefficient for each time period based on the time coefficient corresponding to the number of time periods contained in the past period. Then, based on the attenuation coefficient for each time period and the number of times each interface in the candidate link is called within each time period, the weight of the candidate link is determined. The larger the number of time periods contained in the past period, the smaller the time coefficient. For each time period, the further away the time period is from the current time, the smaller the attenuation coefficient for that time period.

[0112] In this specification, the weight coefficient corresponding to each interface call chain can be determined by the following formula:

[0113]

[0114] Where T represents the total number of time periods contained in the past period;

[0115] T represents the t-th time period counting backwards from the current time.

[0116] c t This represents the number of times each interface in the candidate link is called in each time period within the t-th time period counting backwards from the current time.

[0117] α represents the time coefficient, α < 1;

[0118] (1-α) t-1 This represents the decay coefficient corresponding to the t-th time period counting backwards from the current time.

[0119] The attenuation coefficient α can be taken as follows:

[0120] After determining the weight of each interface call chain, a set number of interface call chains can be selected based on their weights to form the interface call chain set. For example, only the interface call chain with the highest weight can be selected as the target interface chain. Another example is selecting interface call chains with weights greater than a set weight as the target interface chains. Other selection methods will not be listed here.

[0121] It should be noted that the number of times each interface in the candidate link is called in each time period can refer to the sum of the number of times each interface in the candidate link is called in each time period, or it can be the maximum value among the number of times each interface in the candidate link is called in each time period.

[0122] Step S106: Detect the code to be tested based on the target interface and the target link.

[0123] In practice, the terminal device acquires test cases set for the target interface and target link, and then tests the code to be tested based on these test cases. These test cases include: preset test cases, and test cases that replay the target link using pre-recorded online business data.

[0124] When the test case is a pre-defined test case, the terminal device first determines the interfaces called before the target interface as the upstream interfaces corresponding to the target interface, and the interfaces called after the target interface as the downstream interfaces corresponding to the target interface, based on the position of the target interface in the target link. Then, it determines the test cases that can call the target interface, upstream interfaces, and downstream interfaces. Finally, it configures the determined test cases in the pre-defined automated test script and runs the test script to obtain the test results of the code to be tested. The test results include at least one of the following: whether the test case was successfully executed (success / failure), the interfaces covered by the test case execution results, and the code coverage of the test case.

[0125] It should be noted that if the target link is the candidate link with the highest weight, then test cases that can call at least one of the target interface, upstream interface, and downstream interface can be used as test cases to test the code under test. In actual business scenarios, test cases that can call the target interface, upstream interface, and downstream interface simultaneously can also be selected as test cases to test the code under test.

[0126] This test case involves replaying the target link using pre-recorded online business data. The terminal device first obtains the pre-recorded business data for the target link, and generates test cases for testing the code under test based on the recorded business data. Then, it configures the generated test cases in the preset automated test script and runs the test script to obtain the test results of the code under test.

[0127] It should be noted that these two testing methods can be used simultaneously in this manual to test the code to be tested, so as to improve testing efficiency while ensuring code coverage of interface tests.

[0128] Finally, after completing the testing of the code under test, this manual will also display the obtained code testing results to the technical personnel conducting the code testing, so that they can quickly understand the monitoring status of the code under test. Specifically, based on the obtained testing results, the terminal device will mark the interface information of the interfaces called within the target link during the testing of the code under test on the display interface. This interface information includes the name of the interface, whether the interface was called, and whether the code under test corresponding to the interface passed the test.

[0129] In addition, this manual can also use a message push mode to return the interface information of the interfaces called in the target link during the testing of the code to be tested to the technical personnel for viewing.

[0130] It should be noted that all actions involving the acquisition of signals, information, or data in this manual are performed in accordance with the relevant data protection laws and regulations of the country where the device is located, and with the authorization of the owner of the relevant device.

[0131] The above describes one or more embodiments of the code detection method provided in this specification. Based on the same idea, this specification also provides corresponding code detection apparatus, such as... Figure 3 As shown.

[0132] Figure 3 This specification provides a schematic diagram of a code detection device, which specifically includes:

[0133] The interface determination module 300 is used to determine the interface corresponding to the code to be tested, which is then used as the target interface.

[0134] The candidate link determination module 301 is used to determine, based on the target interface, an interface call link containing the target interface from a pre-built set of interface call links, as a candidate link;

[0135] The target link determination module 302 is used to select a target link from each candidate link according to the weights corresponding to each candidate link. For each candidate link, the weight corresponding to the candidate link is used to characterize the number of times each interface in the candidate link has been called in the past period of time.

[0136] The code detection module 303 is used to detect the code to be tested based on the target interface and the target link.

[0137] Optionally, the device includes:

[0138] The link set construction module 304 is used to deduplicate the acquired historical log data to obtain deduplicated historical log data; for each deduplicated historical log data, it generates the corresponding interface call link based on the interfaces called during business execution and the calling order of the interfaces contained in the historical log data; and constructs an interface call link set based on the interface call links corresponding to each deduplicated historical log data.

[0139] Optionally, the link set construction module 304 is specifically used to generate an interface call link corresponding to each historical log data for each acquired historical log data, based on the interfaces called during business execution contained in the historical log data and the calling order of each interface; for each interface call link, if it is determined that there is another interface call link that contains all the interfaces in the interface call link and has the same calling order as the interface call link, then the interface call link is not added to the interface call link set, and the number of times each interface contained in the interface call link has been called in the past period is added to the number of times each interface contained in the other interface call links has been called in the past period.

[0140] Optionally, the link set construction module 304 is specifically used to generate an interface call link corresponding to each historical log data for each acquired historical log data, based on the interfaces called during business execution contained in the historical log data and the calling order of each interface; for two interface call links containing interfaces that are not completely identical, if it is determined that the number of interfaces in the same part meets a preset quantity condition, and the interfaces in the same part are consistent in the calling order, then the number of times the interfaces in the same part of these two interface call links have been called in the past period are merged, so as to adjust the number of times the interfaces contained in these two interface call links have been called in the past period; and construct an interface call link set based on each adjusted interface call link.

[0141] Optionally, the device includes:

[0142] The weight determination module 305 is used to determine the attenuation coefficient corresponding to each time period for each candidate link based on the time coefficient corresponding to the number of time periods contained in the past period. The larger the number of time periods contained in the past period, the smaller the time coefficient. For each time period, the further away the time period is from the current time, the smaller the attenuation coefficient corresponding to the time period.

[0143] The weight of a candidate link is determined based on the attenuation coefficient corresponding to each time period and the number of times each interface in the candidate link is called within each time period.

[0144] Optionally, the device further includes:

[0145] The encoding module 306 is used to determine the encoding corresponding to each interface in the interface call chain for each interface call chain in the interface call chain set, and to determine the encoding sequence corresponding to the interface call chain according to the calling order of each interface in the interface call chain.

[0146] Save the encoding sequence corresponding to each interface call link in the interface call link set.

[0147] Optionally, the candidate link determination module 301 is specifically used to determine the encoding corresponding to the target interface; determine the encoding sequence containing the encoding corresponding to the target interface from the stored encoding sequences, as a candidate encoding sequence; and determine the interface call link containing the target interface based on the candidate encoding sequence, as a candidate link.

[0148] Optionally, the code detection module 303 is specifically used to obtain test cases set for the target interface and the target link. The test cases include: preset test cases and test cases for replaying the target link using pre-recorded online business data of the target link.

[0149] The code to be tested is examined according to the test cases.

[0150] Optionally, the code detection module 303 is specifically used to determine, based on the position of the target interface in the target link, the interface called before the target interface as the upstream interface corresponding to the target interface, and the interface called after the target interface as the downstream interface corresponding to the target interface; and to determine test cases that can call the target interface, the upstream interface, and the downstream interface.

[0151] Optionally, the device further includes:

[0152] The marking module 307 is used to mark the interface information of the interface called in the target link during the testing of the code to be tested in the display interface according to the obtained detection results.

[0153] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 The provided code detection method.

[0154] This instruction manual also provides Figure 4 The diagram shows a schematic structural representation of the electronic device. Figure 4At the hardware level, the electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for the business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to achieve the above-mentioned functions. Figure 1 The code detection method described herein. Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. In other words, the execution subject of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.

[0155] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages ​​and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.

[0156] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.

[0157] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.

[0158] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware components.

[0159] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0160] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0161] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0162] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0163] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0164] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0165] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0166] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0167] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0168] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0169] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0170] The above description is merely an embodiment of this specification and is not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.

Claims

1. A method for code detection, characterized in that, include: Constructing an API call chain set specifically includes: For each historical log data obtained, an interface call chain corresponding to that historical log data is generated based on the interfaces called during business execution and the order in which those interfaces are called. For each interface call chain, if it is determined that there exists another interface call chain that contains all the interfaces within that interface call chain and whose call order is the same as that interface call chain, then that interface call chain will not be added to the interface call chain set, and the number of times each interface contained in that interface call chain has been called in the past period will be added to the number of times each interface contained in the other interface call chain has been called in the past period. For each interface call chain in the interface call chain set, determine the code corresponding to each interface contained in the interface call chain, and determine the code sequence corresponding to the interface call chain according to the call order of each interface contained in the interface call chain; Save the encoding sequence corresponding to each interface call link in the interface call link set; Identify the interface corresponding to the code to be tested, and designate it as the target interface; Based on the target interface, interface call chains containing the target interface are determined from a pre-built set of interface call chains as candidate chains, specifically including: Determine the encoding corresponding to the target interface; From the saved encoding sequences, determine the encoding sequence that contains the encoding corresponding to the target interface, and use it as a candidate encoding sequence; Based on the candidate encoding sequence, an interface call chain containing the target interface is determined as a candidate chain; Based on the weights corresponding to each candidate link, the target link is selected from the candidate links. For each candidate link, the weight corresponding to the candidate link is used to characterize the number of times each interface in the candidate link has been called in the past period of time. The code to be tested is detected based on the target interface and the target link.

2. The method according to claim 1, characterized in that, Building an API call chain also includes: The acquired historical log data is deduplicated to obtain the deduplicated historical log data. For each deduplicated historical log data, an interface call chain corresponding to that historical log data is generated based on the interfaces called during business execution and the order in which those interfaces are called. Based on the API call chain corresponding to each deduplicated historical log data, construct an API call chain set.

3. The method according to claim 1, characterized in that, Building an API call chain also includes: For two call chains containing interfaces that are not completely identical, if it is determined that the number of interfaces in the same part meets the preset quantity condition, and the interfaces in the same part are consistent in the calling order, then the number of times the interfaces in the same part of these two call chains have been called in the past period of time will be merged, so as to adjust the number of times the interfaces contained in these two call chains have been called in the past period of time. Based on the adjusted call chain for each interface, construct an interface call chain set.

4. The method according to claim 1, characterized in that, Determine the weights corresponding to each candidate link, specifically including: For each candidate link, the attenuation coefficient corresponding to each time period is determined based on the time coefficient corresponding to the number of time periods contained in the past period. The larger the number of time periods contained in the past period, the smaller the time coefficient. For each time period, the further away the time period is from the current time, the smaller the attenuation coefficient corresponding to the time period. The weight of a candidate link is determined based on the attenuation coefficient corresponding to each time period and the number of times each interface in the candidate link is called within each time period.

5. The method according to claim 1, characterized in that, The code to be tested is inspected based on the target interface and the target link, specifically including: Obtain test cases for the target interface and the target link, the test cases including: Pre-set test cases, and test cases for replaying the target link using pre-recorded online business data of the target link; The code to be tested is examined according to the test cases.

6. The method according to claim 5, characterized in that, Obtain test cases for the target interface and the target link, specifically including: Based on the position of the target interface in the target link, determine the interface that is called before the target interface as the upstream interface corresponding to the target interface, and the interface that is called after the target interface as the downstream interface corresponding to the target interface. Test cases that can call the target interface, the upstream interface, and the downstream interface are identified.

7. The method according to claim 1, characterized in that, The method further includes: Based on the obtained test results, the interface information of the interfaces called in the target link during the testing of the code to be tested is marked on the display interface.

8. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the method described in any one of claims 1 to 7.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Online test case generation method, device and electronic device

    CN109062809A

  • Code testing method and device, electronic equipment and storage medium

    CN110147317A