CN114385384B - Application programming interface calling method and related equipment - Google Patents

Application programming interface calling method and related equipment Download PDF

Info

Publication number
CN114385384B
CN114385384B CN202111621074.3A CN202111621074A CN114385384B CN 114385384 B CN114385384 B CN 114385384B CN 202111621074 A CN202111621074 A CN 202111621074A CN 114385384 B CN114385384 B CN 114385384B
Authority
CN
China
Prior art keywords
application programming
programming interface
mock
call
message
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111621074.3A
Other languages
Chinese (zh)
Other versions
CN114385384A (en
Inventor
请求不公布姓名
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Unicom Smart Connection Technology Ltd
Original Assignee
China Unicom Smart Connection Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Unicom Smart Connection Technology Ltd filed Critical China Unicom Smart Connection Technology Ltd
Priority to CN202111621074.3A priority Critical patent/CN114385384B/en
Publication of CN114385384A publication Critical patent/CN114385384A/en
Application granted granted Critical
Publication of CN114385384B publication Critical patent/CN114385384B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • G06F9/548Object oriented; Remote method invocation [RMI]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The present invention relates to the field of computer technologies, and in particular, to an application programming interface calling method and related devices. Wherein the method comprises the following steps: receiving a first application programming interface calling request, wherein the first application programming interface calling request comprises identification information of a first application programming interface; searching corresponding mock annotation information from preset configuration information according to the identification information of the first application programming interface, wherein the mock annotation information comprises address information and call type configuration information of the first application programming interface; determining a call type of the first application programming interface according to the mock annotation information, wherein the call type comprises virtual call and real call; if the calling type of the first application programming interface is virtual calling, matching the mock message configuration information stored in the mock service database according to the mock annotation information and the calling request of the first application programming interface to obtain a corresponding simulation message; and responding to the first application programming interface call request according to the simulation message.

Description

Application programming interface calling method and related equipment
[ field of technology ]
The present invention relates to the field of computer technologies, and in particular, to an application programming interface calling method and related devices.
[ background Art ]
The current development of application services often adopts a mode of front-end and back-end development at the same time. In the actual development process, the development difficulty and the workload of the front end are less than those of the back end. The development progress of the front end is often faster than the development progress of the back end. The front-end development depends on the application programming interface (Application Programming Interface, API) of the back-end, and the front-end cannot test and verify the related functions before the back-end completes the development of the API interface. In the prior art, the situation that front-end development excessively depends on a back-end API interface is overcome through a mock technology. When receiving a call request of an API interface sent by the front end, the mock interface replies the request according to the returned preset message information, so that the front end can complete development and test of all functions. However, the existing mock technology has complex logic implementation and high technical requirements for developers.
[ invention ]
In order to solve the above problems, the embodiments of the present invention provide an application programming interface calling method and related devices, which simplify the implementation logic of mock and increase the availability of mock functions in a micro-service development scenario.
In a first aspect, an embodiment of the present invention provides an application programming interface calling method applied to a test terminal, including:
receiving a first application programming interface call request, wherein the first application programming interface call request comprises identification information of a first application programming interface;
searching corresponding mock annotation information from preset configuration information according to the identification information of the first application programming interface, wherein the mock annotation information comprises address information of the first application programming interface;
determining a call type of the first application programming interface according to the mock annotation information, wherein the call type comprises virtual call and real call;
if the call type of the first application programming interface is virtual call, matching the mock message configuration information stored in a mock service database according to the mock annotation information and the call request of the first application programming interface to obtain a corresponding simulation message;
and responding to the first application programming interface call request according to the simulation message.
In the embodiment of the invention, the mock annotation information is added for each application programming interface in the pre-configuration information in advance, and when a call request of the first application programming interface is received, whether the first application programming interface requesting access uses the mock interface or the real interface is determined according to the mock annotation information, so that the difficulty of using a mock technology in micro-service test is reduced.
In one possible implementation manner, before obtaining the mock annotation information of the first application programming interface from preset configuration information, the method further includes:
determining whether the test terminal is in a mock test mode;
and if the test terminal is not in the mock test mode, responding to the first application programming interface call request by using a message with call failure.
In one possible implementation manner, matching the annotation information and the first application programming interface call request with the mock message configuration information stored in the mock service database to obtain a corresponding analog message, including:
determining a request message type and a request parameter of the first application programming interface call request;
searching the return parameters and the return message types of the corresponding simulation messages from the mock message configuration information according to the request message type, the request parameters and the address information of the first application programming interface;
and generating the corresponding simulation message according to the return parameter and the return message type.
In one possible implementation manner, searching the return parameter and the return message type of the corresponding analog message from the mock message configuration information according to the request message type, the request parameter and the address information of the first application programming interface includes:
invoking a Java development tool kit (JDK) dynamic proxy service, wherein the JDK dynamic proxy service determines a request scene of the first application programming interface invoking request according to the request message type and the request parameter;
and searching corresponding simulation message return parameters and return message types from the mock message configuration information according to the request scene and the address information of the first application programming interface.
In one possible implementation, if the call type of the first application programming interface is a real call, the method further includes:
calling the first application programming interface according to the address information of the first application programming interface so that the first application programming interface outputs a corresponding reply message according to the calling request of the first application programming interface;
responding to the first application programming interface according to the reply message.
In one possible implementation, the method further includes:
receiving a micro-service registration instruction, wherein the registration instruction comprises micro-service registration type information;
generating address information of a corresponding newly-built application programming interface according to the micro-service registration type information;
receiving a new application programming interface configuration instruction, wherein the new application programming interface configuration instruction comprises micro service configuration data, and the micro service configuration data at least comprises mock annotation information and mock message configuration information;
and storing the micro service configuration data into the mock service database.
In a second aspect, an embodiment of the present invention provides a test terminal, including:
the communication module is used for receiving a first application programming interface calling request, wherein the first application programming interface calling request comprises identification information and calling type configuration information of the first application programming interface;
the processing module is used for searching corresponding mock annotation information from preset configuration information according to the identification information of the first application programming interface, wherein the mock annotation information comprises address information of the first application programming interface;
the processing module is further used for determining a call type of the first application programming interface according to the mock annotation information, wherein the call type comprises virtual call and real call;
the processing module is further configured to, if the call type of the first application programming interface is a virtual call, match the mock message configuration information stored in the mock service database according to the mock annotation information and the call request of the first application programming interface to obtain a corresponding analog message;
the communication module is further configured to respond to the first application programming interface call request according to the analog message.
In one possible implementation, the processing module is further configured to:
determining whether the test terminal is in a mock test mode;
and if the test terminal is not in the mock test mode, responding to the first application programming interface call request by using a message with call failure.
In a third aspect, an embodiment of the present invention provides an electronic device, including:
at least one processor; and
at least one memory communicatively coupled to the processor, wherein:
the memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the methods of the first to second aspects.
In a fourth aspect, embodiments of the present invention provide a computer-readable storage medium storing computer instructions that cause a computer to perform the methods of the first to second aspects.
It should be understood that, the second to fourth aspects of the embodiments of the present invention are consistent with the technical solutions of the first aspect of the embodiments of the present invention, and the beneficial effects obtained by each aspect and the corresponding possible implementation manner are similar, and are not repeated.
[ description of the drawings ]
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a system architecture diagram of a test system according to an embodiment of the present invention;
FIG. 2 is a flowchart of an application programming interface calling method according to an embodiment of the present invention;
FIG. 3 is a flowchart of another method for calling an application programming interface according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a test terminal according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
[ detailed description ] of the invention
For a better understanding of the technical solutions of the present specification, the following detailed description of the embodiments of the present invention refers to the accompanying drawings.
It should be understood that the described embodiments are only some, but not all, of the embodiments of the present description. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are intended to be within the scope of the present invention based on the embodiments herein.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the description. As used in this application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
In the embodiment of the invention, the call type of the application programming interface is realized by adding the mock annotation information to each application programming interface in advance, and when the call type is virtual call, the corresponding simulation message is determined from the mock service database through the mock interface and returned, so that the management and call of the mock interface are realized in the micro-service architecture.
Fig. 1 is a system architecture diagram of a test system according to an embodiment of the present invention, where, as shown in fig. 1, the system architecture includes a front-end system, a back-end system, and a mock system. The Mock system comprises a registration/configuration center, a service gateway, a Mock service database and a Mock-Server service. The front-end system comprises a Mock-Client service.
Corresponding to the system architecture diagram shown in fig. 1, an embodiment of the present invention provides an application programming interface calling method, as shown in fig. 2, where the processing steps of the method include:
step 201, a first application programming interface call request is received, where the first application programming interface call request includes identification information of a first application programming interface. When the front-end developer wants to test the first application programming interface, the service gateway may analyze the HTTP address by sending a first application programming interface call request in the format of hypertext transfer protocol (Hyper Text Transfer Protocol, HTTP) to the service gateway shown in fig. 1, and send the analyzed first application programming interface call request to the registration/configuration center shown in fig. 1. The HTTP address is the identification information of the first application programming interface. The HTTP addresses of different application programming interfaces are different.
Step 202, searching corresponding mock annotation information from preset configuration information according to the identification information of the first application programming interface, wherein the mock annotation information comprises address information and call type configuration information of the first application programming interface. The dock annotation information is used for marking whether the first application programming interface supports dock call, and if so, the dock annotation information also comprises a dock interface address of the first application programming interface. If the mock call is not supported, the mock annotation information may contain the actual interface address of the address application programming interface. I.e. the real back-end API interface address.
Step 203, determining a call type of the first application programming interface according to the mock annotation information, wherein the call type comprises a virtual call and a real call. The virtual call is to call the mock interface and return preset message information, and the real call is to call the API interface developed and completed by the back end and return real message information.
And 204, if the call type of the first application programming interface is virtual call, matching the mock message configuration information stored in the mock service database according to the mock annotation information and the call request of the first application programming interface to obtain a corresponding simulation message. Wherein, when the call type is a virtual call, the registration/configuration center calls the Mock-Server service shown in fig. 1. The Mock-Server service accesses the Mock message configuration information stored in the Mock service database through the address information in the annotation, so as to obtain the corresponding simulation message.
In a specific example, when the framework used may be a feign open source framework, on the basis of the functions of the feign-hystrix module in the feign open source project, the fallback function may be extended to implement the relevant content in step 204. The FallBackFactory default implementation FallBackFactory. If the remote call fails (according to the system application configuration and deployment environment), a return value mock is made. If the call is successful, no FallbackFactory will be entered.
In some embodiments, if the call type of the first application programming interface is a real call, the real first application programming interface may be called instead of the mock interface, so that the front-end developer may configure different test modes for different application programming interfaces according to the completion condition of the back-end API interface. Specifically, the first application programming interface may be called according to the address information of the first application programming interface, so that the first application programming interface outputs a corresponding reply message according to the call request of the first application programming interface.
Step 205, responding to the first application programming interface call request according to the simulation message.
In some embodiments, it may also be determined whether the current system state of the test terminal supports interface mock before the mock annotation information of the first application programming interface is obtained from the pre-configuration information. It may be first determined whether the test terminal is in the mock test mode. Specifically, whether the mock function is currently supported or not can be determined according to the micro-service configuration file of the test terminal, and if so, the corresponding parameter is mock. And if the test terminal is not in the test mode, responding to the first application programming interface call request by using the message with the call failure. Thus, the first application programming interface may only be mock enabled if the parameter in the micro-service configuration file is mock.enable and the call type configuration information in the mock annotation of the first application programming interface is configured as a virtual call.
In some embodiments, after determining that the call type of the first application programming interface is a virtual call, it may further first determine whether a corresponding analog message exists in the mock service database, and if so, generate the analog message. The processing steps for generating the analog message are shown in fig. 3:
step 301, determining a request message type and a request parameter of a first application programming interface call request.
Step 302, searching the return parameters and the return message types of the corresponding analog messages from the mock message configuration information according to the request message type, the request parameters and the address information of the first application programming interface. For example, when the login function is tested, for the login scenes of different users, the login result scene can be determined according to the user name and the user password, and the login result scene comprises login success and login failure. In the Mock message configuration information, a user password corresponding to the user name is configured. When the user name and the user password in the first application programming interface call request are not matched with the mock leopard print configuration information, determining that login fails, and generating a corresponding simulation message, wherein the message content can be as follows: the user name or password is incorrect.
In one specific example, when implementing step 302, a method of Java development kit (Java Development Kit, JDK) dynamic proxy may be used to implement a mock interface that accesses a mock database. Specifically, a Java development tool package JDK dynamic proxy service may be invoked, where the JDK dynamic proxy service determines a request scenario of a first application programming interface call request according to a request message type and a request parameter. And searching corresponding simulation message return parameters and return message types from the mock message configuration information according to the request scene and the address information of the first application programming interface.
Step 303, generating a corresponding simulation message according to the return parameter and the return message type.
In some embodiments, the front-end tester registers the micro-services being developed in advance as needed to generate the corresponding application programming interfaces, and then performs specific mock testing based on the generated application programming interfaces. Specifically, the registration/configuration center shown in fig. 1 receives a micro service registration instruction, which includes micro service registration type information. And generating address information of the corresponding newly-built application programming interface according to the micro-service registration type information. Wherein the address information of the application programming interface comprises service interface information and access address information. And then the front-end developer can configure the specific mock virtual message. Specifically, a newly-built application programming interface configuration instruction is received, the newly-built application programming interface configuration instruction comprises micro-service configuration data, and the micro-service configuration data at least comprises mock annotation information and mock message configuration information. The micro service configuration data may then be stored in a mock service database.
In the embodiment of the invention, the Mock annotation is used for identification on the application programming interface, whether the currently accessed interface supports the Mock function is enhanced and identified in the custom Fallback Factoy, and meanwhile, according to the access address of the Mock annotation, the multi-scene multi-user scene simulation of the dynamic Mock simulation message is realized through a JDK dynamic proxy realization mechanism of JAVA. And registration/configuration centers are used to achieve registration of the micro-services and configuration of the micro-services. And by changing the configuration information of the mock message in the mock service database, the method can realize cross-platform, cross-language and cross-environment.
Alternatively, nacos may be selected as the registration/configuration center. Or split the registry/configuration center into a registry and a configuration center. The registry may use Eureka, zookeeper and condul. The configuration center may use SpringCloud Config Apollo. The registration/configuration center can realize the management and document generation of the interface API by using a Swagger mode, beautifies related pages and displays by using the knife4j, and realizes the unified management of the API by unified management of the pages.
The application programming interface calling method provided by the embodiment of the invention solves the defects that the mock interface in the prior art has no universality and configurability and the type of the interface message return is limited.
Corresponding to the above application programming interface calling method, the embodiment of the invention provides a structural schematic diagram of a test terminal. As shown in fig. 4, the test terminal includes a communication module 401 and a processing module 402.
The communication module 401 is configured to receive a first application programming interface call request, where the first application programming interface call request includes identification information and call type configuration information of the first application programming interface.
The processing module 402 is configured to search corresponding mock annotation information from preset configuration information according to identification information of the first application programming interface, where the mock annotation information includes address information of the first application programming interface.
The processing module 402 is further configured to determine a call type of the first application programming interface according to the mock annotation information, where the call type includes a virtual call and a real call.
And the processing module 402 is further configured to, if the call type of the first application programming interface is a virtual call, match the mock message configuration information stored in the mock service database according to the mock annotation information and the call request of the first application programming interface, and obtain a corresponding analog message.
The communication module 401 is further configured to respond to the first application programming interface call request according to the analog message.
In some embodiments, the processing module 402 is further to:
it is determined whether the test terminal is in the mock test mode.
And if the test terminal is not in the mock test mode, responding to the first application programming interface call request by using the message with the call failure.
The test terminal provided in the embodiment shown in fig. 4 may be used to implement the technical solutions of the method embodiments shown in fig. 1 to 3 in the present specification, and the implementation principle and technical effects may be further referred to in the related description of the method embodiments.
Fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention, where, as shown in fig. 5, the electronic device may include at least one processor and at least one memory communicatively connected to the processor, where: the memory stores program instructions executable by a processor that are capable of executing the application programming interface calling methods provided by the embodiments of fig. 1-3 of the present specification.
As shown in fig. 5, the electronic device is in the form of a general purpose computing device. Components of an electronic device may include, but are not limited to: one or more processors 510, a communication interface 520, and a memory 530, a communication bus 540 that connects the various system components (including the memory 530, the communication interface 520, and the processing unit 510).
Communication bus 540 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include industry Standard architecture (Industry Standard Architecture; hereinafter ISA) bus, micro channel architecture (Micro Channel Architecture; hereinafter MAC) bus, enhanced ISA bus, video electronics standards Association (Video Electronics Standards Association; hereinafter VESA) local bus, and peripheral component interconnect (Peripheral Component Interconnection; hereinafter PCI) bus.
Electronic devices typically include a variety of computer system readable media. Such media can be any available media that can be accessed by the electronic device and includes both volatile and nonvolatile media, removable and non-removable media.
Memory 530 may include computer system readable media in the form of volatile memory, such as random access memory (Random Access Memory; hereinafter: RAM) and/or cache memory. The electronic device may further include other removable/non-removable, volatile/nonvolatile computer system storage media. Memory 530 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of the embodiments of the present description.
A program/utility having a set (at least one) of program modules may be stored in the memory 530, such program modules include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules typically carry out the functions and/or methods of the embodiments described herein.
The processor 510 executes various functional applications and data processing by running programs stored in the memory 530, for example, implementing the application programming interface calling methods provided by the embodiments shown in fig. 1-3 of the present specification.
Embodiments of the present disclosure provide a computer readable storage medium storing computer instructions that cause a computer to perform the application programming interface calling methods provided by the embodiments of fig. 1-3 of the present disclosure.
Any combination of one or more computer readable media may be utilized as the above-described computer readable storage media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an erasable programmable Read-Only Memory (Erasable Programmable Read Only Memory; EPROM) or flash Memory, an optical fiber, a portable compact disc Read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The foregoing describes specific embodiments of the present disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
In the description of the present specification, a description referring to terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present specification. In this specification, schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, the different embodiments or examples described in this specification and the features of the different embodiments or examples may be combined and combined by those skilled in the art without contradiction.
Furthermore, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include at least one such feature. In the description of the present specification, the meaning of "plurality" means at least two, for example, two, three, etc., unless explicitly defined otherwise.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process, and additional implementations are included within the scope of the preferred embodiment of the present specification in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the embodiments of the present specification.
Depending on the context, the word "if" as used herein may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to detection". Similarly, the phrase "if determined" or "if detected (stated condition or event)" may be interpreted as "when determined" or "in response to determination" or "when detected (stated condition or event)" or "in response to detection (stated condition or event), depending on the context.
It should be noted that the devices according to the embodiments of the present disclosure may include, but are not limited to, a personal Computer (Personal Computer; hereinafter referred to as a PC), a personal digital assistant (Personal Digital Assistant; hereinafter referred to as a PDA), a wireless handheld device, a Tablet Computer (Tablet Computer), a mobile phone, an MP3 display, an MP4 display, and the like.
In the several embodiments provided in this specification, it should be understood that the disclosed systems, apparatuses, and methods may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the elements is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple elements or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
In addition, each functional unit in each embodiment of the present specification may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in hardware plus software functional units.
The integrated units implemented in the form of software functional units described above may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium, and includes several instructions for causing a computer device (which may be a personal computer, a connector, or a network device, etc.) or a Processor (Processor) to perform part of the steps of the methods described in the embodiments of the present specification. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a Read-Only Memory (hereinafter referred to as ROM), a random access Memory (Random Access Memory) and various media capable of storing program codes such as a magnetic disk or an optical disk.
The foregoing description of the preferred embodiments is provided for the purpose of illustration only, and is not intended to limit the scope of the disclosure, since any modifications, equivalents, improvements, etc. that fall within the spirit and principles of the disclosure are intended to be included within the scope of the disclosure.

Claims (10)

1. An application programming interface calling method, wherein the method is applied to a test terminal and comprises the following steps:
receiving a first application programming interface call request, wherein the first application programming interface call request comprises identification information of a first application programming interface;
searching corresponding mock annotation information from preset configuration information according to the identification information of the first application programming interface, wherein the mock annotation information comprises address information and call type configuration information of the first application programming interface;
determining a call type of the first application programming interface according to the mock annotation information, wherein the call type comprises virtual call and real call;
if the call type of the first application programming interface is virtual call, matching the mock message configuration information stored in a mock service database according to the mock annotation information and the call request of the first application programming interface to obtain a corresponding simulation message;
and responding to the first application programming interface call request according to the simulation message.
2. The method of claim 1, wherein prior to obtaining the mock annotation information for the first application programming interface from the preset configuration information, the method further comprises:
determining whether the test terminal is in a mock test mode;
and if the test terminal is not in the mock test mode, responding to the first application programming interface call request by using a message with call failure.
3. The method of claim 1, wherein matching the annotation information and the first application programming interface call request with mock message configuration information stored in a mock service database to obtain a corresponding analog message comprises:
determining a request message type and a request parameter of the first application programming interface call request;
searching the return parameters and the return message types of the corresponding simulation messages from the mock message configuration information according to the request message type, the request parameters and the address information of the first application programming interface;
and generating the corresponding simulation message according to the return parameter and the return message type.
4. The method of claim 3, wherein searching the corresponding return parameters and return message types of the analog message from the mock message configuration information according to the request message type, the request parameters and the address information of the first application programming interface comprises:
invoking a Java development tool kit (JDK) dynamic proxy service, wherein the JDK dynamic proxy service determines a request scene of the first application programming interface invoking request according to the request message type and the request parameter;
and searching corresponding simulation message return parameters and return message types from the mock message configuration information according to the request scene and the address information of the first application programming interface.
5. The method of claim 1, wherein if the call type of the first application programming interface is a real call, the method further comprises:
calling the first application programming interface according to the address information of the first application programming interface so that the first application programming interface outputs a corresponding reply message according to the calling request of the first application programming interface;
responding to the first application programming interface according to the reply message.
6. The method according to claim 1, wherein the method further comprises:
receiving a micro-service registration instruction, wherein the registration instruction comprises micro-service registration type information;
generating address information of a corresponding newly-built application programming interface according to the micro-service registration type information;
receiving a new application programming interface configuration instruction, wherein the new application programming interface configuration instruction comprises micro service configuration data, and the micro service configuration data at least comprises mock annotation information and mock message configuration information;
and storing the micro service configuration data into the mock service database.
7. A test terminal, comprising:
the communication module is used for receiving a first application programming interface calling request, wherein the first application programming interface calling request comprises identification information and calling type configuration information of the first application programming interface;
the processing module is used for searching corresponding mock annotation information from preset configuration information according to the identification information of the first application programming interface, wherein the mock annotation information comprises address information of the first application programming interface;
the processing module is further used for determining a call type of the first application programming interface according to the mock annotation information, wherein the call type comprises virtual call and real call;
the processing module is further configured to, if the call type of the first application programming interface is a virtual call, match the mock message configuration information stored in the mock service database according to the mock annotation information and the call request of the first application programming interface to obtain a corresponding analog message;
the communication module is further configured to respond to the first application programming interface call request according to the analog message.
8. The test terminal of claim 7, wherein the processing module is further configured to:
determining whether the test terminal is in a mock test mode;
and if the test terminal is not in the mock test mode, responding to the first application programming interface call request by using a message with call failure.
9. An electronic device, comprising:
at least one processor; and
at least one memory communicatively coupled to the processor, wherein:
the memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the method of any of claims 1-6.
10. A computer readable storage medium storing computer instructions for causing a computer to perform the method of any one of claims 1 to 6.
CN202111621074.3A 2021-12-28 2021-12-28 Application programming interface calling method and related equipment Active CN114385384B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111621074.3A CN114385384B (en) 2021-12-28 2021-12-28 Application programming interface calling method and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111621074.3A CN114385384B (en) 2021-12-28 2021-12-28 Application programming interface calling method and related equipment

Publications (2)

Publication Number Publication Date
CN114385384A CN114385384A (en) 2022-04-22
CN114385384B true CN114385384B (en) 2023-11-21

Family

ID=81197657

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111621074.3A Active CN114385384B (en) 2021-12-28 2021-12-28 Application programming interface calling method and related equipment

Country Status (1)

Country Link
CN (1) CN114385384B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109299010A (en) * 2018-09-25 2019-02-01 深圳壹账通智能科技有限公司 Mock test method, device, computer equipment and storage medium
CN109656807A (en) * 2018-11-01 2019-04-19 平安科技(深圳)有限公司 Interface mock test method, device, equipment and storage medium based on information security
CN111399819A (en) * 2020-03-18 2020-07-10 北京达佳互联信息技术有限公司 Data generation method and device, electronic equipment and storage medium
CN111831277A (en) * 2020-09-21 2020-10-27 腾讯科技(深圳)有限公司 Virtual data generation method, device, equipment and computer readable storage medium
CN112035282A (en) * 2020-09-01 2020-12-04 北京百度网讯科技有限公司 API management method, device, equipment and storage medium applied to cloud platform
CN112131118A (en) * 2020-09-25 2020-12-25 平安国际智慧城市科技股份有限公司 Mock testing method, Mock testing device, electronic equipment and computer readable storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109299010A (en) * 2018-09-25 2019-02-01 深圳壹账通智能科技有限公司 Mock test method, device, computer equipment and storage medium
CN109656807A (en) * 2018-11-01 2019-04-19 平安科技(深圳)有限公司 Interface mock test method, device, equipment and storage medium based on information security
CN111399819A (en) * 2020-03-18 2020-07-10 北京达佳互联信息技术有限公司 Data generation method and device, electronic equipment and storage medium
CN112035282A (en) * 2020-09-01 2020-12-04 北京百度网讯科技有限公司 API management method, device, equipment and storage medium applied to cloud platform
CN111831277A (en) * 2020-09-21 2020-10-27 腾讯科技(深圳)有限公司 Virtual data generation method, device, equipment and computer readable storage medium
CN112131118A (en) * 2020-09-25 2020-12-25 平安国际智慧城市科技股份有限公司 Mock testing method, Mock testing device, electronic equipment and computer readable storage medium

Also Published As

Publication number Publication date
CN114385384A (en) 2022-04-22

Similar Documents

Publication Publication Date Title
WO2020233369A1 (en) Method for improving software integration system on basis of simulated port, and related device
CN109873735B (en) Performance test method and device for H5 page and computer equipment
CN111597110B (en) Page test method and device, electronic equipment and storage medium
CN110955409B (en) Method and device for creating resources on cloud platform
CN111143087A (en) Interface calling method and device, storage medium and server
CN110320378B (en) Method, apparatus, device and computer readable storage medium for applying for a quality control test
CN111858296A (en) Interface test method, device, equipment and storage medium
CN113360377B (en) Test method and device
She et al. Hermes: A tool for testing mobile device applications
CN114385384B (en) Application programming interface calling method and related equipment
CN111752644A (en) Interface simulation method, device, equipment and storage medium
CN114527983A (en) Interface adaptation method and device based on middleware and electronic equipment
CN112181822A (en) Test method and test method for starting time consumption of application program
CN112416747A (en) Test case execution method, device, equipment and medium
CN111124627B (en) Method and device for determining call initiator of application program, terminal and storage medium
CN111309407A (en) Processing method and device for integrated third-party library
CN116028356A (en) Bluetooth-based terminal software testing method and device
CN116414689A (en) Interface parameter verification method and system based on reflection mechanism
CN111488286B (en) Method and device for independently developing Android modules
CN112379967B (en) Simulator detection method, device, equipment and medium
CN110825370A (en) Mobile terminal application development method, device and system
CN112732547B (en) Service testing method and device, storage medium and electronic equipment
CN115016968A (en) Exception handling method, device, equipment and medium
CN111984541A (en) Memory leak detection method and device and terminal
CN112631812A (en) Identification setting method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant