CN-122019370-A - API (application programming interface) testing method, device, equipment and medium
Abstract
The application discloses a method, a device, equipment and a medium for testing the performance of an Application Programming Interface (API), which are used for testing the performance of the API rapidly and accurately. The method comprises the steps that electronic equipment sends a control instruction to tested equipment, the control instruction is an instruction for allowing the initiator equipment and the receiver equipment to communicate through a target API, based on a first hook function, the communication instruction for enabling the initiator equipment to communicate through the target API and the receiver equipment is sent to the initiator equipment, first data statistics information is obtained from the tested equipment, the first data statistics information comprises data information sent by the initiator equipment, based on a second hook function, second data statistics information comprises data information received by the receiver equipment is obtained from the receiver equipment, based on the first data statistics information and the second data statistics information, whether the performance of the target API passes testing is judged, and the performance of the API can be tested rapidly and accurately.
Inventors
- LI HUIYU
- LI ZONGJIE
- LIU WEI
Assignees
- 曙光网络科技有限公司
- 佛山市顺德合耕信息科技有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260104
Claims (10)
- 1. An API performance testing method, applied to an electronic device, comprising: Sending a control instruction to tested equipment to which a target API to be tested belongs, so that the tested equipment performs corresponding operation according to the control instruction, wherein the control instruction is an instruction for allowing an initiator device and a receiver device to communicate through the target API; based on a first hook function, sending a communication instruction to the initiator device, wherein the communication instruction is communicated with the receiver device through the target API; Obtaining first data statistics information from the tested device, wherein the first data statistics information comprises data information sent by the initiator device to the receiver device through the target API, and obtaining second data statistics information from the receiver device based on a second hook function, and the second data statistics information comprises data information received by the receiver device from the initiator device through the target API; And judging whether the target API performance passes the test or not based on the first data statistical information and the second data statistical information.
- 2. The method of claim 1, wherein prior to sending the control instruction to the device under test to which the target API to be tested belongs, the method further comprises: Based on a pre-hook function, sending a test target API request to the tested equipment, and receiving license certificate information which is returned by the tested equipment and aims at the target API; The sending the control instruction to the tested equipment to which the target API to be tested belongs comprises the following steps: And sending a control instruction carrying the license information to the tested equipment, so that the tested equipment carries out corresponding operation according to the control instruction when the license information is identified to be qualified.
- 3. The method of claim 1, wherein the obtaining first data statistics from the device under test comprises: receiving response information returned by the tested equipment, wherein the response information carries the first data statistical information, and the first data statistical information contains the sending data quantity, or, Acquiring first data statistical information from the tested equipment based on a post-hook function, wherein the first data statistical information comprises a transmission data amount; the determining whether the target API performance passes the test based on the first data statistics and the second data statistics includes: Determining a ratio between an amount of received data in the second data statistic and an amount of transmitted data in the first data statistic; and judging whether the target API performance passes the test or not based on the ratio and the set ratio threshold.
- 4. The method of claim 3, wherein obtaining the first data statistics from the device under test based on a post-hook function further comprises sending a listening destination port identification of data by a sender device and an actual rolling out destination port identification of data forwarded by the device under test; based on the first data statistics and the second data statistics, determining whether the target API performance passes a test, including: Determining a reference forwarding destination port identifier corresponding to the monitoring destination port identifier according to a pre-configured port conversion corresponding relation; And judging whether the target API performance passes a test or not based on whether the actual transfer-out destination port identification is consistent with the reference transfer-out destination port identification and the ratio between the received data volume in the second data statistical information and the transmitted data volume in the first data statistical information.
- 5. The method according to any one of claims 1-4, wherein before sending the control instruction to the device under test to which the target API to be tested belongs, the method further comprises: And generating a test case of the target API based on the information of the preset field, and carrying out an API performance test flow which comprises the step of sending a control instruction to tested equipment to which the target API to be detected belongs.
- 6. The method of claim 5, wherein the obtaining information of the preset field of the target API comprises: pulling the API document of the target API from the tested equipment, obtaining the information of preset fields from the API document, or And recording the data information of the API in the tested equipment based on a recorder in Pytest test frames, and acquiring the information of the preset field of the target API based on the data information.
- 7. The method of claim 5, wherein if the information of the preset field includes information of a URL field of a uniform resource locator, generating information of a URL field in a test case of the target API based on the information of the preset field includes: And splicing the basic URL with the URL field information in the preset field information to obtain the URL field information in the test case.
- 8. The method of claim 5, wherein the test case format comprises YAML format, javaScript object notation JSON format, or extensible markup language XML format.
- 9. An application programming interface API performance testing apparatus for use with an electronic device, the apparatus comprising: the device comprises a first sending module, a second sending module and a second sending module, wherein the first sending module is used for sending a control instruction to tested equipment to which a target API to be tested belongs, so that the tested equipment performs corresponding operation according to the control instruction, and the control instruction is an instruction allowing an initiator device and a receiver device to communicate through the target API; A second sending module, configured to send, to the initiator device, a communication instruction for communicating with the receiver device through the target API based on the first hook function; An obtaining module, configured to obtain first data statistics from the device under test, where the first data statistics includes data information sent by the initiator device to the receiver device through the target API, and obtain second data statistics from the receiver device based on a second hook function, where the second data statistics includes data information received by the receiver device from the initiator device through the target API; And the judging module is used for judging whether the target API performance passes the test or not based on the first data statistical information and the second data statistical information.
- 10. An electronic device, comprising: a memory for storing program instructions; A processor for invoking program instructions stored in the memory and for performing the steps comprised in the method according to any of claims 1-8 in accordance with the obtained program instructions.
Description
API (application programming interface) testing method, device, equipment and medium Technical Field The present application relates to the field of data processing technologies, and in particular, to a method, an apparatus, a device, and a medium for testing performance of an application programming interface (Application Programming Interface, API). Background In modern software development lifecycles (Software Development LIFE CYCLE, SDLC), especially in a micro-service architecture and front-end and back-end split mode, the stability, reliability and correctness of APIs as a bridge for communication between different services are critical. The performance of the API is a key link for guaranteeing stability, reliability and correctness of the API. However, there is no good solution at present how to test the performance of the API quickly and accurately. Disclosure of Invention The application provides a method, a device, equipment and a medium for testing the performance of an application programming interface (Application Programming Interface, API) so as to test the performance of the API rapidly and accurately. In a first aspect, the present application provides a method for testing API performance of an application programming interface, applied to an electronic device, the method comprising: Sending a control instruction to tested equipment to which a target API to be tested belongs, so that the tested equipment performs corresponding operation according to the control instruction, wherein the control instruction is an instruction for allowing an initiator device and a receiver device to communicate through the target API; based on a first hook function, sending a communication instruction to the initiator device, wherein the communication instruction is communicated with the receiver device through the target API; Obtaining first data statistics information from the tested device, wherein the first data statistics information comprises data information sent by the initiator device to the receiver device through the target API, and obtaining second data statistics information from the receiver device based on a second hook function, and the second data statistics information comprises data information received by the receiver device from the initiator device through the target API; And judging whether the target API performance passes the test or not based on the first data statistical information and the second data statistical information. By the method, the electronic device can send the control instruction to the tested device to which the target API to be tested belongs, wherein the control instruction is an instruction for allowing the initiator device and the receiver device to communicate through the target API, meanwhile, the communication instruction for allowing the initiator device to communicate with the receiver device through the target API can be sent to the initiator device based on the first hook function, then, the first data statistics information can be obtained from the tested device, the first data statistics information comprises data information sent to the receiver device through the target API by the initiator device, and the second data statistics information comprises data information received from the initiator device through the target API by the receiver device based on the second hook function, so that whether the performance of the target API passes the test or not can be judged based on the first data statistics information and the second data statistics information, and the purpose of rapidly and accurately testing the performance of the API can be achieved based on the first data statistics information and the second data statistics information. In addition, the embodiment of the application can be based on a special hook (Hooks) mechanism, breaks through the limitation that the API performance is judged only based on the data information counted by the tested equipment, can obtain the second data statistic information received by the receiver equipment from the initiator equipment through the target API based on the hook function, can verify the complete data forwarding service flow based on the first data statistic information and the second data statistic information sent by the initiator equipment to the receiver equipment through the target API, realizes the end-to-end service scene verification, and improves the accuracy of the API performance test. In a possible implementation manner, before the sending a control instruction to the tested device to which the target API to be tested belongs, the method further includes: Based on a pre-hook function, sending a test target API request to the tested equipment, and receiving license certificate information which is returned by the tested equipment and aims at the target API; The sending the control instruction to the tested equipment to which the target API to be tested belongs comprises the following steps: A