Application programming interface (API) test method and device, equipment and medium

By sending control commands to the target API device and using hook functions to obtain data statistics, the problem of inaccurate API performance testing in existing technologies is solved, enabling fast and accurate API performance evaluation and end-to-end verification.

CN122019370APending Publication Date: 2026-05-12DAWNING NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
DAWNING NETWORK TECH CO LTD
Filing Date
2026-01-04
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

The lack of quick and accurate API performance testing methods in existing technologies makes it difficult to guarantee the stability and reliability of APIs.

Method used

By sending control commands to the device under test to which the target API belongs, and using hook functions to obtain data statistics from the initiating and receiving devices, API performance is judged based on this information, including using pre-hook functions to verify license certificates and post-hook functions to obtain data volume ratios.

Benefits of technology

It enables fast and accurate API performance testing, improves the accuracy and security of testing, and can verify the data forwarding business process end-to-end.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019370A_ABST
    Figure CN122019370A_ABST
Patent Text Reader

Abstract

The invention discloses an application programming interface (API) performance test method and device, equipment and a medium, which are used for quickly and accurately testing the performance of an API. In the method, an electronic device sends a control instruction to a tested device, and the control instruction is an instruction allowing communication between an initiator device and a receiver device through a target API; based on the first hook function, sending a communication instruction for enabling the initiator device to communicate with the receiver device through the target API to the initiator device; based on the first hook function, obtaining first data statistical information from the tested device, the first data statistical information comprising data information sent by the initiator device, based on the second hook function, obtaining second data statistical information from the receiver device, the second data statistical information comprising data information received by the receiver device, and judging whether the performance of the target API passes the test or not based on the first data statistical information and the second data statistical information, so that the performance of the API can be quickly and accurately tested.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to an application programming interface (API) performance testing method, apparatus, device and medium. Background Technology

[0002] In the modern Software Development Life Cycle (SDLC), especially in microservice architectures and front-end / back-end separation models, APIs serve as bridges for communication between different services, and their stability, reliability, and correctness are crucial. Among these, performance testing of APIs is a key step in ensuring their stability, reliability, and correctness.

[0003] However, there is currently no good solution for how to quickly and accurately test the performance of APIs. Summary of the Invention

[0004] This application provides an application programming interface (API) performance testing method, apparatus, device, and medium for quickly and accurately testing API performance.

[0005] In a first aspect, this application provides an application programming interface (API) performance testing method, applied to electronic devices, the method comprising: Send a control command to the device under test to which the target API belongs, so that the device under test performs a corresponding operation according to the control command, wherein the control command is an instruction that allows the initiating device and the receiving device to communicate through the target API; Based on the first hook function, a communication instruction is sent to the initiating device to communicate with the receiving device through the target API; First data statistics are obtained from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API; and second data statistics are obtained from the receiving device based on the second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API. Based on the first and second data statistics, a judgment is made as to whether the performance of the target API passes the test.

[0006] In this way, the electronic device can send control commands to the device under test (DUT) to which the target API belongs. These control commands allow communication between the initiating device and the receiving device via the target API. Simultaneously, based on a first hook function, a communication command can be sent to the initiating device to enable communication between the initiating device and the receiving device via the target API. Then, first data statistics can be obtained from the DUT, containing data sent from the initiating device to the receiving device via the target API. Based on a second hook function, second data statistics can be obtained from the receiving device, containing data received by the receiving device from the initiating device via the target API. Based on both the first and second data statistics, the performance of the target API can be judged to determine whether it has passed the test. This allows for quick and accurate performance testing of the API.

[0007] Furthermore, this application embodiment can break through the limitations of traditional methods that rely solely on statistical data from the device under test to judge API performance based on a unique hook mechanism. This application embodiment can obtain the second data statistics received by the receiving device from the initiating device through the target API based on the hook function. Based on the first data statistics sent by the initiating device to the receiving device through the target API and the aforementioned second data statistics, the complete data forwarding business process can be verified, achieving end-to-end business scenario verification and improving the accuracy of API performance testing.

[0008] In one possible implementation, before sending control commands to the device under test (DUT) to which the target API belongs, the method further includes: Based on the pre-hook function, a test target API request is sent to the device under test, and the license certificate information for the target API returned by the device under test is received. Sending control commands to the device under test to which the target API belongs includes: A control command carrying the license certificate information is sent to the device under test, so that when the device under test recognizes that the license certificate information is compliant, it performs the corresponding operation according to the control command.

[0009] Using the above method, a test API request can be sent to the device under test based on a pre-hook function, and the license certificate information for the target API returned by the device under test can be received. When sending control commands to the device under test later, the license certificate information can be included in the control commands. The device under test will only perform the corresponding operation according to the control commands when it recognizes that the license certificate information is compliant, thereby ensuring the security of the API performance testing process.

[0010] In one possible implementation, obtaining the first data statistics from the device under test includes: Receive response information returned by the device under test, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or, Based on the post-hook function, the first data statistics information is obtained from the device under test, and the first data statistics information includes the amount of data sent. The step of determining whether the target API performance passes the test based on the first and second data statistics includes: Determine the ratio between the amount of data received in the second data statistics and the amount of data sent in the first data statistics; Based on the ratio and the set ratio threshold, the performance of the target API is judged to determine whether it passes the test.

[0011] By using the above method, the ratio between the amount of data received and the amount of data sent can be determined. Based on this ratio and the set ratio threshold, the performance of the target API can be quickly and accurately judged to improve the accuracy of API performance testing.

[0012] In one possible implementation, the first data statistics obtained from the device under test based on the post-hook function further includes: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test. Based on the first and second data statistics, a judgment is made on whether the performance of the target API passes the test, including: Based on the pre-configured port translation correspondence, determine the base outgoing destination port identifier corresponding to the listening destination port identifier; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

[0013] Using the above method, the listening destination port identifier of the sending device and the actual forwarding destination port identifier of the data forwarded by the device under test can be obtained. Based on the pre-configured port conversion correspondence, the baseline forwarding destination port identifier corresponding to the listening destination port identifier can be determined. Then, based on whether the actual forwarding destination port identifier and the baseline forwarding destination port identifier are consistent, and the ratio between the received data volume and the sent data volume, the performance of the target API can be quickly and accurately judged to improve the accuracy of API performance testing.

[0014] In one possible implementation, before sending control commands to the device under test (DUT) to which the target API belongs, the method further includes: Obtain information about preset fields of the target API; generate test cases for the target API based on the information about preset fields; and perform API performance testing based on the test cases, including the step of sending control commands to the device under test to which the target API belongs.

[0015] Using the above method, test cases for the target API can be generated quickly and efficiently by obtaining information from the target API's preset fields. Based on these test cases, the performance of the target API can be tested quickly and accurately.

[0016] In one possible implementation, obtaining information about a preset field of the target API includes: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

[0017] The above methods allow for the quick and efficient acquisition of the target API's preset field information. This can be achieved by either retrieving the API documentation from the device under test, which contains information about the target API's preset fields, or by recording API data from the device under test using the recorder in the Pytest testing framework, which also contains information about the target API's preset fields. Based on this information, the efficiency of test case generation (creation) can be improved.

[0018] In one possible implementation, if the information in the preset field includes information from the Uniform Resource Locator (URL) field, information from the URL field in the test cases of the target API is generated based on the information from the preset field, including: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

[0019] Using the above method, the base URL applicable to global configuration can be quickly and accurately obtained based on the configuration manager in the Pytest testing framework. Then, by concatenating the base URL with the information in the URL field of the target API's preset fields, the information in the URL field of the target API's test cases can be quickly and accurately obtained, improving the efficiency and accuracy of test case generation.

[0020] In one possible implementation, the test cases may be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

[0021] By using the above methods, test cases can be generated in YAML, JSON, or XML formats, which have concise syntax and low learning curves, thereby improving the efficiency, flexibility, and convenience of test case generation.

[0022] Secondly, this application provides an application programming interface (API) performance testing device for electronic devices, the device comprising: The first sending module is used to send control instructions to the device under test to which the target API belongs, so that the device under test performs corresponding operations according to the control instructions. The control instructions are instructions that allow the initiating device and the receiving device to communicate through the target API. The second sending module is used to send a communication instruction to the initiating device to communicate with the receiving device through the target API, based on the first hook function; The acquisition module is used to obtain first data statistics from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API, and to obtain second data statistics from the receiving device based on the second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API; The adjudication module is used to determine whether the performance of the target API passes the test based on the first data statistics and the second data statistics.

[0023] In one possible implementation, the first transmitting module is further configured to: Based on the pre-hook function, a test target API request is sent to the device under test, and the license certificate information for the target API returned by the device under test is received. A control command carrying the license certificate information is sent to the device under test, so that when the device under test recognizes that the license certificate information is compliant, it performs the corresponding operation according to the control command.

[0024] In one possible implementation, the acquisition module is specifically used for: Receive response information returned by the device under test, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or, Based on the post-hook function, the first data statistics information is obtained from the device under test, and the first data statistics information includes the amount of data sent. Determine the ratio between the amount of data received in the second data statistics and the amount of data sent in the first data statistics; Based on the ratio and the set ratio threshold, the performance of the target API is judged to determine whether it passes the test.

[0025] In one possible implementation, the first data statistics obtained from the device under test based on the post-hook function further includes: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test. The adjudication module is specifically used to: determine the base outgoing destination port identifier corresponding to the monitoring destination port identifier according to the pre-configured port conversion correspondence; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

[0026] In one possible implementation, the device further includes: The test case creation module is used to obtain information about preset fields of the target API; based on the information about preset fields, it generates test cases for the target API; and based on the test cases, it performs a subsequent API performance test process, which includes the step of sending control commands to the device under test to which the target API belongs.

[0027] In one possible implementation, the test case creation module is specifically used for: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

[0028] In one possible implementation, the test case creation module is specifically used for: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

[0029] In one possible implementation, the test cases may be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

[0030] Thirdly, this application also provides a schematic diagram of an API performance testing system, which includes: Electronic devices used to send control commands to the device under test to which the target API belongs; The device under test is used to receive control commands sent by the electronic device and perform corresponding operations according to the control commands, wherein the control commands are instructions that allow the initiating device and the receiving device to communicate through the target API; The electronic device is also configured to send a communication instruction to the initiating device to communicate with the receiving device through the target API, based on the first hook function; The initiating device is configured to perform corresponding operations according to the communication instruction if it receives the communication instruction. The electronic device is further configured to obtain first data statistics from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API, and to obtain second data statistics from the receiving device based on a second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API; The electronic device is also used to determine whether the performance of the target API passes the test based on the first data statistics and the second data statistics.

[0031] In one possible implementation, the electronic device is further configured to send a test target API request to the device under test based on a pre-hook function; The device under test is also configured to return license information for the target API to the electronic device; The electronic device is specifically used to send control commands carrying the license certificate information to the device under test; The device under test is specifically used to perform corresponding operations according to the control instructions when the license certificate information is found to be compliant.

[0032] In one possible implementation, the device under test is specifically configured to return response information to the electronic device, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or... The electronic device is specifically used to obtain the first data statistics information from the device under test based on a post-hook function, wherein the first data statistics information includes the amount of data sent. The electronic device is specifically used to determine the ratio between the amount of received data in the second data statistics and the amount of sent data in the first data statistics; and to determine whether the performance of the target API passes the test based on the ratio and a set ratio threshold.

[0033] In one possible implementation, the electronic device is further configured to: If the first data statistics obtained from the device under test based on the post-hook function also include: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test; determine the reference outgoing destination port identifier corresponding to the listening destination port identifier according to the pre-configured port conversion correspondence; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

[0034] In one possible implementation, the electronic device is further configured to: Obtain information about preset fields of the target API; generate test cases for the target API based on the information about preset fields; and perform API performance testing based on the test cases, including the step of sending control commands to the device under test to which the target API belongs.

[0035] In one possible implementation, the electronic device is specifically used for: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

[0036] In one possible implementation, the electronic device is specifically used for: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

[0037] In one possible implementation, the test cases may be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

[0038] Fourthly, this application also provides an electronic device, which includes at least a processor and a memory, wherein the processor is configured to execute a computer program stored in the memory to implement the steps of the API performance testing method as described in any of the first aspects.

[0039] Fifthly, embodiments of this application provide a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the steps of the API performance testing method as described in any one of the first aspects.

[0040] Sixthly, embodiments of this application provide a computer program product comprising: computer program code, which, when executed on a computer, causes the computer to perform the steps of the API performance testing method described in any one of the first aspects. Attached Figure Description

[0041] To more clearly illustrate the implementation methods in the embodiments of this application or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings.

[0042] Figure 1 This is a schematic diagram of an API performance testing process provided in an embodiment of this application; Figure 2 This is a schematic diagram illustrating another API performance testing process provided in an embodiment of this application; Figure 3 This is a schematic diagram illustrating another API performance testing process provided in an embodiment of this application; Figure 4 This is a schematic diagram of an API performance testing device provided in an embodiment of this application; Figure 5 This application provides a schematic diagram of an API performance testing system structure. Figure 6 This is a schematic diagram of an electronic device structure provided in an embodiment of this application. Detailed Implementation

[0043] To make the objectives and implementation methods of this application clearer, the exemplary implementation methods of this application will be clearly and completely described below with reference to the accompanying drawings of the exemplary embodiments of this application. Obviously, the exemplary embodiments described are only some embodiments of this application, and not all embodiments.

[0044] It should be noted that the brief descriptions of terms in this application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise stated, these terms should be understood in their ordinary and common meaning.

[0045] The terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar or related objects or entities, and do not necessarily imply a specific order or sequence, unless otherwise specified. It should be understood that such terms are interchangeable where appropriate.

[0046] The terms “comprising” and “having”, and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device that includes a range of components is not necessarily limited to all of the components that are clearly listed, but may include other components that are not clearly listed or that are inherent to such product or device.

[0047] The term "module" refers to any known or subsequently developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.

[0048] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

[0049] For ease of explanation, the above description has been provided in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Various modifications and variations can be obtained based on the above teachings. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, thereby enabling those skilled in the art to better utilize the described embodiments and various different variations of embodiments suitable for specific use considerations.

[0050] This application provides an API performance testing method, apparatus, device, and medium. In this method, an electronic device can send a control command to the device under test (DUT) to which the target API belongs. This control command allows communication between the initiating device and the receiving device via the target API. Simultaneously, based on a first hook function, a communication command can be sent to the initiating device to enable communication between the initiating device and the receiving device via the target API. Then, first data statistics can be obtained from the DUT; these first data statistics represent data sent by the initiating device to the receiving device via the target API. Based on a second hook function, second data statistics can be obtained from the receiving device; these second data statistics represent data received by the receiving device from the initiating device via the target API. Based on the first and second data statistics, the performance of the target API can be determined to have passed the test. Therefore, the purpose of quickly and accurately testing API performance can be achieved.

[0051] Example 1: Figure 1 This application provides a schematic diagram of an API performance testing process, which includes: S101: Send a control command to the device under test to which the target API belongs, so that the device under test performs a corresponding operation according to the control command, wherein the control command is an instruction that allows the initiating device and the receiving device to communicate through the target API.

[0052] The API performance testing method provided in this application is applied to electronic devices, such as personal computers (PCs), mobile terminals, servers, etc., and this application does not specifically limit them.

[0053] In one possible implementation, when it is necessary to test the performance of an API (for ease of description, referred to as the target API), the tester can input the identification information of the target API to be tested into the electronic device and trigger the test instruction by clicking the test button. When the electronic device receives the test instruction for the target API, it can perform the process of testing the performance of the target API.

[0054] To quickly and accurately test API performance, when an electronic device receives a test instruction for a target API, it can automatically and intelligently generate test cases applicable to the target API. Based on these test cases, the performance testing process for the target API can be performed quickly and accurately. Specifically, the electronic device can deploy testing frameworks such as Pytest, unittest, JUnit, or Jest using the Python programming language. Test cases for the target API can be generated based on these frameworks, and the API performance testing process can be executed. For ease of understanding, the API performance testing process of this application embodiment will be explained using the Pytest testing framework as an example. When generating test cases for the target API, information about several preset fields of the target API can be obtained. Then, test cases for the target API can be generated based on this preset field information. These preset fields may include: Method, Uniform Resource Locator (URL), HTTP Headers, and Body (request body or response body), etc., which can be flexibly set according to requirements, and this application does not impose specific limitations on them.

[0055] Since this application can quickly and efficiently generate test cases for the target API by obtaining information from the preset fields of the target API, the performance of the target API can be tested quickly and accurately based on the test cases.

[0056] In one possible implementation, information about the preset fields of the target API can be obtained in the following two ways.

[0057] Method 1: Pull the API documentation of the target API from the device under test to which the target API belongs, and obtain the information of the target API's preset fields from the API documentation.

[0058] Specifically, electronic devices can pull the API documentation of the target API from the platform of the device under test (such as Swagger, YApi, etc.) using an API platform interface, and can obtain information about the preset fields of the target API from the API documentation.

[0059] Method 2: Based on the recorder in the Pytest testing framework, record the API data information of the device under test to which the target API belongs, and obtain the information of the preset fields of the target API based on the data information.

[0060] The process of recording API data from the device under test using a recorder will not be detailed here. The API data recorded by the recorder can be in formats such as HTTP Archive Format (HAR), and this application does not impose any specific limitations on this. This data may contain information about preset fields of each API in the device under test, and based on this, the preset fields of the target API can be obtained from this data.

[0061] Since this application can quickly and efficiently obtain the target API's preset field information by pulling the API documentation of the target API from the device under test, which contains information about the preset fields of the target API, or by recording the API data information of the device under test based on the recorder in the Pytest testing framework, which contains information about the preset fields of the target API, the efficiency of test case generation (creation) can be improved based on the preset field information of the target API.

[0062] In one possible implementation, when the information in the preset fields includes URL field information, the URL field information obtained from the API documentation and API data can be considered as a personalized portion of the URL field information applicable only to the target API. To quickly and efficiently determine the URL field information in test cases, the configuration manager in the Pytest testing framework can be used to obtain the portion of the URL applicable to the global configuration (referred to as the base URL for ease of description). This base URL is applicable to all APIs; that is, it can serve as a shared portion of the URL field information across all API test cases. Then, this base URL applicable to the global configuration and the URL field information from the preset fields of the target API that is only applicable to the target API can be concatenated to obtain the complete URL field information for the target API test cases.

[0063] Since this application can quickly and accurately obtain the base URL applicable to global configuration based on the configuration manager in the Pytest testing framework, the information of the URL field in the test cases of the target API can be obtained quickly and accurately by concatenating the base URL with the information of the URL field in the preset fields of the target API, thereby improving the efficiency and accuracy of test case generation.

[0064] In one possible implementation, to improve the ease of creating (generating) test cases, the test cases can be in a user-friendly format such as YAML (YAML Ain't a Markup Language), JavaScript Object Notation (JSON), or Extensible Markup Language (XML). These formats have concise syntax; for example, YAML can also support comments. Compared to writing complex code, these formats can lower the barrier to creating test cases and improve the efficiency, flexibility, and ease of test case generation.

[0065] Since the test cases in this embodiment can be in YAML, JSON or XML format, these formats have simple syntax and low usage threshold, thereby improving the efficiency, flexibility and convenience of generating test cases.

[0066] In addition, taking YAML format as an example, its test case structure is clear and highly descriptive. It is itself a readable and executable API usage document. Configuring test cases in YAML format can greatly improve the maintainability of test cases and improve the communication efficiency between test teams.

[0067] In one possible implementation, after obtaining test cases for the target API, a performance testing process for the target API can be conducted based on the test rules specified in the test cases. For example, when performing performance testing on the target API, the electronic device can send a control command to the device under test (DUT) to which the target API belongs. This control command may include instructions to allow the initiating device and the receiving device to communicate through the target API. The DUT can then perform corresponding operations according to the control command. For example, it can forward data information sent by the initiating device to the receiving device through the target API, enabling communication between the initiating device and the receiving device through the target API. This application does not specifically limit the specific communication process.

[0068] S102: Based on the first hook function, send a communication instruction to the initiating device to communicate with the receiving device through the target API.

[0069] In one possible implementation, the electronic device can send a communication command to the initiating device via a hook function (referred to as the first hook function for ease of description). This communication command may be an instruction instructing the initiating device to communicate with the receiving device through the target API. This application does not specifically limit the form of the communication command and can flexibly set it according to requirements. After receiving the communication command, the initiating device can send data information (such as data packets) to the device under test to which the target API belongs, according to the instructions of the communication command. This data information may also carry the identifier of the receiving device. After receiving the data information, the device under test can send the data information to the receiving device through the target API.

[0070] S103: Obtain first data statistics from the device under test, wherein the first data statistics are data information sent by the initiating device to the receiving device through the target API; and obtain second data statistics from the receiving device based on the second hook function, wherein the second data statistics are data information received by the receiving device from the initiating device through the target API; and determine whether the performance of the target API passes the test based on the first data statistics and the second data statistics.

[0071] In one possible implementation, considering that the data information sent by the initiating device to the receiving device, as statistically recorded at the device under test, is typically only the data sent by the initiating device to the receiving device through the target API, this data information does not reflect the actual data received by the receiving device. If the performance of the API is judged solely based on the statistical data from the device under test, it cannot accurately reflect the API's performance and has certain limitations. To accurately test the performance of the target API, in addition to obtaining the data information sent by the initiating device to the receiving device through the target API from the device under test (referred to as the first data statistics for ease of description), the electronic device can also obtain the data information received by the receiving device from the initiating device through the target API from the external receiving device via a hook function (referred to as the second hook function for ease of description) (referred to as the second data statistics for ease of description).

[0072] Then, the electronic device can determine whether the target API's performance passes the test based on the assertion rules in the test cases. Specifically, the electronic device can determine whether the target API's performance passes the test based on the first data statistics and the second data statistics.

[0073] In one possible implementation, the first data statistics may include the amount of data sent by the initiating device to the receiving device via the target API (referred to as the amount of data sent for ease of description). For example, it may include the number and size of data packets (data packets sent) sent by the initiating device to the receiving device via the target API. The first data statistics can be obtained from the device under test in two ways.

[0074] The first method: In response to control commands, after the device under test forwards the data information sent by the initiating device to the receiving device through the target API, it can return a response message to the electronic device, which can carry the first data statistics information.

[0075] The second approach: The electronic device can obtain the first data statistics from the device under test based on the post-hook function in the test case. The post-hook function can be flexibly configured according to requirements, and this application does not impose specific limitations on it.

[0076] Meanwhile, the second set of data statistics may include the amount of data received by the receiving device from the initiating device through the target API (referred to as the received data amount for ease of description). Corresponding to the amount of data sent, the received data amount may include the number and size of data packets (received data packets) received by the receiving device from the initiating device through the target API.

[0077] Electronic devices can obtain the ratio between the amount of data received and the amount of data sent by calculating the ratio between the number of data packets received and the number of data packets sent, or by calculating the ratio between the size of the data packets received and the size of the data packets sent. Then, based on the relationship between this ratio and a set ratio threshold, the performance of the target API can be judged to determine whether it passes the test.

[0078] For example, if the ratio of received data to sent data exceeds a certain threshold, the target API's performance can be considered good, and the API's performance can be considered to have passed the test. Conversely, if the ratio of received data to sent data does not exceed the threshold, the target API's performance can be considered poor, and the API's performance can be considered to have failed the test.

[0079] Since this application can determine the ratio between the amount of data received and the amount of data sent, based on this ratio and a set ratio threshold, it can quickly and accurately determine whether the performance of the target API has passed the test, thereby improving the accuracy of API performance testing.

[0080] In one possible implementation, to accurately test the performance of the target API, a post-hook function can be used to obtain the listening destination port identifier of the sending device and the actual outgoing destination port identifier of the data forwarded by the device under test through the target API. That is, the first data statistics information can include not only the amount of data sent, but also the listening destination port identifier of the sending device and the actual outgoing destination port identifier of the data forwarded by the device under test. When determining whether the target API performance passes the test, a baseline outgoing destination port identifier corresponding to the listening target port identifier can be determined based on a pre-configured port conversion correspondence. Then, the performance of the target API can be comprehensively judged based on whether the actual outgoing destination port identifier matches the baseline outgoing destination port identifier, and the relationship between the ratio of received data to sent data and the ratio threshold.

[0081] For example, the target API performance is considered to have passed the test if the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume and the sent data volume exceeds a ratio threshold. Otherwise, if the actual outgoing destination port identifier is inconsistent with the baseline outgoing destination port identifier, or if the ratio between the received data volume and the sent data volume does not exceed the ratio threshold, the target API performance is considered to have failed the test. This application does not specifically limit the listening destination port identifier, the corresponding baseline outgoing destination port identifier, or the actual outgoing destination port identifier; these can be flexibly set according to requirements.

[0082] Since this application can obtain the listening destination port identifier of the sending device sending data and the actual forwarding destination port identifier of the device under test forwarding data, and can determine the reference forwarding destination port identifier corresponding to the listening destination port identifier according to the pre-configured port conversion correspondence, it can then quickly and accurately judge whether the target API performance has passed the test based on whether the actual forwarding destination port identifier is consistent with the reference forwarding destination port identifier and the ratio between the received data volume and the sent data volume, thereby improving the accuracy of API performance testing.

[0083] In this embodiment, the electronic device can send control commands to the device under test (DUT) to which the target API belongs. These control commands allow communication between the initiating device and the receiving device via the target API. Simultaneously, based on a first hook function, a communication command can be sent to the initiating device to enable communication between the initiating device and the receiving device via the target API. Then, first data statistics can be obtained from the DUT, containing data sent from the initiating device to the receiving device via the target API. Based on a second hook function, second data statistics can be obtained from the receiving device, containing data received by the receiving device from the initiating device via the target API. Based on both the first and second data statistics, the performance of the target API can be judged to determine whether it has passed the test. Therefore, the goal of quickly and accurately testing API performance can be achieved.

[0084] Furthermore, this application embodiment can break through the limitations of traditional methods that rely solely on statistical (returned) data information from the tested device to judge API performance based on a unique hook mechanism. This application embodiment can obtain the second data statistics information received by the receiving device from the initiating device through the target API based on the hook function. Based on the first data statistics information sent by the initiating device to the receiving device through the target API and the aforementioned second data statistics information, the complete data forwarding business process can be verified, achieving end-to-end business scenario verification and improving the accuracy of API performance testing.

[0085] Example 2: To improve the security of the testing process, based on the above embodiments, in this embodiment of the application, before sending the control command to the device under test to which the target API belongs, the method further includes: Based on the pre-hook function, a test target API request is sent to the device under test, and the license certificate information for the target API returned by the device under test is received. Sending control commands for the target API to the device under test to which the target API belongs includes: The device under test sends a control command for the target API, wherein the control command carries the license certificate information, so that when the device under test recognizes that the license certificate information is compliant, it performs the corresponding operation according to the control command.

[0086] In one possible implementation, to improve the security of the testing process, before sending control commands to the device under test to which the target API belongs, the electronic device may first send a test target API request to the device under test based on the pre-hook function in the test case. The test API request may contain the identifier of the target API.

[0087] After receiving the target API request, the device under test (DUT) can return license information for the target API to the electronic device. This license information may include the identifier of the target API. Subsequently, when the electronic device sends control commands to the DUT, it can include this license information in the control commands. Upon receiving the control commands, the DUT can first verify the security (compliance) of the license information carried in the control commands. If the verified license information is the same as the license information previously sent by the DUT to the electronic device, then the license information in the control commands is considered compliant, and the corresponding operation can be performed according to the control commands. Otherwise, if the verified license information is not the same as the license information previously sent by the DUT to the electronic device, then the license information in the control commands is considered non-compliant, and the corresponding operation can be disregarded.

[0088] Since this application can send test API requests to the device under test based on the pre-hook function and receive the license certificate information for the target API returned by the device under test, the license certificate information can be carried in the control command when sending control commands to the device under test. The device under test will only perform the corresponding operation according to the control command when it recognizes that the license certificate information is compliant, thereby ensuring the security of the API performance testing process.

[0089] To facilitate understanding, the API performance testing process provided in this application will be explained below through a specific embodiment. See also... Figure 2 The process includes the following steps: S201: Obtain information about the preset fields of the target API; based on the information about the preset fields, generate test cases for the target API, and based on the test cases, conduct subsequent performance testing of the target API.

[0090] S202: Based on the pre-hook function, send a test API request to the device under test and receive the license certificate information for the target API returned by the device under test; send a control instruction carrying the license certificate information to the device under test, so that when the device under test recognizes that the license certificate information is compliant, it shall perform the corresponding operation according to the control instruction, wherein the control instruction is an instruction that allows the initiating device and the receiving device to communicate through the target API.

[0091] S203: Based on the first hook function, send a communication command to the initiating device to communicate with the receiving device through the target API.

[0092] S204: Obtain first data statistics from the device under test, wherein the first data statistics are data information sent by the initiating device to the receiving device through the target API, and obtain second data statistics from the receiving device based on the second hook function, wherein the second data statistics are data information received by the receiving device from the initiating device through the target API; and determine whether the performance of the target API passes the test based on the first data statistics and the second data statistics.

[0093] Example 3: To facilitate understanding, the API performance testing process provided in this application will be explained below through a specific embodiment. (See also...) Figure 3 The process includes the following steps: S301: The electronic device, based on the test case management and generation layer configured in the electronic device, pulls the API document of the target API from the device under test and obtains the information of the preset fields from the API document; or, based on the recorder in the Pytest testing framework, it records the API data information in the device under test, obtains the information of the preset fields of the target API based on the data information, and constructs (generates) test cases for the target API based on the information of these preset fields, wherein the test cases are in YAML format.

[0094] S302: After the Pytest engine in the electronic device starts, it calls the test executor through the pytest_generate_tests hook function. Based on the core execution engine layer configured in the electronic device, it reads the YAML format test cases by calling the YAML parser and parses their contents into the data structures required to execute the test flow. Before executing the test flow, dynamic data in the test cases can be processed based on the placeholder replacements in the electronic device.

[0095] For example, replace (fill) the current time {current_time} field in dynamic data with the current time.

[0096] S303: The electronic device sends a test target API request to the device under test to which the target API belongs by calling the pre-hooks function, based on the hook executor configured in the electronic device.

[0097] S304: The device under test returns license information carrying the identifier of the target API to the electronic device.

[0098] S305: An electronic device sends a control command to the device under test. The control command carries license information for the target API. The control command is an instruction that allows the initiating device to communicate with the receiving device through the target API.

[0099] The control command can be a Hypertext Transfer Protocol (HTTP) or Hypertext Transfer Protocol Secure (HTTPS) request command, and this application does not specifically limit it.

[0100] S306: After receiving the control command, the device under test verifies the compliance of the license information carried in the control command. If the verification is successful, the device can then perform the corresponding operations according to the control command.

[0101] S307: The electronic device sends a communication instruction to the initiating device to communicate with the receiving device through the target API, based on the first hook function.

[0102] S308: After receiving the communication command, the initiating device can send a data packet to the receiving device through the target API's associated device. After receiving the data packet sent by the initiating device, the target device can forward the data packet to the receiving device through the target API.

[0103] S309: The amount of data sent by the device under test to the initiating device (first data statistics information) is fed back by the device under test to the electronic device.

[0104] S310: The electronic device can obtain the listening destination port identifier of the data (data packet) sent by the sending device and the actual outgoing destination port identifier when the device under test forwards the data from the device under test (such as the database of the device under test) based on the post-hooks function.

[0105] S311: The electronic device obtains second data statistics from the receiving device based on the second hook function. The second data statistics include data information received by the receiving device from the initiating device through the target API.

[0106] In this application, the order of steps S310 and S311 is not specifically limited. That is, the electronic device can first obtain the listening destination port identifier of the sending device and the actual outgoing destination port identifier when the device under test forwards the data from the device under test based on the post-hook function, or it can first perform the step of obtaining the second data statistics information from the receiving device based on the second hook function, or it can perform the two steps in parallel.

[0107] S312: The electronic device, based on the response assertion verifier configured in the electronic device, determines the reference outgoing destination port identifier corresponding to the listening destination port identifier according to the pre-configured port conversion correspondence; and judges whether the target API performance passes the test based on whether the actual outgoing destination port identifier is consistent with the reference outgoing destination port identifier and the ratio between the received data volume in the second data statistics information and the sent data volume in the first data statistics information.

[0108] S313: Electronic devices can call the logging module in the electronic device based on the configuration support layer configured in the electronic device. Based on the logging module, detailed execution logs of the entire API performance test process are recorded to facilitate subsequent debugging and problem tracing.

[0109] In addition, electronic devices can call the Allure report generator within the device based on the collaboration and reporting layer configured within the device. Through deep integration with the Allure framework, a detailed and aesthetically pleasing test report can be generated for the entire API performance testing process. The test report can be in Hyper Text Markup Language (HTML) format.

[0110] In addition, electronic devices can send a link to the test report, a core summary of the test report, and test results to the email addresses of pre-defined testers after the performance test of the target API is completed, so that testers can easily view the test report.

[0111] Additionally, electronic devices can use the ZenTao synchronizer to associate test results of the target API with project management tools such as ZenTao. For example, the test status of test cases for the target API in ZenTao can be updated based on the test results. When the test result indicates that the target API's performance has failed the test, a defect / bug alert can be output to prompt testers to investigate and fix the target API.

[0112] This application's embodiments feature an automated testing closed-loop process, from test case generation and API performance testing to test report generation and defect / error alarm notification, comprehensively improving the automation level and efficiency of API testing.

[0113] Example 4: Based on the same technical concept, this application provides an application programming interface (API) performance testing device for use in electronic devices. (See attached document.) Figure 4 The device includes: The first sending module 401 is used to send a control command to the device under test to which the target API belongs, so that the device under test performs a corresponding operation according to the control command. The control command is an instruction that allows the initiating device and the receiving device to communicate through the target API. The second sending module 402 is used to send a communication instruction to the initiating device to communicate with the receiving device through the target API, based on the first hook function; The acquisition module 403 is used to obtain first data statistics from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API, and to obtain second data statistics from the receiving device based on the second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API; The adjudication module 404 is used to determine whether the performance of the target API passes the test based on the first data statistics and the second data statistics.

[0114] In one possible implementation, the first transmitting module 401 is further configured to: Based on the pre-hook function, a test API request is sent to the device under test, and the license certificate information for the target API returned by the device under test is received. A control command carrying the license certificate information is sent to the device under test, so that when the device under test recognizes that the license certificate information is compliant, it performs the corresponding operation according to the control command.

[0115] In one possible implementation, the acquisition module 403 is specifically used for: Receive response information returned by the device under test, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or, Based on the post-hook function, the first data statistics information is obtained from the device under test, and the first data statistics information includes the amount of data sent. Determine the ratio between the amount of data received in the second data statistics and the amount of data sent in the first data statistics; Based on the ratio and the set ratio threshold, the performance of the target API is judged to determine whether it passes the test.

[0116] In one possible implementation, the first data statistics obtained from the device under test based on the post-hook function further includes: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test. The adjudication module 404 is specifically used to: determine the base outgoing destination port identifier corresponding to the monitoring destination port identifier according to the pre-configured port conversion correspondence; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

[0117] In one possible implementation, the device further includes: The test case creation module 405 is used to obtain information about preset fields of the target API; generate test cases for the target API based on the information about preset fields; and perform API performance testing process based on the test cases, including the step of sending control commands to the device under test to which the target API belongs.

[0118] In one possible implementation, the test case creation module 405 is specifically used for: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

[0119] In one possible implementation, the test case creation module 405 is specifically used for: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

[0120] In one possible implementation, the test cases may be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

[0121] Example 5: Based on the same technical concept, this application provides an API performance testing system, see [link / reference]. Figure 5 , Figure 5This application provides a schematic diagram of an API performance testing system, which includes: Electronic device 501 is used to send control commands to the device under test 502 to which the target API to be tested belongs; The device under test 502 is used to receive control commands sent by the electronic device 501 and perform corresponding operations according to the control commands. The control commands are instructions that allow communication between the initiating device 503 and the receiving device 504 through the target API. The electronic device 501 is also configured to send a communication instruction to the initiating device 503, based on the first hook function, to communicate with the receiving device 504 through the target API; The initiating device 503 is configured to perform corresponding operations according to the communication instruction if it receives the communication instruction. The electronic device 501 is further configured to obtain first data statistics from the device under test 502, wherein the first data statistics include data information sent by the initiating device 503 to the receiving device 504 through the target API, and to obtain second data statistics from the receiving device 504 based on a second hook function, wherein the second data statistics include data information received by the receiving device 504 from the initiating device 503 through the target API; The electronic device 501 is also used to determine whether the performance of the target API passes the test based on the first data statistics and the second data statistics.

[0122] In one possible implementation, the electronic device 501 is further configured to send a test target API request to the device under test 502 based on a pre-hook function. The device under test 502 is also used to return license information for the target API to the electronic device 501; The electronic device 501 is specifically used to send control commands carrying the license certificate information to the device under test 502; The device under test 502 is specifically used to perform corresponding operations according to the control instructions when the license certificate information is found to be compliant.

[0123] In one possible implementation, the device under test 502 is specifically configured to return response information to the electronic device 501, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or... The electronic device 501 is specifically used to obtain the first data statistics information from the device under test 502 based on the post-hook function, wherein the first data statistics information includes the amount of data sent. The electronic device 501 is specifically used to determine the ratio between the amount of received data in the second data statistics and the amount of sent data in the first data statistics; and to determine whether the performance of the target API passes the test based on the ratio and a set ratio threshold.

[0124] In one possible implementation, the electronic device 501 is further configured to: If the first data statistics obtained from the device under test based on the post-hook function also include: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test; determine the reference outgoing destination port identifier corresponding to the listening destination port identifier according to the pre-configured port conversion correspondence; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

[0125] In one possible implementation, the electronic device 501 is further configured to: Obtain information about preset fields of the target API; generate test cases for the target API based on the information about preset fields; and perform API performance testing based on the test cases, including the step of sending control commands to the device under test to which the target API belongs.

[0126] In one possible implementation, the electronic device 501 is specifically used for: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

[0127] In one possible implementation, the electronic device 501 is specifically used for: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

[0128] In one possible implementation, the test cases may be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

[0129] Example 6: Based on the same technical concept, this application also provides an electronic device. Figure 6 This application provides a schematic diagram of an electronic device structure, such as... Figure 6 As shown, it includes: processor 601, communication interface 602, memory 603 and communication bus 604, wherein processor 601, communication interface 602 and memory 603 communicate with each other through communication bus 604. The memory 603 stores a computer program, which, when executed by the processor 601, causes the processor 601 to perform the following steps: Send a control command to the device under test to which the target API belongs, so that the device under test performs a corresponding operation according to the control command, wherein the control command is an instruction that allows the initiating device and the receiving device to communicate through the target API; Based on the first hook function, a communication instruction is sent to the initiating device to communicate with the receiving device through the target API; First data statistics are obtained from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API; and second data statistics are obtained from the receiving device based on the second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API. Based on the first and second data statistics, a judgment is made as to whether the performance of the target API passes the test.

[0130] In one possible implementation, the processor 601 is further configured to: Based on the pre-hook function, a test API request is sent to the device under test, and the license certificate information for the target API returned by the device under test is received. A control command carrying the license certificate information is sent to the device under test, so that when the device under test recognizes that the license certificate information is compliant, it performs the corresponding operation according to the control command.

[0131] In one possible implementation, the processor 601 is specifically used for: Receive response information returned by the device under test, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or, Based on the post-hook function, the first data statistics information is obtained from the device under test, and the first data statistics information includes the amount of data sent. Determine the ratio between the amount of data received in the second data statistics and the amount of data sent in the first data statistics; Based on the ratio and the set ratio threshold, the performance of the target API is judged to determine whether it passes the test.

[0132] In one possible implementation, if the first data statistics obtained from the device under test based on the post-hook function further includes: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test; the processor 601 is specifically used for: Based on the pre-configured port translation correspondence, determine the base outgoing destination port identifier corresponding to the listening destination port identifier; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

[0133] In one possible implementation, the processor 601 is further configured to: Obtain information about preset fields of the target API; generate test cases for the target API based on the information about preset fields; and perform API performance testing based on the test cases, including the step of sending control commands to the device under test to which the target API belongs.

[0134] In one possible implementation, the processor 601 is specifically used for: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

[0135] In one possible implementation, the processor 601 is specifically used for: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

[0136] In one possible implementation, the test cases may be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

[0137] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.

[0138] The communication interface 602 is used for communication between the above-mentioned electronic device and other devices.

[0139] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0140] The processors mentioned above can be general-purpose processors, including central processing units, network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits, field-programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0141] Example 7: Based on the same technical concept, embodiments of this application provide a computer-readable storage medium storing a computer program executable by an electronic device. When the program is run on the electronic device, the electronic device performs the following steps: Send a control command to the device under test to which the target API belongs, so that the device under test performs a corresponding operation according to the control command, wherein the control command is an instruction that allows the initiating device and the receiving device to communicate through the target API; Based on the first hook function, a communication instruction is sent to the initiating device to communicate with the receiving device through the target API; First data statistics are obtained from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API; and second data statistics are obtained from the receiving device based on the second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API. Based on the first and second data statistics, a judgment is made as to whether the performance of the target API passes the test.

[0142] In one possible implementation, before sending control commands to the device under test (DUT) to which the target API belongs, the method further includes: Based on the pre-hook function, a test target API request is sent to the device under test, and the license certificate information for the target API returned by the device under test is received. Sending control commands to the device under test to which the target API belongs includes: A control command carrying the license certificate information is sent to the device under test, so that when the device under test recognizes that the license certificate information is compliant, it performs the corresponding operation according to the control command.

[0143] In one possible implementation, obtaining the first data statistics from the device under test includes: Receive response information returned by the device under test, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or, Based on the post-hook function, the first data statistics information is obtained from the device under test, and the first data statistics information includes the amount of data sent. The step of determining whether the target API performance passes the test based on the first and second data statistics includes: Determine the ratio between the amount of data received in the second data statistics and the amount of data sent in the first data statistics; Based on the ratio and the set ratio threshold, the performance of the target API is judged to determine whether it passes the test.

[0144] In one possible implementation, the first data statistics obtained from the device under test based on the post-hook function further includes: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test. Based on the first and second data statistics, a judgment is made on whether the performance of the target API passes the test, including: Based on the pre-configured port translation correspondence, determine the base outgoing destination port identifier corresponding to the listening destination port identifier; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

[0145] In one possible implementation, before sending control commands to the device under test (DUT) to which the target API belongs, the method further includes: Obtain information about preset fields of the target API; generate test cases for the target API based on the information about preset fields; and perform API performance testing based on the test cases, including the step of sending control commands to the device under test to which the target API belongs.

[0146] In one possible implementation, obtaining information about a preset field of the target API includes: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

[0147] In one possible implementation, if the information in the preset field includes information from the Uniform Resource Locator (URL) field, information from the URL field in the test cases of the target API is generated based on the information from the preset field, including: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

[0148] In one possible implementation, the test cases may be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

[0149] The aforementioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in an electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), optical storage such as CDs, DVDs, BDs, HVDs, etc., and semiconductor storage such as ROMs, EPROMs, EEPROMs, non-volatile memory (NAND flash), solid-state drives (SSDs), etc.

[0150] Based on the same technical concept, this application also provides a computer program product, which includes computer program code. When the computer program code is run on a computer, it causes the computer to execute any of the above embodiments. Since the principle by which the above computer program product solves the problem is similar to that of the above method, the implementation of the above computer program product can refer to the implementation of the method, and repeated details will not be described again.

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

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

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

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

[0155] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. A method for testing the performance of an application programming interface (API), characterized in that, Applied to electronic devices, the method includes: Send a control command to the device under test to which the target API belongs, so that the device under test performs a corresponding operation according to the control command, wherein the control command is an instruction that allows the initiating device and the receiving device to communicate through the target API; Based on the first hook function, a communication instruction is sent to the initiating device to communicate with the receiving device through the target API; First data statistics are obtained from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API; and second data statistics are obtained from the receiving device based on the second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API. Based on the first and second data statistics, a judgment is made as to whether the performance of the target API passes the test.

2. The method according to claim 1, characterized in that, Before sending control commands to the device under test to which the target API belongs, the method further includes: Based on the pre-hook function, a test target API request is sent to the device under test, and the license certificate information for the target API returned by the device under test is received. Sending control commands to the device under test to which the target API belongs includes: A control command carrying the license certificate information is sent to the device under test, so that when the device under test recognizes that the license certificate information is compliant, it performs the corresponding operation according to the control command.

3. The method according to claim 1, characterized in that, The first data statistics information obtained from the device under test includes: Receive response information returned by the device under test, wherein the response information carries the first data statistics information, and the first data statistics information includes the amount of data sent; or, Based on the post-hook function, the first data statistics information is obtained from the device under test, and the first data statistics information includes the amount of data sent. The step of determining whether the target API performance passes the test based on the first and second data statistics includes: Determine the ratio between the amount of data received in the second data statistics and the amount of data sent in the first data statistics; Based on the ratio and the set ratio threshold, the performance of the target API is judged to determine whether it passes the test.

4. The method according to claim 3, characterized in that, The first data statistics information obtained from the device under test based on the post-hook function also includes: the listening destination port identifier of the data sent by the sending device, and the actual outgoing destination port identifier of the data forwarded by the device under test; Based on the first and second data statistics, the performance of the target API is judged to determine whether it passes the test, including: Based on the pre-configured port translation correspondence, determine the base outgoing destination port identifier corresponding to the listening destination port identifier; The performance of the target API is judged based on whether the actual outgoing destination port identifier is consistent with the baseline outgoing destination port identifier, and the ratio between the received data volume in the second data statistics and the sent data volume in the first data statistics.

5. The method according to any one of claims 1-4, characterized in that, Before sending control commands to the device under test to which the target API belongs, the method further includes: Obtain information about preset fields of the target API; generate test cases for the target API based on the information about preset fields; and perform API performance testing based on the test cases, including the step of sending control commands to the device under test to which the target API belongs.

6. The method according to claim 5, characterized in that, The step of obtaining information from preset fields of the target API includes: Retrieve the API documentation of the target API from the device under test; obtain information about preset fields from the API documentation; or, The Pytest testing framework uses a recorder to capture data from the API of the device under test, and then uses this data to obtain information about preset fields of the target API.

7. The method according to claim 5, characterized in that, If the information in the preset fields includes information in the Uniform Resource Locator (URL) field, based on the information in the preset fields, generate the URL field information in the test cases for the target API, including: Based on the configuration manager in the Pytest testing framework, obtain the base URL applicable to the global configuration; concatenate the base URL with the information in the URL field of the preset fields to obtain the information in the URL field of the test case.

8. The method according to claim 5, characterized in that, The test cases can be in the following formats: YAML, JavaScript Object Notation (JSON), or Extensible Markup Language (XML).

9. An application programming interface (API) performance testing device, characterized in that, Applied to electronic devices, the device includes: The first sending module is used to send control instructions to the device under test to which the target API belongs, so that the device under test performs corresponding operations according to the control instructions. The control instructions are instructions that allow the initiating device and the receiving device to communicate through the target API. The second sending module is used to send a communication instruction to the initiating device to communicate with the receiving device through the target API, based on the first hook function; The acquisition module is used to obtain first data statistics from the device under test, wherein the first data statistics include data information sent by the initiating device to the receiving device through the target API, and to obtain second data statistics from the receiving device based on the second hook function, wherein the second data statistics include data information received by the receiving device from the initiating device through the target API; The adjudication module is used to determine whether the performance of the target API passes the test based on the first data statistics and the second data statistics.

10. An electronic device, characterized in that, include: Memory, used to store program instructions; A processor is configured to invoke program instructions stored in the memory and execute the steps of the method according to any one of claims 1-8.