Interface comparison test method and device

By using proxy classes during the test process to intercept the original interface and call the comparison interface, and compare the similarities and differences of the return value, the problems of insufficient test coverage and performance impact in the existing technology are solved, and more accurate test results and reduced replacement risks are achieved. .

CN113468041BActive Publication Date: 2025-02-25BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010237645.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-30
Publication Date
2025-02-25
Estimated Expiration
2040-03-30

AI Technical Summary

Technical Problem

In the existing technology, the test process cannot cover all test cases, which affects the accuracy of the test results, resulting in a high risk of replacement of new and old systems; during the test process, it is necessary to compare the return values ​​of new and old interfaces in real time, affecting the performance of the old system; every new addition For comparison of one interface, you need to modify the code of the old system before going online.

Method used

When the original interface receives the call request, the proxy class is used to intercept the original interface to obtain the first request parameter and the first return value. Then, the second request parameter required for the comparison interface is assembled based on the first request parameter, and the comparison interface is called to obtain the second request parameter. The second return value is then compared with the similarities and differences between the two return values.

Benefits of technology

It can cover all the original interfaces to be tested, ensure the accuracy of the test results, and reduce the risk of replacement of new and old systems; flexibly configure interfaces to intercept information through management pages to reduce modifications to the old system code; use bytecode technology to dynamically generate proxy classes, Reduce the impact on the performance of the old system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113468041B_ABST
    Figure CN113468041B_ABST
Patent Text Reader

Abstract

The present invention discloses an interface comparison test method and device, and relates to the field of computer technology. A specific implementation of the method includes: when the original interface receives a call request, triggering a proxy class to intercept the original interface, and obtaining the first request parameter and the first return value of the call request; wherein the proxy class is an object generated according to the configured interface interception information for intercepting the original interface; assembling the first request parameter according to the parameter format of the comparison interface, obtaining the second request parameter, calling the comparison interface and passing the second request parameter to the comparison interface, and obtaining the second return value; comparing the first return value and the second return value to obtain a comparison result. In this implementation, when the original interface receives a call request, the proxy class is used to intercept the original interface to obtain the first return value, and then the comparison interface is called to obtain the second return value, and then the similarities and differences of the two return values ​​are compared, which can cover all the original interfaces to be tested and ensure the accuracy of the test results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an interface comparison test method and device. Background Art

[0002] Due to the needs of technology and business development, business systems need to be continuously iterated and updated. The iterative update of business systems involves the replacement of old systems with new ones. Since the old system is used online, the conventional replacement method is to develop a new system, and the new interface of the new system needs to be adapted to the interface of the old system, and the new interface is tested. After passing the test, the whole system is replaced.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] The testing process cannot cover all test cases, which affects the accuracy of the test results and leads to a higher risk of replacing the old system with the new one. During the testing process, it is necessary to compare the return values ​​of the new and old interfaces in real time, which affects the performance of the old system. Every time a new interface is added for comparison, the code of the old system needs to be modified before it can be put online. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides an interface comparison test method and device. When the original interface receives a call request, a proxy class is used to intercept the original interface to obtain a first request parameter and a first return value. Then, the second request parameter required for calling the comparison interface is assembled based on the first request parameter, and the comparison interface is called to obtain the second return value. The similarities and differences between the two return values ​​are then compared. This method can cover all original interfaces to be tested, ensure the accuracy of the test results, and reduce the risk of replacing the old and new systems.

[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, an interface comparison test method is provided.

[0007] An interface comparison test method according to an embodiment of the present invention includes: when an original interface receives a call request, triggering a proxy class to intercept the original interface and obtain a first request parameter and a first return value of the call request; wherein the proxy class is an object generated according to configured interface interception information and used to intercept the original interface; assembling the first request parameter according to the parameter format of the comparison interface to obtain a second request parameter, calling the comparison interface and passing the second request parameter to the comparison interface to obtain a second return value; comparing the first return value with the second return value to obtain a comparison result.

[0008] Optionally, the method also includes: obtaining the interface interception information configured through the management page; generating a proxy class for intercepting the original interface based on the interface interception information, including: dynamically generating a proxy class for intercepting the original interface using bytecode technology based on the interface interception information.

[0009] Optionally, based on the interface interception information, a proxy class for intercepting the original interface is dynamically generated using bytecode technology, including: concatenating the interface name of the original interface contained in the interface interception information, the method name that implements the original interface, and the return value of the original interface into a string; and compiling the string to generate the proxy class.

[0010] Optionally, the proxy class intercepts the original interface by using aspect-oriented programming or intrusion into business program hard coding.

[0011] Optionally, after the step of obtaining the first request parameter and the first return value of the calling request, the method also includes: the proxy class uses the first working thread to store the first request parameter and the first return value in a temporary queue; the proxy class uses the second working thread to read the first request parameter and the first return value of the temporary queue, and calls the message middleware to output the first request parameter and the first return value.

[0012] Optionally, after the step of assembling the first request parameter according to the parameter format of the comparison interface to obtain the second request parameter, the method further includes: performing protocol encapsulation according to the input parameter requirements of the transmission mode supported by the interface protocol of the comparison interface.

[0013] Optionally, before the step of comparing the first return value with the second return value, the method further includes: converting the format of the first return value according to a set data format; converting the format of the second return value according to the data format; comparing the first return value with the second return value, including: comparing the first return value after format conversion with the second return value.

[0014] To achieve the above objective, according to another aspect of an embodiment of the present invention, an interface comparison test device is provided.

[0015] An interface comparison test device according to an embodiment of the present invention comprises: a first acquisition module, which is used to trigger a proxy class to intercept the original interface when the original interface receives a call request, and obtain a first request parameter and a first return value of the call request; wherein the proxy class is an object for intercepting the original interface generated according to the configured interface interception information; a second acquisition module, which is used to assemble the first request parameter according to the parameter format of the comparison interface, obtain a second request parameter, call the comparison interface and pass the second request parameter to the comparison interface, and obtain a second return value; and a comparison module, which is used to compare the first return value with the second return value to obtain a comparison result.

[0016] Optionally, the device also includes: a third acquisition module, used to acquire the interface interception information configured through the management page; a generation module, used to dynamically generate a proxy class for intercepting the original interface based on the interface interception information using bytecode technology.

[0017] Optionally, the generation module is further used to concatenate the interface name of the original interface, the method name implementing the original interface and the return value of the original interface contained in the interface interception information into a string; and compile the string to generate the proxy class.

[0018] Optionally, the proxy class intercepts the original interface by using aspect-oriented programming or intrusion into business program hard coding.

[0019] Optionally, the device also includes: an asynchronous output module, which is used for, after obtaining the first request parameter and the first return value of the call request, the proxy class uses the first working thread to store the first request parameter and the first return value in a temporary queue; the proxy class uses the second working thread to read the first request parameter and the first return value of the temporary queue, and calls the message middleware to output the first request parameter and the first return value.

[0020] Optionally, the device also includes: a protocol encapsulation module, which is used to assemble the first request parameters according to the parameter format of the comparison interface to obtain the second request parameters, and then perform protocol encapsulation according to the input parameter requirements of the transmission mode supported by the interface protocol of the comparison interface.

[0021] Optionally, the device also includes: a format conversion module, used to perform format conversion on the first return value according to a set data format before comparing the first return value with the second return value; and to perform format conversion on the second return value according to the data format; the comparison module is also used to compare the first return value and the second return value after format conversion.

[0022] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.

[0023] An electronic device according to an embodiment of the present invention comprises: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement an interface comparison test method according to an embodiment of the present invention.

[0024] To achieve the above objective, according to another aspect of the embodiments of the present invention, a computer readable medium is provided.

[0025] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, an interface comparison test method according to an embodiment of the present invention is implemented.

[0026] An embodiment of the above invention has the following advantages or beneficial effects: when the original interface receives a call request, a proxy class is used to intercept the original interface to obtain a first request parameter and a first return value, and then the second request parameter required for calling the comparison interface is assembled based on the first request parameter, and the comparison interface is called to obtain the second return value, and then the similarities and differences of the two return values ​​are compared, which can cover all original interfaces to be tested, ensure the accuracy of the test results, and reduce the risk of replacing the old and new systems; flexibly configure the interface interception information through the management page, and realize multiple interface comparisons through one transformation; use bytecode technology to dynamically generate proxy classes to increase development flexibility; use AOP to intercept the original interface, greatly reducing code intrusion into the old system; reduce the impact on the operating performance of the old system by asynchronously outputting the first request parameter and the first return value; ensure successful communication with the second interface through the encapsulation protocol; unify the data format of the first return value and the second return value to ensure the correctness of the comparison results between the two.

[0027] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0029] Figure 1 is a schematic diagram of the main steps of the interface comparison test method according to an embodiment of the present invention;

[0030] Figure 2 is a schematic diagram of the main flow of an interface comparison test method according to yet another embodiment of the present invention;

[0031] Figure 3 is a schematic diagram of a management page of an interface comparison test method according to yet another embodiment of the present invention;

[0032] Figure 4 is a schematic diagram of the system architecture of an interface comparison test method according to another embodiment of the present invention;

[0033] Figure 5 is a schematic diagram of the main flow of an interface comparison test method according to another embodiment of the present invention;

[0034] Figure 6 is a schematic diagram of main modules of an interface comparison test device according to an embodiment of the present invention;

[0035] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0036] Figure 8 It is a schematic diagram of the structure of a computer device suitable for implementing the electronic device of the embodiment of the present invention. DETAILED DESCRIPTION

[0037] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0038] Figure 1 FIG. 1 is a schematic diagram of the main steps of the interface comparison test method according to an embodiment of the present invention. Figure 1 As shown, the interface comparison test method of the embodiment of the present invention mainly includes the following steps:

[0039] Step S101: When the original interface receives a call request, the proxy class is triggered to intercept the original interface and obtain the first request parameter and the first return value of the call request. The original interface is the interface included in the old system; the proxy class is an object generated for intercepting the original interface according to the interface interception information configured by the administrator on the management page. In the embodiment, the interface interception information includes the interface name of the original interface to be intercepted, the method name that implements the original interface, and the return value of the original interface.

[0040] After the interface interception information is obtained, a proxy class is generated for the original interface contained in the interface interception information. The proxy class intercepts the original interface using AOP (Aspect Oriented Programming) or by invading the business program hard-coded method. If the original interface receives a call request, the proxy class will be triggered to intercept the original interface and obtain the first request parameter contained in the call request and the first return value fed back by the original interface. After intercepting the original interface, the business processing flow of the old system continues.

[0041] Step S102: Assemble the first request parameter according to the parameter format of the comparison interface to obtain the second request parameter, call the comparison interface and pass the second request parameter to the comparison interface to obtain the second return value. The comparison interface is an interface included in the new system used to replace the original interface. After obtaining the first request parameter, assemble it according to the parameter format of the comparison interface to obtain the second request parameter. Then call the comparison interface and pass the second request parameter while calling the comparison interface to obtain the second return value fed back by the comparison interface.

[0042] Step S103: Compare the first return value and the second return value to obtain a comparison result. Unify the data formats of the first return value and the second return value, and compare the first return value and the second return value after the unified format to obtain a comparison result. If the comparison is inconsistent, it means that the code corresponding to the comparison interface has defects, and an inconsistent return value can be output. If the comparison is consistent, it means that the code corresponding to the comparison interface has no defects and can be used to replace the original interface later.

[0043] Figure 2 FIG. 2 is a schematic diagram of the main flow of an interface comparison test method according to another embodiment of the present invention. Figure 2 As shown, the interface comparison test method of the embodiment of the present invention is implemented by an interface comparison test device, and mainly includes the following steps:

[0044] Step S201: Obtaining interface interception information configured through the management page. The administrator configures the interface interception information on the management page according to business requirements, and then sends it to the interface comparison test device.

[0045] Figure 3 FIG. 1 is a schematic diagram of a management page of an interface comparison test method according to another embodiment of the present invention. Figure 3 As shown, the interface interception information includes the interface name of the original interface to be intercepted, the method name that implements the original interface, the return value of the original interface, the interception method, the interface description, the comparison mark and the operation.

[0046] The operation includes at least one enable button and at least one disable button. The enable button can be used to send configured interface interception information, send interface comparison start instructions, etc., and the stop button can be used to stop sending interface interception information, send interface comparison stop instructions, etc. These buttons enable the configuration of interface interception information to be started and stopped at any time, with good flexibility and easy management.

[0047] Step S202: Based on the interface interception information, a proxy class for intercepting the original interface is dynamically generated using bytecode technology. This step uses Javassist bytecode technology to dynamically generate a proxy class. Specifically, the interface name of the original interface contained in the interface interception information, the method name that implements the original interface, and the return value of the original interface are concatenated into a string, and the string is compiled to generate a proxy class. Among them, Javassist is an open source class library for analyzing, editing, and creating Java bytecodes. The concatenated string contains the AOP interception configuration.

[0048] Step S203: When the original interface receives a call request, the proxy class is triggered to intercept the original interface and obtain the first request parameter and the first return value of the call request. When the original interface receives a call request, such as a TCP request or an HTTP request, the proxy class is triggered to intercept using AfterReturning of AOP to obtain the first request parameter and the first return value of the call request, and the business processing flow of the old system is continued after interception.

[0049] AfterReturning is marked at the method level of the proxy code. After the method to be tested (that is, the method of the original interface) is proxied, once the call is completed, the processing method marked with AfterReturning of the proxy class will be triggered for interception.

[0050] Step S204: Assemble the first request parameter according to the parameter format of the comparison interface to obtain the second request parameter. The second request parameter is the input parameter required when calling the comparison interface. The parameter format of the comparison interface is implemented differently according to different interfaces, such as including 3 string type parameters or 2 object types and 1 numeric type parameter. Assemble the first request parameter according to the parameter format of the comparison interface to obtain the second request parameter.

[0051] Step S205: Perform protocol encapsulation according to the input parameter requirements of the transmission mode supported by the interface protocol of the comparison interface. The interface protocol of the comparison interface may be a TCP protocol, an HTTP protocol, etc. Taking the HTTP protocol as an example, the transmission modes it supports include Post, Get, etc. The protocol encapsulation is performed according to the input parameter requirements of the Post and Get methods to ensure successful communication with the comparison interface.

[0052] Step S206: calling the comparison interface, passing the second request parameter to the comparison interface, and obtaining the second return value. Calling the comparison interface, passing the second request parameter to the comparison interface, and obtaining the second return value returned by the comparison interface.

[0053] Step S207: Convert the first return value and the second return value into the specified data format respectively, compare the first return value and the second return value after the format conversion, and output the comparison result. Convert the first return value and the second return value into Json format or XML format. Json stands for JavaScript Object Notation, which is a lightweight data exchange format; XML stands for Extensible Markup Language, which is an extensible markup language.

[0054] In the embodiment, the first return value and the second return value are converted into Json format, and the corresponding first string and second string are obtained after conversion, and both strings include a key name (Key) and a corresponding key value (Value). Use the comparison API (Application Programming Interface) to compare the values ​​corresponding to the same Key in the two strings to determine whether the two strings are the same. If there are two different values ​​corresponding to the same Key, the Key and Value are output. Among them, the comparison API is a Json comparison tool class written in Java.

[0055] Figure 4 Schematic diagram of the system architecture of the interface comparison test method according to another embodiment of the present invention. Figure 4 As shown, the interface comparison test method of the embodiment of the present invention is implemented by the improved old system and control system. The old system adds interface interception Agent and agent class on the basis of the original functional modules (i.e., the original interface access module and the original interface business processing module); the control system includes an original data storage module, a comparison call module, a comparison data storage module, a comparison result output module and a comparison management terminal.

[0056] The dotted line in the figure is the original processing flow of the new and old systems. After receiving the call request, the original interface access module in the old system forwards it to the original interface business processing module, which performs the corresponding business processing; after receiving the call request, the comparison interface access module in the new system forwards it to the comparison interface business processing module, which performs the corresponding business processing.

[0057] The solid line is the dynamic interception process of the embodiment of the present invention. The functions of each module involved are described below.

[0058] The comparison management terminal is used to maintain the management page, including configuring interface interception information, enabling configuration delivery and interface comparison through the enable button, and stopping configuration delivery and interface comparison through the disable button. The schematic diagram of the management page is as follows Figure 3 shown.

[0059] The interface interception Agent is integrated into the old system, providing a rest or http interface to receive the interface interception information sent by the comparison management end, and then dynamically generates the proxy class based on the interface interception information using bytecode technology.

[0060] Proxy class, when the original interface receives a call request (such as a TCP request), the proxy class uses the AfterReturning method of AOP to intercept, obtain the first request parameter and the first return value in the call request, and then assemble the first request parameter and the first return value into Json format, and call the message middleware to send it to the original data storage module. After interception, the proxy class continues the business processing flow of the old system.

[0061] The original data storage module receives the first request parameter and the first return value in Json format, converts them into a database format, and stores them in a database. The database may be MySQL, ES (ElasticSearch), or HBase.

[0062] After receiving the interface comparison start instruction sent by the comparison management end, the comparison calling module obtains the original interface data (including the first request parameter and the first return value in the database format) from the database, assembles the first request parameter according to the parameter format of the comparison interface, and obtains the second request parameter; encapsulates the comparison interface protocol, calls the comparison interface, obtains the second return value, and sends the second request parameter and the second return value to the comparison data storage module.

[0063] The comparison data storage module receives the second request parameter and the second return value, and converts them into a database format for storage.

[0064] The comparison result output module reads the first return value and the second return value, uses the comparison API to perform comparison, outputs the comparison report and presents it.

[0065] Figure 5 FIG. 2 is a schematic diagram of the main flow of an interface comparison test method according to another embodiment of the present invention. Figure 5 As shown, the interface comparison test method of the embodiment of the present invention is based on Figure 4 The system architecture shown mainly includes the following steps:

[0066] Step S501: The comparison management terminal sends the interface interception information configured by the administrator through the management page to the interface interception Agent. Figure 3 The interface interception information includes the interface name of the original interface to be intercepted, the method name that implements the original interface, the return value of the original interface, the interception method, the interface description, the comparison mark and the operation.

[0067] Step S502: The interface interception agent receives the interface interception information through the rest or http interface, and dynamically generates the proxy class using bytecode technology based on the interface interception information. The interface protocol of the rest or http interface is simple and can be called across platforms. The interface interception agent concatenates the interface name, method name and return value into a java source code string (including AOP interception configuration), and then dynamically compiles and generates a proxy class using Javassit technology. If the original interface is called, it will trigger the call of the proxy class to implement interception.

[0068] Step S503: When the original interface receives the call request, the proxy class uses the AfterReturning method of AOP to intercept the original interface and obtain the first request parameter and the first return value in the call request. Using the AfterReturning method of AOP for interception can trigger the proxy class to intercept after the method call of the original interface ends, which is less invasive to the code of the old system. After interception, the proxy class continues the business processing flow of the old system.

[0069] Step S504: After the proxy class assembles the first request parameter and the first return value into Json format, it calls the message middleware to send them to the original data storage module. The message middleware will send the interface identifier, interface name, first request parameter and first return value of the original interface to the original data storage module via a message.

[0070] In a preferred embodiment, the proxy class uses the first working thread to store the first request parameter and the first return value in a temporary queue; then uses the second working thread to read the first request parameter and the first return value in the temporary queue, and then calls the message middleware to output the first request parameter and the first return value. This embodiment implements asynchronous data output and reduces the impact on the operating performance of the old system.

[0071] Step S505: the original data storage module converts the first request parameter and the first return value in Json format into a database format and stores them in the database.

[0072] Step S506: the comparison management terminal sends an interface comparison start instruction to the comparison calling module.

[0073] Step S507: After receiving the interface comparison start instruction, the comparison calling module obtains the first request parameter and the first return value from the database, assembles the first request parameter according to the parameter format of the comparison interface, and obtains the second request parameter. The specific implementation of the assembly is the same as step S204, which will not be repeated here.

[0074] Step S508: The comparison calling module encapsulates the comparison interface protocol, calls the comparison interface, obtains the second return value, and sends the first to second request parameters and the first to second return values ​​to the comparison data storage module. The specific implementation of the protocol encapsulation is the same as step S205, which will not be repeated here. The following example illustrates.

[0075] Assume that the old system has a commission ratio value query business, and now a new system is launched to reconstruct the old system. Since the commission ratio setting logic is relatively complex and the business logic is a dynamic combination, it is difficult to cover all test cases through testing, so the method of the embodiment of the present invention is used for testing.

[0076] The first request parameter passed in by the original interface of the old system is the order number, product number, and category number, and the second request parameter passed in by the comparison interface of the new system is the order number, order type, country code, product number, and category number. The fields included in the second request parameter are the parameter format of the comparison interface. After processing in step S507, the first request parameter can be packaged into the second request parameter.

[0077] After that, call the comparison interface to get the second return value. Both the old and new systems require the commission ratio to be returned. The old system returns the commission ratio and business type (i.e., the first return value), and the new system returns the commission ratio and business identity (i.e., the second return value). Among them, the business type and business identity have a corresponding relationship.

[0078] Step S509: The comparison data storage module stores the first to second request parameters and the first to second return values. The second request parameter and the second return value are converted into a database format and then stored.

[0079] Step S510: The comparison result output module reads the first return value and the second return value from the comparison data storage module, uses the comparison API for comparison, outputs and presents the comparison report. The specific implementation of the comparison is the same as step S207 and will not be repeated here. After the above processing, if the return values ​​of the original interface and the comparison interface are the same, it means that there are no defects in the code corresponding to the comparison interface, and the original interface can be replaced by the comparison interface, which solves the problem of smooth switching of the original interface of a newly created business system or a reconstructed business system, and ensures the accuracy of the interface switching data.

[0080] It can be seen from the interface comparison test method of the embodiment of the present invention that when the original interface receives a call request, the proxy class is used to intercept the original interface to obtain the first request parameter and the first return value, and then the second request parameter required for calling the comparison interface is assembled based on the first request parameter, and the comparison interface is called to obtain the second return value, and then the similarities and differences of the two return values ​​are compared, which can cover all the original interfaces to be tested, ensure the accuracy of the test results, and reduce the risk of replacing the new and old systems; flexibly configure the interface interception information through the management page, and realize multiple interface comparisons through one transformation; use bytecode technology to dynamically generate proxy classes to increase development flexibility; use AOP to intercept the original interface, which greatly reduces the code intrusion into the old system; reduce the impact on the running performance of the old system by asynchronously outputting the first request parameter and the first return value; ensure successful communication with the second interface through the encapsulation protocol; unify the data format of the first return value and the second return value to ensure the correctness of the comparison results between the two.

[0081] Figure 6 Schematic diagram of the main modules of the interface comparison test device according to an embodiment of the present invention. Figure 6 As shown, the interface comparison test device 600 of the embodiment of the present invention mainly includes:

[0082] The first acquisition module 601 is used to trigger the proxy class to intercept the original interface when the original interface receives a call request, and obtain the first request parameter and the first return value of the call request. The original interface is the interface included in the old system; the proxy class is an object generated for intercepting the original interface according to the interface interception information configured by the administrator on the management page. In the embodiment, the interface interception information includes the interface name of the original interface to be intercepted, the method name that implements the original interface, and the return value of the original interface.

[0083] After the interface interception information is obtained, a proxy class is generated for the original interface contained in the interface interception information. The proxy class intercepts the original interface using AOP or hard-coded intrusion into the business program. If the original interface receives a call request, the proxy class is triggered to intercept the original interface and obtain the first request parameter contained in the call request and the first return value fed back by the original interface. After intercepting the original interface, the business processing flow of the old system continues.

[0084] The second acquisition module 602 is used to assemble the first request parameter according to the parameter format of the comparison interface to obtain the second request parameter, call the comparison interface and pass the second request parameter to the comparison interface to obtain the second return value. The comparison interface is an interface included in the new system used to replace the original interface. After obtaining the first request parameter, assemble it according to the parameter format of the comparison interface to obtain the second request parameter. Then, call the comparison interface, and pass the second request parameter while calling the comparison interface to obtain the second return value fed back by the comparison interface.

[0085] The comparison module 603 is used to compare the first return value and the second return value to obtain a comparison result. The data formats of the first return value and the second return value are unified, and the first return value and the second return value after the unified format are compared to obtain a comparison result. If the comparison is inconsistent, it means that the code corresponding to the comparison interface has defects, and an inconsistent return value can be output. If the comparison is consistent, it means that the code corresponding to the comparison interface has no defects and can be used to replace the original interface later.

[0086] In addition, the interface comparison test device 600 of the embodiment of the present invention may also include: a third acquisition module, a generation module, an asynchronous output module and a format conversion module. Among them, the third acquisition module is used to obtain the interface interception information configured through the management page. The generation module is used to dynamically generate a proxy class for intercepting the original interface based on the interface interception information using bytecode technology.

[0087] An asynchronous output module is used to, after obtaining the first request parameter and the first return value of the call request, the proxy class uses the first working thread to store the first request parameter and the first return value in a temporary queue; the proxy class uses the second working thread to read the first request parameter and the first return value of the temporary queue, and calls the message middleware to output the first request parameter and the first return value.

[0088] The format conversion module is used to perform format conversion on the first return value according to a set data format before comparing the first return value with the second return value; and to perform format conversion on the second return value according to the data format.

[0089] From the above description, it can be seen that when the original interface receives a call request, the proxy class is used to intercept the original interface to obtain the first request parameter and the first return value, and then the second request parameter required to call the comparison interface is assembled based on the first request parameter, and the comparison interface is called to obtain the second return value, and then the similarities and differences of the two return values ​​are compared. This can cover all the original interfaces to be tested, ensure the accuracy of the test results, and reduce the risk of replacing the old and new systems.

[0090] Figure 7An exemplary system architecture 700 is shown to which the interface comparison test method or interface comparison test device according to the embodiment of the present invention can be applied.

[0091] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0092] Users can use terminal devices 701, 702, and 703 to interact with server 705 through network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0093] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0094] The server 705 may be a server that provides various services, such as a background management server that an administrator processes by using the call request sent by the terminal devices 701, 702, and 703. The background management server may intercept the original interface to obtain the first return value, call the comparison interface to obtain the second return value, compare the first return value with the second return value, and feed back the processing result (such as the comparison result) to the terminal device.

[0095] It should be noted that the interface comparison test method provided in the embodiment of the present application is generally executed by the server 705 , and accordingly, the interface comparison test device is generally set in the server 705 .

[0096] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0097] According to an embodiment of the present invention, the present invention also provides an electronic device and a computer-readable medium.

[0098] The electronic device of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement an interface comparison test method of an embodiment of the present invention.

[0099] The computer-readable medium of the present invention stores a computer program, and when the program is executed by a processor, an interface comparison test method of an embodiment of the present invention is implemented.

[0100] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 suitable for implementing an electronic device of an embodiment of the present invention. Figure 8 The electronic device 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.

[0101] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the computer system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

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

[0103] In particular, according to the embodiments disclosed in the present invention, the process described in the main step diagram above can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the main step diagram. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.

[0104] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-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 of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0105] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0106] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a first acquisition module, a second acquisition module, and a comparison module. The names of these modules do not constitute a limitation on the modules themselves in certain cases. For example, the first acquisition module may also be described as "a module that triggers a proxy class to intercept the original interface when the original interface receives a call request and obtains the first request parameter and the first return value of the call request."

[0107] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by a device, the device includes: when the original interface receives a call request, trigger the proxy class to intercept the original interface and obtain the first request parameter and the first return value of the call request; wherein the proxy class is an object generated according to the configured interface interception information to intercept the original interface; assemble the first request parameter according to the parameter format of the comparison interface to obtain the second request parameter, call the comparison interface and pass the second request parameter to the comparison interface to obtain the second return value; compare the first return value and the second return value to obtain a comparison result.

[0108] According to the technical solution of an embodiment of the present invention, when the original interface receives a call request, a proxy class is used to intercept the original interface to obtain a first request parameter and a first return value, and then the second request parameter required for calling the comparison interface is assembled based on the first request parameter, and the comparison interface is called to obtain the second return value, and then the similarities and differences between the two return values ​​are compared. This can cover all original interfaces to be tested, ensure the accuracy of the test results, and reduce the risk of replacing the old and new systems.

[0109] The above product can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.

[0110] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. An interface comparison test method, characterized in that: include: When the original interface receives a call request, the proxy class is triggered to intercept the original interface and obtain the first request parameter and the first return value of the call request; wherein the proxy class is an object generated according to the configured interface interception information and used to intercept the original interface; Assembling the first request parameter according to the parameter format of the comparison interface to obtain a second request parameter, calling the comparison interface and passing the second request parameter to the comparison interface to obtain a second return value; The first return value and the second return value are compared to obtain a comparison result.

2. The method according to claim 1, characterized in that The method further comprises: Obtain the interface interception information configured through the management page; Generate a proxy class for intercepting the original interface according to the interface interception information, including: According to the interface interception information, a proxy class for intercepting the original interface is dynamically generated using bytecode technology.

3. The method according to claim 2, characterized in that According to the interface interception information, a proxy class for intercepting the original interface is dynamically generated using bytecode technology, including: Concatenate the interface name of the original interface, the method name that implements the original interface, and the return value of the original interface contained in the interface interception information into a string; Compile the string to generate the proxy class.

4. The method according to claim 2, characterized in that: The proxy class intercepts the original interface by using aspect-oriented programming or intrusion into the business program hard-coding.

5. The method according to claim 1, characterized in that After the step of obtaining the first request parameter and the first return value of the call request, the method further includes: The proxy class uses a first working thread to store the first request parameter and the first return value into a temporary queue; The proxy class uses the second working thread to read the first request parameter and the first return value of the temporary queue, and calls the message middleware to output the first request parameter and the first return value.

6. The method according to claim 1, characterized in that After the step of assembling the first request parameter according to the parameter format of the comparison interface to obtain the second request parameter, the method further includes: Protocol encapsulation is performed according to the input parameter requirements of the transmission mode supported by the interface protocol of the comparison interface.

7. The method according to claim 1, characterized in that Before the step of comparing the first return value with the second return value, the method further includes: Convert the first return value into a new format according to the set data format; According to the data format, convert the second return value into a format; Comparing the first return value with the second return value includes: comparing the first return value after format conversion with the second return value.

8. An interface comparison test device, characterized in that: include: A first acquisition module is used to trigger the proxy class to intercept the original interface when the original interface receives a call request, and obtain the first request parameter and the first return value of the call request; wherein the proxy class is an object generated according to the configured interface interception information and used to intercept the original interface; A second acquisition module, configured to assemble the first request parameter according to the parameter format of the comparison interface to obtain a second request parameter, call the comparison interface and pass the second request parameter to the comparison interface to obtain a second return value; A comparison module is used to compare the first return value with the second return value to obtain a comparison result.

9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Interface function comparison and test method and device, electronic equipment and storage medium

    CN108694104A

  • A full-process distributed system automatic test method and test system

    CN109828914A