An interface testing method and related device

By adding extended attributes to the interface and using the program reflection mechanism to call the adapted interface processing chain, the problems of redundant code and strong dependencies in interface automation testing are solved, and the efficiency and flexibility of interface testing are achieved.

CN112667506BActive Publication Date: 2024-10-25ONE CITY ONE NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011570135.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-26
Publication Date
2024-10-25
Estimated Expiration
2040-12-26

Smart Images

  • Figure CN112667506B_ABST
    Figure CN112667506B_ABST
Patent Text Reader

Abstract

An interface testing method and related device include: obtaining a test request of an interface to be tested, the test request includes: basic attributes matching the interface to be tested; marking the interface to be tested based on user operations, adding extended attributes to the test request, and treating the interface to be tested after the marking operation as a marked interface; obtaining the extended attributes of the marked interface based on a program reflection mechanism; calling an interface processing chain matching the extended attributes; using a processor corresponding to the interface processing chain to process the interface to be tested; and feeding back the processing result of the interface to be tested to the sender of the test request. The scheme adds extended attributes to the interface to be tested through a marking operation, indicates the use identity of the interface to be tested, and then selects a suitable processor for processing according to its use identity, so that different test interfaces can be processed by the same processor, reducing code redundancy and improving processor reusability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data testing, and in particular to an interface testing method and related devices. Background Art

[0002] As the testing time required for continuous delivery becomes shorter and shorter, but the quality requirements are also higher and higher; how to effectively ensure the quality of product launch and release under the condition of insufficient testing time? At this time, interface automation testing provides the necessary technical support. Interface automation testing includes automation testing of a single interface and automation testing of multiple interfaces (which are further divided into no dependency between interfaces and dependencies between interfaces). For automation testing of a single interface and no dependency between multiple interfaces, it can be fully achieved through the existing unit testing framework (unittest, junit, TestNG). Figure 1 As shown, these unit testing frameworks have encapsulated the corresponding pre-processing (e.g., setting up the environment before testing) and post-processing (e.g., restoring the environment after testing) to meet the needs of interface testing.

[0003] However, during the interface testing process, you will also face the situation of verifying the correctness of the business logic by calling various service interfaces. Compared with end-to-end automated testing (such as UI testing), its input-output ratio is relatively high, so using interface assembly to verify business logic is also a popular practice in the industry; but at this time, you will face a series of problems that the above unit testing framework cannot solve. The problems are as follows:

[0004] Inconsistent configuration conditions: The preconditions and postconditions required by the assembled interfaces are inconsistent, and the conditions are highly dependent.

[0005] Serious code coupling: The success or failure processing strategies of each assembled interface request are different. Often this part of the interface processing will be coupled into the code, causing code redundancy.

[0006] Strong dependency between interfaces: In the process of verifying business logic through interfaces, there are downstream interfaces that rely on data returned by successful calls to upstream interfaces. For example, the "Load Menu List" interface requires the token returned by the upstream "Login" interface after a successful call as an input parameter before the interface can be tested. Summary of the invention

[0007] In view of this, an embodiment of the present invention provides an interface testing method and related devices to reduce redundant codes in the testing process.

[0008] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0009] An interface testing method, comprising:

[0010] Obtaining a test request for the interface to be tested, the test request including: basic attributes matching the interface to be tested;

[0011] Performing a marking operation on the interface to be tested based on a user operation, adding an extended attribute to the test request, and treating the interface to be tested after the marking operation as a marked interface;

[0012] Obtain extended attributes of the marked interface based on program reflection mechanism;

[0013] Invoke an interface processing chain matching the extended attribute;

[0014] Using a processor corresponding to the interface processing chain to process the interface to be tested;

[0015] Feedback the processing result of the interface to be tested to the sender of the test request.

[0016] Optionally, the above interface testing method includes:

[0017] The extended attributes include: a first extended attribute and a second extended attribute;

[0018] The first extended attribute is a control judgment condition for selecting an interface processing chain;

[0019] The second extended attribute is used to provide necessary adaptation parameters for the processor corresponding to the interface processing chain.

[0020] Optionally, in the above interface testing method, the first extended attribute includes but is not limited to: a priority parameter and a type parameter, or a combination of both of them;

[0021] The second extended attribute includes, but is not limited to, one or a combination of two of an environment parameter and an extracted value.

[0022] Optionally, in the above interface testing method, the step of obtaining the extended attributes of the marked interface based on the program reflection mechanism includes:

[0023] Get the extended attributes of the marked interface based on the Java program reflection mechanism.

[0024] An interface testing device, comprising:

[0025] A collection unit, used for obtaining a test request of the interface to be tested, wherein the test request includes: basic attributes matching the interface to be tested;

[0026] A processing unit, configured to perform a marking operation on the interface to be tested based on a user operation, add an extended attribute to the test request, and use the interface to be tested after the marking operation as a marked interface;

[0027] A calling unit, used for obtaining the extended attributes of the marked interface based on a program reflection mechanism, and calling an interface processing chain matching the extended attributes;

[0028] An execution unit, configured to process the interface to be tested using a processor corresponding to the interface processing chain;

[0029] A feedback unit is used to feed back the processing result of the interface to be tested to the sender of the test request.

[0030] Optionally, the above interface testing device includes:

[0031] The extended attributes include: a first extended attribute and a second extended attribute;

[0032] The first extended attribute is a control judgment condition for selecting an interface processing chain;

[0033] The second extended attribute is used to provide necessary adaptation parameters for the processor corresponding to the interface processing chain.

[0034] Optionally, in the above interface testing device, the first extended attribute includes but is not limited to: a priority parameter and a type parameter, or a combination of both of them;

[0035] The second extended attribute includes, but is not limited to, one or a combination of two of an environment parameter and an extracted value.

[0036] Optionally, in the above interface testing device, the step of obtaining the extended attributes of the marked interface based on the program reflection mechanism includes:

[0037] Get the extended attributes of the marked interface based on the Java program reflection mechanism.

[0038] A readable storage medium stores a plurality of instructions, wherein the instructions are suitable for a processor to load to execute the steps in any one of the above-mentioned interface testing methods.

[0039] An interface testing device comprises a memory and a processor;

[0040] The memory is used to store programs;

[0041] The processor is used to execute the program to implement each step of the interface testing method described in any one of the above items.

[0042] Based on the above technical scheme, the above scheme provided by the embodiment of the present invention, before testing the interface to be tested, the user can decouple the relationship between the interface object to be tested and the interface processing chain, so that according to the different usage scenarios of the interface to be tested, extended attributes can be added to the interface to be tested through marking operations, and the usage identity of the interface to be tested can be marked based on the extended attributes, and then a suitable processor can be selected for processing according to its usage identity, so that different test interfaces can be processed by the same processor, reducing code redundancy and improving the reusability of the processor. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0044] Figure 1 This is a schematic diagram of the structure of the existing unit testing framework;

[0045] Figure 2 A flowchart of the interface testing method disclosed in the embodiment of the present application;

[0046] Figure 3 is a schematic diagram of the structure of the processor;

[0047] Figure 4 A schematic diagram of the structure of the interface testing device disclosed in the embodiment of the present application;

[0048] Figure 5 A schematic diagram of the processing flow of processors obtained by calling different interface processing chains for extended attributes of different interfaces to be tested;

[0049] Figure 6 This is a schematic diagram of the structure of the interface testing device disclosed in the embodiment of the present application. DETAILED DESCRIPTION

[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0051] In order to reduce redundant code, this application provides an interface testing method, see Figure 2 , the method may include:

[0052] Step S101: obtaining a test request of the interface to be tested, wherein the test request includes: basic attributes matching the interface to be tested;

[0053] When testing an interface, this step is used to obtain a test request for the interface to be tested, wherein the test request for the interface to be tested includes basic attributes such as a URL, a test method, and basic parameters that match the interface to be tested;

[0054] Step S102: marking the interface to be tested based on the user operation, adding an extended attribute to the test request, and treating the interface to be tested after the marking operation as a marked interface;

[0055] In this scheme, before testing the interface to be tested, the interface to be tested can be marked. The marking operation can be completed based on user operation. Through the marking operation, extended attributes matching the interface to be tested can be added to the test request corresponding to the interface to be tested, and the interface to be tested can be recorded as a marked interface.

[0056] The extended attribute is an extended attribute that matches the interface to be tested, and the specific data content contained therein can be selected based on the test requirements. For example, the extended attribute may include a combination of one or more of priority, type, environment, extracted value, etc. Through the extended parameters, the processor used to test the interface to be tested can be determined;

[0057] Step S103: obtaining the extended attributes of the marked interface based on the program reflection mechanism;

[0058] In this step, before testing the interface to be tested, the extended attributes of the marked interface are dynamically obtained through the program reflection mechanism, wherein the program reflection mechanism may refer to the Java program reflection mechanism or other program reflection mechanisms. The core of the Java program reflection mechanism is to dynamically load classes and obtain detailed information of classes when the program is running, so as to operate the attributes and methods of classes or objects. Its essence is that after the JVM obtains the class object, it decompiles through the class object to obtain various information of the object;

[0059] Step S104: calling an interface processing chain matching the extended attribute;

[0060] In this step, in the system applying the method, the mapping relationship between the extended attributes and the interface processing chain can be pre-stored, and the mapping relationship is stored in a preset mapping table. After the corresponding extended attributes of the interface to be tested are obtained based on the program reflection mechanism, the interface processing chain matching the extended attributes is searched based on the mapping table. In this solution, each of the interface processing chains corresponds to one or more processors. When the interface processing chain is determined, the processor used to test the interface to be tested is also determined.

[0061] Step S105: using the processor corresponding to the interface processing chain to process the interface to be tested;

[0062] After the interface processor is determined, the interface processor reads the basic attributes and extended attributes of the interface to be tested through the interface processing chain, and processes the interface to be tested based on the basic attributes and extended attributes. The processing content may include but is not limited to log records, performance statistics, security control, transaction processing, exception handling, etc.

[0063] Step S106: Feedback the processing result of the interface to be tested to the sender of the test request;

[0064] In this step, after the test of the interface to be tested is completed, a corresponding processing result will be generated. After the processing result is obtained, the processing result will be fed back to the sender of the test request.

[0065] In this solution, before testing the interface to be tested, the user can decouple the relationship between the interface object to be tested and the interface processing chain, so that according to the different usage scenarios of the interface to be tested, extended attributes can be added to the interface to be tested through marking operations, and the usage identity of the interface to be tested can be marked based on the extended attributes. Then, a suitable processor can be selected for processing according to its usage identity, so that different test interfaces can be processed by the same processor, reducing code redundancy and improving the reusability of the processor.

[0066] In this solution, each processor corresponding to the interface processing chain supports vertical and horizontal expansion, improves the flexibility of interface processing, and solves the differences in configuration processing of each interface and the dependency problems between interfaces when verifying business logic through interfaces.

[0067] In summary, the device solves the problems of configuration differences, interface dependencies, and code redundancy in complex interface set verification scenarios.

[0068] In a specific embodiment of the present application, the extended attributes can be divided into two categories, that is, the extended attributes include: a first extended attribute and a second extended attribute;

[0069] The first extended attribute is a control judgment condition for selecting an interface processing chain, that is, the corresponding interface processing chain can be mapped through the first extended attribute. For example, the attributes such as priority and type can find the interface processing chain corresponding to the interface priority and type, and the interface to be tested is processed in sequence according to the interface processing chain sequence. At this time, the attributes such as priority and type are the first extended attributes.

[0070] The second extended attribute is used to provide the necessary parameters for adaptation for the processor corresponding to the interface processing chain. For example, according to the type and priority mapping of the interface to be tested, an interface processing chain matching the interface to be tested will be mapped out. The interface processing chain corresponds to an "environment processor" pre-processor, which is used to prepare the database connection environment before testing the interface to be tested. The "environment processor" needs to know whether the connection is a test, pre-release or production library based on the input parameter "environment type". In this scheme, the extended attribute of "environment type" is weakly bound to the interface to be tested by marking. Similarly, the marking "extracted value" can be provided to the "extracted processor" corresponding to the interface processing chain, and the value indicated by the "extracted value" can be extracted for use by the downstream interface. When marking the interface to be tested, the default value of the extended attribute can be preset to reduce the workload of marking and improve the efficiency of interface testing; the addition of extended attributes such as priority, type, environment, and extracted value to the interface is not limited to this.

[0071] In the technical solutions disclosed in the above embodiments of this application, see Figure 3 , Figure 3 The processor corresponding to the interface processing chain is further explained. The processor corresponding to the interface processing chain is abstracted and divided into two categories: pre-processor and post-processor. The pre-processor is mainly used to provide test preparation before testing with a test interface, such as test data preparation, database connection, etc. These tasks can be completed by the pre-processor. The post-processor is mainly used to complete the related operations of recycling and processing the test request after the test of the interface to be tested succeeds or fails. For example, the post-processor may include a data recovery processor, a failure retry processor, etc. In this solution, the processor corresponding to the interface processing chain is not limited to log recording, performance statistics, security control, transaction processing, exception handling, etc.

[0072] This embodiment discloses an interface testing device. For the specific working contents of each unit in the device, please refer to the contents of the above-mentioned method embodiment. The interface testing device provided by the embodiment of the present invention is described below. The interface testing device described below and the interface testing method described above can be referenced to each other.

[0073] See also Figure 4, an interface testing device disclosed in an embodiment of the present application may include:

[0074] The acquisition unit 1 corresponds to step S101 in the above method and is used to obtain a test request of the interface to be tested, wherein the test request includes: basic attributes matching the interface to be tested;

[0075] Processing unit 2, which corresponds to step S102 in the above method, is used to mark the interface to be tested based on the user operation, add extended attributes to the test request, and use the interface to be tested after the marking operation as a marked interface;

[0076] The calling unit 3 corresponds to steps S103-S104 in the above method, and is used to obtain the extended attributes of the marked interface based on the program reflection mechanism, and call the interface processing chain matching the extended attributes. The different processing chains can call different processors to perform corresponding processing on the extended attributes of different interfaces. For example, see Figure 5 As shown, Figure 5 A schematic diagram of the processing flow of processors obtained by calling different interface processing chains for extended attributes of different interfaces to be tested;

[0077] An execution unit 4, which corresponds to step S105 in the above method, is used to process the interface to be tested using a processor corresponding to the interface processing chain;

[0078] The feedback unit 5 corresponds to step S106 in the above method and is used to feed back the processing result of the interface to be tested to the sender of the test request.

[0079] Corresponding to the above method, the present application also discloses a readable storage medium, which stores multiple instructions, and the instructions are suitable for a processor to load to execute the steps of the interface testing method described in any of the above embodiments of the present application.

[0080] This embodiment discloses an interface testing device, including a memory and a processor;

[0081] Figure 6 For the hardware structure diagram of the interface test device provided by the embodiment of the present invention, see Figure 6 As shown, it may include: a storage 100 and a processor 200;

[0082] The interface testing device further includes a communication interface 300 and a communication bus 400 , wherein the memory 100 , the processor 200 and the communication interface 300 communicate with each other via the communication bus 400 .

[0083] The memory 100 is used to store program codes; the program codes include computer operation instructions.

[0084] The memory 100 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.

[0085] The processor 200 may be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The processor 200 is used to call the program code, and when the program code is executed, it is used to execute the method described in any of the above embodiments of the present application.

[0086] For example, the processor 200 is used to call the program code to execute:

[0087] Obtaining a test request for the interface to be tested, the test request including: basic attributes matching the interface to be tested;

[0088] Performing a marking operation on the interface to be tested based on a user operation, adding an extended attribute to the test request, and treating the interface to be tested after the marking operation as a marked interface;

[0089] Obtain extended attributes of the marked interface based on program reflection mechanism;

[0090] Invoke an interface processing chain matching the extended attribute;

[0091] Using a processor corresponding to the interface processing chain to process the interface to be tested;

[0092] Feedback the processing result of the interface to be tested to the sender of the test request.

[0093] For the convenience of description, the above system is described as being divided into various modules according to their functions. Of course, when implementing the present invention, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0094] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0095] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0096] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0097] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0098] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. An interface testing method, characterized in that: include: Obtaining a test request for the interface to be tested, the test request including: basic attributes matching the interface to be tested; Based on the user operation, the interface to be tested is marked, an extended attribute is added to the test request, and the interface to be tested after the marking operation is used as a marked interface; wherein the extended attribute includes: a first extended attribute and a second extended attribute; the first extended attribute is a control judgment condition for selecting an interface processing chain; the second extended attribute is used to provide necessary parameters for adaptation for a processor corresponding to the interface processing chain; Obtain extended attributes of the marked interface based on program reflection mechanism; Invoke an interface processing chain matching the extended attribute; Using a processor corresponding to the interface processing chain to process the interface to be tested; Feedback the processing result of the interface to be tested to the sender of the test request.

2. The interface testing method according to claim 1, characterized in that: The first extended attribute includes but is not limited to: one or a combination of two of a priority parameter and a type parameter; The second extended attribute includes, but is not limited to, one or a combination of two of an environment parameter and an extracted value.

3. The interface testing method according to claim 1, characterized in that: The method of obtaining the extended attributes of the marked interface based on the program reflection mechanism includes: Get the extended attributes of the marked interface based on the Java program reflection mechanism.

4. An interface testing device, characterized in that: include: A collection unit, used to obtain a test request of the interface to be tested, wherein the test request includes: basic attributes matching the interface to be tested; A processing unit, configured to mark the interface to be tested based on a user operation, add an extended attribute to the test request, and use the interface to be tested after the marking operation as a marked interface; wherein the extended attribute includes: a first extended attribute and a second extended attribute; the first extended attribute is a control judgment condition for selecting an interface processing chain; the second extended attribute is used to provide necessary parameters for adaptation for a processor corresponding to the interface processing chain; A calling unit, used for obtaining the extended attributes of the marked interface based on a program reflection mechanism, and calling an interface processing chain matching the extended attributes; An execution unit, configured to process the interface to be tested using a processor corresponding to the interface processing chain; A feedback unit is used to feed back the processing result of the interface to be tested to the sender of the test request.

5. The interface testing device according to claim 4, characterized in that: The first extended attribute includes but is not limited to: one or a combination of two of a priority parameter and a type parameter; The second extended attribute includes, but is not limited to, one or a combination of two of an environment parameter and an extracted value.

6. The interface testing device according to claim 4, characterized in that: The method of obtaining the extended attributes of the marked interface based on the program reflection mechanism includes: Get the extended attributes of the marked interface based on the Java program reflection mechanism.

7. A readable storage medium, characterized in that: The storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the interface testing method according to any one of claims 1 to 3.

8. An interface testing device, characterized in that: including memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the interface testing method as described in any one of claims 1-3.