Interface testing method and device, electronic equipment, storage medium and program product
By obtaining task data in the task queue and generating interface call requests or performing assertion operations based on the task type, the problem of high resource consumption and inability to accurately obtain request responses in the existing asynchronous interface testing methods is solved, and efficient and accurate asynchronous interface testing is achieved.
Patent Information
- Application Number
- CN202411883513.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-04-15
AI Technical Summary
In the existing asynchronous interface testing methods, the resource consumption is high, the inability to perceive the end of a stateless task, and the inability to accurately obtain the request response of the asynchronous interface, affecting the completeness and accuracy of the test.
By obtaining the task data of the task to be executed in the task queue, determining the task as an asynchronous interface test task or a callback request processing task according to the task type, generating an interface call request or obtaining an expected response for assertion operations, verifying the correctness of the response data returned by the tested service.
It avoids resource consumption caused by long polling, improves the system performance and testing efficiency of asynchronous interface testing, realizes effective monitoring of all tasks (including stateless tasks), and improves the integrity and accuracy of asynchronous interface testing.
Smart Images

Figure CN119829436A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an interface testing method, device, electronic equipment, storage medium and program product. Background Art
[0002] In existing interface testing methods, the tested interface is usually asynchronous, that is, the result is not returned immediately after sending the test request. Existing asynchronous interface testing methods mainly use long polling (while true) to wait for the end of the asynchronous operation. Its working principle and method are as follows: (1) Sending asynchronous requests: The test system sends asynchronous requests to the service under test; (2) Long polling wait: The test system enters a long polling loop, continuously querying the status of the database or other middleware to determine whether the asynchronous operation has ended; (3) Determine the end of the asynchronous operation: Determine the completion of the asynchronous operation by querying the status of the database or middleware; (4) Assertion execution: By obtaining the values from the database and middleware, the correctness of the interface execution logic is verified.
[0003] The existing long polling method has the following defects: (1) High resource consumption: frequent access to databases or middleware is required, resulting in high system resource consumption, low efficiency, and poor overall performance. (2) Unable to perceive the end of stateless tasks: The method of relying on the middleware status to judge the end of asynchronous operations. For tasks without middleware status, the end of asynchronous operations cannot be perceived, resulting in the inability to complete the test; (3) Due to the complexity of asynchronous operations, existing technologies cannot accurately obtain the request responses of asynchronous interfaces, which affects the accuracy of the test. Summary of the invention
[0004] The present invention provides an interface testing method, device, electronic device, storage medium and program product, which are used to solve the defects of asynchronous interface testing in the prior art, such as large resource consumption, inability to perceive the end of stateless tasks and inability to accurately obtain the request response of the asynchronous interface, which affects the integrity and accuracy of the test, and improve the test efficiency, accuracy and integrity of the asynchronous interface test.
[0005] The present invention provides an interface testing method, comprising the following steps: obtaining task data of a task to be executed in a task queue; wherein, for an asynchronous interface testing task, the task data comprises an asynchronous interface testing task unique identifier, test case parameters, a callback address and a task type; for a callback request processing task, the task data comprises a callback request processing task unique identifier, the asynchronous interface testing task unique identifier of the corresponding asynchronous interface testing task, callback request parameters, response data and a task type; in response to determining that the task to be executed is the asynchronous interface testing task according to the task type, An interface call request is generated based on the test case parameters and the callback address, and the interface call request is sent to the service under test; in response to determining that the task to be executed is a callback request processing task according to the task type, based on the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, the test case parameters corresponding to the asynchronous interface test task unique identifier are obtained by querying the task data pre-stored in the database, an expected response is obtained based on the test case parameters, an assertion operation is performed based on the expected response and the response data of the callback request processing task, and the correctness of the response data returned by the service under test is verified.
[0006] According to an interface testing method provided by the present invention, before generating an interface call request according to the asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task, the method also includes: obtaining a prefix code segment based on the test case parameters, and performing data preparation or environment configuration by executing the prefix code segment; and / or, obtaining variable initialization information based on the test case parameters, and initializing variables in a variable pool according to the variable initialization information.
[0007] According to an interface testing method provided by the present invention, the method also includes: generating interface testing context data and storing it in a database according to the execution process of the front-end code segment and the generation process of the interface call request; wherein the interface testing context data includes an interface testing context data unique identifier, the asynchronous interface testing task unique identifier and context object data.
[0008] According to an interface testing method provided by the present invention, in response to determining that the task to be executed is a callback request processing task according to the task type, the method also includes: obtaining the corresponding interface test context data according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, and obtaining the corresponding context object data by querying the interface test context data; performing data processing or verifying the correctness of the callback request parameters according to the context object data.
[0009] According to an interface testing method provided by the present invention, in the interface testing context data, the asynchronous interface testing task unique identifier is included in the interface testing context data unique identifier.
[0010] According to an interface testing method provided by the present invention, in the task data of the asynchronous interface testing task, the unique identifier of the asynchronous interface testing task is spliced into the callback address; and / or, in the callback request processing task, the unique identifier of the asynchronous interface testing task is included in the unique identifier of the callback request processing task.
[0011] According to an interface testing method provided by the present invention, the task data of the task to be executed is generated based on the currently input test case parameters and stored in the database and added to the task queue after the client responds to the trigger operation of the use case execution.
[0012] According to an interface testing method provided by the present invention, the task data of the callback request processing task is generated by the client after receiving the callback request of the tested service and added to the task queue.
[0013] The present invention also provides an asynchronous interface testing device, comprising the following modules: an acquisition module, used to: acquire task data of tasks to be executed in a task queue; wherein, for an asynchronous interface testing task, the task data includes a unique identifier of the asynchronous interface testing task, test case parameters, a callback address and a task type; for a callback request processing task, the task data includes a unique identifier of the callback request processing task, the unique identifier of the asynchronous interface testing task of the corresponding asynchronous interface testing task, callback request parameters, response data and task type; an asynchronous interface testing task execution module, used to: in response to determining that the task to be executed is the asynchronous interface testing task according to the task type, execute the asynchronous interface testing task according to the unique identifier of the asynchronous interface testing task. An identifier, the test case parameters and the callback address generate an interface call request, and send the interface call request to the service under test; a callback request processing task execution module is used to: in response to determining that the task to be executed is a callback request processing task according to the task type, according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, obtain the test case parameters corresponding to the asynchronous interface test task unique identifier by querying the task data pre-stored in the database, obtain the expected response according to the test case parameters, perform an assertion operation according to the expected response and the response data of the callback request processing task, and verify the correctness of the response data returned by the service under test.
[0014] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned interface testing methods when executing the computer program.
[0015] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the interface testing method described in any one of the above methods is implemented.
[0016] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the interface testing method described above is implemented.
[0017] The interface testing method, device, electronic device, storage medium and program product provided by the present invention obtain task data of a task to be executed in a task queue, in response to determining that the task to be executed is an asynchronous interface testing task according to the task type, an interface call request is generated according to the asynchronous interface testing task unique identifier, test case parameters and callback address of the asynchronous interface testing task, and the interface call request is sent to the service under test, in response to determining that the task to be executed is a callback request processing task according to the task type, the asynchronous interface testing task unique identifier of the asynchronous interface testing task corresponding to the callback request processing task is obtained by querying task data pre-stored in a database, an expected response is obtained according to the test case parameters, an assertion operation is performed according to the expected response and the response data of the callback request processing task, and the correctness of the response data returned by the service under test is verified, thereby avoiding resource consumption caused by long polling, improving the system performance and test efficiency of the asynchronous interface test, and realizing effective monitoring of all tasks (including stateless tasks) without obtaining data from the middleware, thereby improving the integrity of the asynchronous interface test, ensuring that the request response of the asynchronous interface can be accurately obtained, and improving the accuracy of the asynchronous interface test. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 This is one of the flow charts of the interface testing method provided by the present invention.
[0020] Figure 2 This is one of the schematic diagrams of the generation process of task data in the interface testing method provided by the present invention.
[0021] Figure 3 This is the second schematic diagram of the generation process of task data in the interface testing method provided by the present invention.
[0022] Figure 4 This is the second processing flow diagram of the interface testing method provided by the present invention.
[0023] Figure 5 It is a structural schematic diagram of the asynchronous interface testing device provided by the present invention.
[0024] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] Figure 1 It is one of the flow charts of the interface testing method provided by the present invention, such as Figure 1 As shown, the method includes the following: Step S1, obtain the task data of the tasks to be executed in the task queue; wherein, for the asynchronous interface test task, the task data includes the asynchronous interface test task unique identifier, test case parameters, callback address and task type; for the callback request processing task, the task data includes the callback request processing task unique identifier, the asynchronous interface test task unique identifier of the corresponding asynchronous interface test task, callback request parameters, response data and task type.
[0027] The interface testing method provided by the present invention is applied to a server. The server can obtain the task data of the tasks to be executed in the task queue by monitoring the task queue. Among them, the task queue can be a Redis queue. The monitoring operation can be implemented through the subscription / publishing mechanism of Redis to ensure that the tasks can be acquired and processed in time. The tasks to be executed in the task queue include asynchronous interface test tasks or callback request processing tasks. The asynchronous interface test task is used to execute the interface call of the tested service to perform the asynchronous interface test. The callback request processing task is generated based on the callback request of the tested service, and is used to verify the result of the asynchronous interface test, thereby completing the asynchronous interface test. If it is an asynchronous interface test task, the asynchronous interface test task processing is performed. If it is a callback request processing task, the callback request processing task processing is performed. The judgment of the task type can be implemented by checking the task type field in the task data to ensure that different types of tasks can be correctly classified and processed.
[0028] For asynchronous interface test tasks, task data includes asynchronous interface test task unique identifier, test case parameters, callback address and task type. Among them, the asynchronous interface test task unique identifier is used to uniquely identify the asynchronous interface test task. The asynchronous interface test task unique identifier will be used to track and associate asynchronous interface test requests and their callbacks to ensure that the status and results of each request can be accurately recorded and processed. Test case parameters include request method (GET, POST, etc.), request header, request body, expected response and other data. The callback address (callbackUrl) is used to receive the callback request returned by the service under test. For example, it is represented as http: / / test.com / callback. The task type indicates the type of task to be executed. For example, 0 can be used to indicate that the task type is an asynchronous interface test task.
[0029] For the callback request processing task, the task data includes the callback request processing task unique identifier, the asynchronous interface test task unique identifier of the corresponding asynchronous interface test task, the callback request parameters, the response data and the task type. Among them, the callback request processing task unique identifier is used to uniquely identify the callback request processing task. Since the callback request is generated based on the asynchronous interface test task, the callback request processing task has a one-to-one correspondence with the asynchronous interface test task. The task data in the callback request processing task includes the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task. According to the asynchronous interface test task unique identifier, it can be known which asynchronous interface test task the callback request processing task is based on or responds to. The callback request parameters are the parameters of the callback request sent by the tested service, and the callback request parameters can be pre-set, such as pre-set variables. The response data is the response data generated by executing the interface method after the interface of the tested service is called. The task type indicates the type of task to be executed, such as 1 can be used to indicate that the task type is a callback request processing task.
[0030] Step S2, in response to determining that the task to be executed is the asynchronous interface test task according to the task type, generate an interface call request according to the asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task, and send the interface call request to the service under test.
[0031] If the task to be executed is determined to be an asynchronous interface test task according to the task type, an interface call request is generated according to the asynchronous interface test task unique identifier, test case parameters and callback address of the asynchronous interface test task, and the interface call request is sent to the service under test. The interface call request includes the information of the asynchronous interface test task unique identifier, test case parameters and callback address of the asynchronous interface test task.
[0032] You can use Python's requests module to send an interface call HTTP request to the service under test. The requests module provides a simple API for building and sending HTTP requests and processing response data. The construction of the request includes setting the request method, request header, request body, etc. to ensure that the request can be sent correctly according to the user's configuration.
[0033] Step S3, in response to determining that the task to be executed is a callback request processing task according to the task type, according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, obtain the test case parameters corresponding to the asynchronous interface test task unique identifier by querying the task data pre-stored in the database, obtain the expected response according to the test case parameters, perform an assertion operation according to the expected response and the response data of the callback request processing task, and verify the correctness of the response data returned by the service under test.
[0034] After the asynchronous interface test task in the task queue is executed, it can be deleted from the task queue. However, when executing the corresponding callback request processing task later, the test case parameters of the asynchronous interface test task need to be obtained. In order to ensure the reliability of data query, the task data of the asynchronous interface test task is not only stored in the task queue, but also in the database, such as the Redis database, and the RedisKey can be set as the unique identifier of the asynchronous interface test task. Of course, the task data of the callback request processing task can also be stored in the redis database, and the RedisKey can be set as the unique identifier of the callback request processing task.
[0035] If the task to be executed is determined to be a callback request processing task according to the task type, then the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task is obtained by querying the task data pre-stored in the database to obtain the test case parameters corresponding to the asynchronous interface test task unique identifier, and the expected response is obtained according to the test case parameters. The assertion operation is performed according to the expected response and the response data of the callback request processing task to verify the correctness of the response data returned by the service under test. For example, the response data is compared with the expected response to see if they are consistent. If they are consistent, it means that the response data sent by the service under test is correct; if they are inconsistent, it means that the response data sent by the service under test is wrong.
[0036] The interface testing method provided by the present invention obtains task data of tasks to be executed in a task queue, responds to determining that the task to be executed is an asynchronous interface testing task according to the task type, generates an interface calling request according to the asynchronous interface testing task unique identifier, test case parameters and callback address of the asynchronous interface testing task, and sends the interface calling request to the tested service, responds to determining that the task to be executed is a callback request processing task according to the task type, processes the asynchronous interface testing task unique identifier of the asynchronous interface testing task corresponding to the callback request processing task, obtains test case parameters corresponding to the asynchronous interface testing task unique identifier by querying task data pre-stored in a database, obtains an expected response according to the test case parameters, performs an assertion operation according to the expected response and the response data of the callback request processing task, verifies the correctness of the response data returned by the tested service, avoids resource consumption caused by long polling, improves the system performance and testing efficiency of the asynchronous interface testing, does not need to obtain data from the middleware, can realize effective monitoring of all tasks (including stateless tasks), improves the integrity of the asynchronous interface testing, ensures that the request response of the asynchronous interface can be accurately obtained, and improves the accuracy of the asynchronous interface testing.
[0037] According to an interface testing method provided by the present invention, before generating an interface call request according to the asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task, the method also includes: obtaining a prefix code segment based on the test case parameters, and performing data preparation or environment configuration by executing the prefix code segment; and / or, obtaining variable initialization information based on the test case parameters, and initializing variables in a variable pool according to the variable initialization information.
[0038] Before generating an interface call request based on the asynchronous interface test task unique identifier, test case parameters, and callback address of the asynchronous interface test task, perform pre-operations, such as executing a user-configured pre-code block, or initializing variables in the variable pool. The pre-code block can be obtained based on test case parameters, the pre-code block can be executed based on a user-defined script, or can be executed by calling a third-party interface. The execution of the pre-code block is used to prepare data or configure the environment before sending the interface call request. Data preparation, such as building an interface call request according to the specifications set in the pre-code block. The variable pool is used to store and manage variables used in the test process to ensure that variables can be shared and passed between different steps.
[0039] The interface testing method provided by the present invention improves the reliability of asynchronous interface testing by obtaining a front-end code segment based on test case parameters, performing data preparation or environment configuration by executing the front-end code segment, and / or obtaining variable initialization information based on test case parameters, and initializing variables in a variable pool according to the variable initialization information.
[0040] According to an interface testing method provided by the present invention, the method also includes: generating interface testing context data and storing it in a database according to the execution process of the front-end code segment and the generation process of the interface call request; wherein the interface testing context data includes an interface testing context data unique identifier, the asynchronous interface testing task unique identifier and context object data.
[0041] According to the execution process of the pre-code segment and the generation process of the interface call request, the interface test context data is generated and stored in the database. Among them, the interface test context data includes the interface test context data unique identifier, the asynchronous interface test task unique identifier, the context object data and the test case execution status. Among them, the interface test context data unique identifier is used to uniquely identify the interface test context data. The interface test context data corresponds to the asynchronous interface test task, and the asynchronous interface test task unique identifier in the interface test context data is the asynchronous interface test task unique identifier of the corresponding asynchronous interface test task.
[0042] The context object data is the data of the specific context object, which may include request parameters, response data, variable pool data, etc., to ensure that the execution environment can be restored during asynchronous callback. Among them, since it is an asynchronous interface call, the response data of the context object is not the final processing result of the interface call, for example, it can be the confirmation information sent by the tested service after receiving the interface call request. The context object data can be serialized and stored in a database, such as serialized and stored in a Redis database. Deserialization processing is required when reading the context object.
[0043] After the interface test context data is generated, since the processing result of the interface asynchronous call has not been returned, the test case execution status is set to waiting for asynchronous callback. The test case execution status can be used as a field in the interface test context data or stored separately.
[0044] The interface testing method provided by the present invention generates interface testing context data and stores it in a database according to the execution process of the front-end code segment and the generation process of the interface call request. The interface testing context data includes a unique identifier of the interface testing context data, a unique identifier of the asynchronous interface testing task, context object data and a test case execution status. The test case execution status is set to waiting for asynchronous callback, laying a foundation for realizing comprehensive testing of asynchronous interfaces.
[0045] According to an interface testing method provided by the present invention, in response to determining that the task to be executed is a callback request processing task according to the task type, the method also includes: obtaining the corresponding interface test context data according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, and obtaining the corresponding context object data by querying the interface test context data; performing data processing or verifying the correctness of the callback request parameters according to the context object data.
[0046] If the task to be executed is determined to be a callback request processing task based on the task type, the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task is used, and the test case parameters corresponding to the unique identifier of the asynchronous interface test task are obtained by querying the task data pre-stored in the database. The expected response is obtained according to the test case parameters, and the assertion operation is performed according to the expected response and the response data of the callback request processing task to verify the correctness of the response data returned by the service under test.
[0047] In addition, in asynchronous interface testing, after receiving the response data returned by the service under test, you may need to verify other information, such as whether the asynchronous request parameters are certain variable values. In this case, you need to verify based on the context object data. Alternatively, you may need to further perform preset data processing operations based on the response data returned by the service under test based on the execution environment after issuing the interface test request.
[0048] Therefore, if the task to be executed is determined to be a callback request processing task according to the task type, the corresponding interface test context data is obtained according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, and the corresponding context object data is obtained by querying the interface test context data, and data processing is performed or the correctness of the callback request parameters is verified according to the context object data. After the processing is completed, the test case execution status is set to execution completed. The acquisition of the context object is implemented through the Redis get operation to ensure that the execution environment can be accurately restored.
[0049] The interface testing method provided by the present invention obtains corresponding interface testing context data by processing the asynchronous interface testing task unique identifier of the asynchronous interface testing task corresponding to the callback request processing task, obtains corresponding context object data by querying the interface testing context data, performs data processing or verifies the correctness of callback request parameters according to the context object data, sets the test case execution status to execution completion, and improves the comprehensiveness of the asynchronous interface testing.
[0050] According to an interface testing method provided by the present invention, in the interface testing context data, the asynchronous interface testing task unique identifier is included in the interface testing context data unique identifier.
[0051] The interface test context data includes information of the interface test context data unique identifier and the asynchronous interface test task unique identifier. Among them, the asynchronous interface test task unique identifier can be included in the interface test context data unique identifier to facilitate the rapid acquisition of information and clarify the correlation between data. The interface test context data unique identifier can be obtained by appending a first string on the basis of the asynchronous interface test task unique identifier, such as expressed as {asynchronous interface test task unique identifier}_context. In this way, the asynchronous interface test task unique identifier and the interface test context data unique identifier can be represented by one field, which is also conducive to saving storage space. When the interface test context data is stored in the Redis database, the interface test context data unique identifier can be used as the RedisKey.
[0052] The interface testing method provided by the present invention includes the unique identifier of the asynchronous interface testing task in the interface testing context data into the unique identifier of the interface testing context data, thereby facilitating the rapid acquisition of information, clarifying the correlation between data, and helping to save storage space.
[0053] According to an interface testing method provided by the present invention, in the task data of the asynchronous interface testing task, the unique identifier of the asynchronous interface testing task is spliced into the callback address; and / or, in the callback request processing task, the unique identifier of the asynchronous interface testing task is included in the unique identifier of the callback request processing task.
[0054] In the task data of the asynchronous interface test task, the unique identifier of the asynchronous interface test task can be spliced into the callback address. In this way, the unique identifier of the asynchronous interface test task can be obtained based on the callback address at the same time, which saves information transmission and facilitates information acquisition. For example, the callback address can be expressed as: http: / / test.com / callback?debugId={unique identifier of the asynchronous interface test task}.
[0055] In addition, the callback request processing task includes information about the callback request processing task unique identifier and the asynchronous interface test task unique identifier, and the asynchronous interface test task unique identifier can be included in the callback request processing task unique identifier. For example, the callback request processing task unique identifier can be obtained by appending a second string on the basis of the asynchronous interface test task unique identifier, such as {asynchronous interface test task unique identifier}_sync. In this way, the callback request processing task unique identifier and the asynchronous interface test task unique identifier can be represented by one field, which is also conducive to saving storage space.
[0056] The interface testing method provided by the present invention facilitates the rapid acquisition of information, clarifies the correlation between data, and is beneficial to saving storage space and improving data transmission performance.
[0057] According to an interface testing method provided by the present invention, the task data of the task to be executed is generated based on the currently input test case parameters and stored in the database and added to the task queue after the client responds to the trigger operation of the use case execution.
[0058] The user can edit the test case parameters on the client side and trigger the execution of the test case by clicking the test case execution button. After receiving the trigger operation of the test case execution, the client will generate the task data of the task to be executed, save it in the database and add it to the task queue.
[0059] The following is an example of the client's processing process: Asynchronous interface test trigger: The user writes the test case parameters on the platform interface, sets it as an asynchronous request case, and configures callbackUrl (callback address) to the request parameters of the case. The domain name and request path of callbackUrl are the addresses where the test system receives callbacks, such as http: / / test.com / callback. The user can enter the test case parameters through a graphical interface or script, which include but are not limited to request method (GET, POST, etc.), request header, request body, expected response, etc.
[0060] Generate a unique ID (asynchronous interface test task unique ID): When the user clicks the use case execution button, the client's web module generates an asynchronous interface test task unique ID for each asynchronous interface test task. The asynchronous interface test task unique ID can be generated by the UUID algorithm to ensure its global uniqueness; the generated asynchronous interface test task unique ID will be used to track and associate asynchronous requests and their callbacks to ensure that the status and results of each request can be accurately recorded and processed.
[0061] Automatic completion of callbackUrl unique ID: The web module uses the generated asynchronous interface test task unique ID as a parameter and automatically splices it into callbackUrl. The completed callbackUrl is http: / / test.com / callback?debugId={asynchronous interface test task unique ID}.
[0062] Storing use case parameter information: The web module assembles the use case parameter information and callbackUrl into package data, stores it in Redis, and marks the task type as "asynchronous interface test task", using the unique identifier of the asynchronous interface test task as the RedisKey; the stored information includes request parameters, request header, request body, expected response, unique identifier of the asynchronous interface test task, etc. As a high-performance in-memory database, Redis can quickly access this information to ensure efficient operation of the system.
[0063] Add to task queue: Add the package data composed of the use case parameter information and callbackUrl to the Redis task queue. The Redis task queue is used to manage and schedule tasks to be executed to ensure that tasks can be processed in order; the package data format can be JSON or other serialized formats to ensure that data is not lost during transmission and storage.
[0064] The interface testing method provided by the present invention generates and stores test case parameters based on the current input in a database and adds them to a task queue after the client responds to the trigger operation of the use case execution, which facilitates the user to perform relevant configuration for asynchronous interface testing and improves the convenience of interface testing.
[0065] According to an interface testing method provided by the present invention, the task data of the callback request processing task is generated by the client after receiving the callback request of the tested service and added to the task queue.
[0066] The task data of the callback request processing task may be generated by the client after receiving the callback request of the service under test and added to the task queue.
[0067] The following is an example of the client's processing process: Receive callback request (callback request): After the asynchronous operation of the service under test is executed, it actively requests the client's web module through HTTP with the unique identifier of the asynchronous interface test task; the web module can receive the callback request from the service under test by listening to a specific HTTP port and path. The unique identifier of the asynchronous interface test task contained in the callback request is used to associate the corresponding asynchronous interface test task.
[0068] Generate and call back the task data of the request processing task: mark the task type as "callback request processing task", set the callback request processing task unique identifier to {asynchronous interface test task unique identifier}_sync, and use it as RedisKey; the stored information includes the callback request processing task unique identifier, the corresponding asynchronous interface test task unique identifier, callback request parameters, response data, etc. The naming rules of RedisKey ensure that each callback request can be uniquely identified and quickly retrieved.
[0069] Add to task queue: Add the task data of the callback request processing task to the Redis task queue.
[0070] The interface testing method provided by the present invention initiates a callback request through the callback address provided by the client through the service under test. After receiving the callback request from the service under test, the client generates task data of the callback request processing task and adds it to the task queue, thereby ensuring the reliable generation of task data of the callback request processing task.
[0071] The interface testing method provided by the present invention can integrate the function of synchronous interface testing on the basis of realizing asynchronous interface testing, and realize interface testing of different interface processing modes (including asynchronous and synchronous). Among them, since the service under test directly returns the result, the synchronous interface test does not need to set the callback address.
[0072] Figure 2 This is one of the schematic diagrams of the generation process of task data in the interface testing method provided by the present invention. Figure 2 The process of generating task data of a task to be executed and adding it to a task queue is shown. The process includes: The client obtains the test case parameters and generates a unique identifier (unique identifier ID) for the asynchronous interface test task after receiving the trigger instruction for the test case execution.
[0073] For asynchronous interface testing, configure the callback address callbackUrl (or expressed as callback url), splice the unique identifier of the asynchronous interface test task to callbackUrl as the request parameter, create a test case and callbackUrl (specifically, it can be mapped through the unique identifier of the asynchronous interface test task), assemble the test case parameters and callbackUrl into package data, set the package data task type to asynchronous interface test task, add the package data to the Redis task queue, and RedisKey is the unique identifier of the asynchronous interface test task.
[0074] For synchronous interface testing, assemble the test case parameters into package data, set the package data task type to synchronous interface test task, add the package data to the Redis task queue, and RedisKey is the unique identifier of the synchronous interface test task.
[0075] Figure 3 This is the second schematic diagram of the generation process of task data in the interface testing method provided by the present invention. Figure 3 The process of receiving the callback request of the service under test, generating task data of the callback request processing task and adding it to the task queue is shown. The process includes: The web module of the client receives the callback request of the tested service; the callback request includes the unique identifier of the asynchronous interface test task, the callback request parameters and the response data; Parse the unique identifier of the asynchronous interface test task, generate the unique identifier of the callback request processing task according to the unique identifier of the asynchronous interface test task, assemble the package data according to the unique identifier of the callback request processing task, the unique identifier of the asynchronous interface test task, the callback request parameters, and the response data, set the package data task type to the callback request processing task (asynchronous callback task), and store the task data of the callback request processing task in the Redis task queue. The RedisKey is the unique identifier of the callback request processing task.
[0076] Figure 4 This is the second processing flow diagram of the interface testing method provided by the present invention. Figure 4 The processing flow of the server when performing synchronous interface testing and asynchronous interface testing is shown. The processing flow includes: The server monitors the Redis queue; According to the unique identifier of the asynchronous interface test task, obtain the task data of the task to be executed in the task queue; Get the task type of task data; For asynchronous interface test tasks (execution tasks), perform pre-operations and send interface call requests to the service under test; For asynchronous interface testing, the context object (context class) is serialized into Redis and identified as {asynchronous interface test task unique identifier}_context, and the test case is marked as waiting for asynchronous callback; For synchronous interface testing, post-processing operations are performed and the use case status is updated to End.
[0077] For callback request processing tasks (asynchronous callback tasks), according to {asynchronous interface test task unique identifier}_context, the context object is obtained from Redis, deserialized, and post-operation is performed, and the use case status is updated to end. Among them, the post-operation can be implemented through third-party interface calls or custom scripts.
[0078] The asynchronous interface testing device provided by the present invention is described below. The asynchronous interface testing device described below and the asynchronous interface testing method described above can be referenced to each other.
[0079] Figure 5 Schematic diagram of the structure of the asynchronous interface test device provided by the present invention. Figure 5 As shown, the device includes an acquisition module 10, an asynchronous interface test task execution module 20 and a callback request processing task execution module 30, wherein: the acquisition module 10 is used to: acquire the task data of the task to be executed in the task queue; wherein, for the asynchronous interface test task, the task data includes the asynchronous interface test task unique identifier, test case parameters, callback address and task type; for the callback request processing task, the task data includes the callback request processing task unique identifier, the asynchronous interface test task unique identifier of the corresponding asynchronous interface test task, callback request parameters, response data and task type; the asynchronous interface test task execution module 20 is used to: in response to determining that the task to be executed is the asynchronous interface test task according to the task type, according to the asynchronous interface test task The asynchronous interface test task unique identifier, the test case parameters and the callback address generate an interface call request, and send the interface call request to the service under test; the callback request processing task execution module 30 is used for: in response to determining that the task to be executed is a callback request processing task according to the task type, according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, obtaining the test case parameters corresponding to the asynchronous interface test task unique identifier by querying the task data pre-stored in the database, obtaining the expected response according to the test case parameters, performing an assertion operation according to the expected response and the response data of the callback request processing task, and verifying the correctness of the response data returned by the service under test.
[0080] The interface testing device provided by the present invention obtains task data of tasks to be executed in a task queue, responds to determining that the task to be executed is an asynchronous interface testing task according to the task type, generates an interface calling request according to the asynchronous interface testing task unique identifier, test case parameters and callback address of the asynchronous interface testing task, and sends the interface calling request to the tested service, responds to determining that the task to be executed is a callback request processing task according to the task type, processes the asynchronous interface testing task unique identifier of the asynchronous interface testing task corresponding to the callback request processing task, obtains test case parameters corresponding to the asynchronous interface testing task unique identifier by querying task data pre-stored in a database, obtains an expected response according to the test case parameters, performs an assertion operation according to the expected response and the response data of the callback request processing task, verifies the correctness of the response data returned by the tested service, avoids resource consumption caused by long polling, improves the system performance and testing efficiency of the asynchronous interface testing, does not need to obtain data from the middleware, can realize effective monitoring of all tasks (including stateless tasks), improves the integrity of the asynchronous interface testing, ensures that the request response of the asynchronous interface can be accurately obtained, and improves the accuracy of the asynchronous interface testing.
[0081] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6As shown, the electronic device may include: a processor 610, a communications interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communications interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the interface testing method, which includes: obtaining the task data of the task to be executed in the task queue; wherein, for the asynchronous interface test task, the task data includes the asynchronous interface test task unique identifier, the test case parameters, the callback address and the task type; for the callback request processing task, the task data includes the callback request processing task unique identifier, the asynchronous interface test task unique identifier of the corresponding asynchronous interface test task, the callback request parameters, the response data and the task type; in response to determining that the task to be executed is the asynchronous interface test task according to the task type, according to the asynchronous interface test task of the asynchronous interface test task An interface call request is generated based on the task unique identifier, the test case parameters and the callback address, and the interface call request is sent to the service under test; in response to determining that the task to be executed is a callback request processing task according to the task type, according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, the test case parameters corresponding to the asynchronous interface test task unique identifier are obtained by querying the task data pre-stored in the database, an expected response is obtained according to the test case parameters, an assertion operation is performed according to the expected response and the response data of the callback request processing task, and the correctness of the response data returned by the service under test is verified.
[0082] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0083] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the interface testing method provided by the above-mentioned methods, which includes: obtaining task data of tasks to be executed in a task queue; wherein, for asynchronous interface testing tasks, the task data includes an asynchronous interface testing task unique identifier, test case parameters, a callback address and a task type; for callback request processing tasks, the task data includes a callback request processing task unique identifier, the asynchronous interface testing task unique identifier of the corresponding asynchronous interface testing task, callback request parameters, response data and task type; in response to determining the task to be executed according to the task type For the asynchronous interface test task, an interface call request is generated according to the asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task, and the interface call request is sent to the service under test; in response to determining that the task to be executed is a callback request processing task according to the task type, according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, the test case parameters corresponding to the asynchronous interface test task unique identifier are obtained by querying the task data pre-stored in a database, an expected response is obtained according to the test case parameters, an assertion operation is performed according to the expected response and the response data of the callback request processing task, and the correctness of the response data returned by the service under test is verified.
[0084] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the interface testing method provided by the above-mentioned methods, the method comprising: obtaining task data of tasks to be executed in a task queue; wherein, for asynchronous interface testing tasks, the task data comprises an asynchronous interface testing task unique identifier, test case parameters, a callback address and a task type; for callback request processing tasks, the task data comprises a callback request processing task unique identifier, the asynchronous interface testing task unique identifier of the corresponding asynchronous interface testing task, callback request parameters, response data and a task type; in response to determining that the task to be executed is the asynchronous interface testing task according to the task type, according to The asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task generate an interface call request, and send the interface call request to the service under test; in response to determining that the task to be executed is a callback request processing task according to the task type, according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, obtain the test case parameters corresponding to the asynchronous interface test task unique identifier by querying the task data pre-stored in the database, obtain the expected response according to the test case parameters, perform an assertion operation according to the expected response and the response data of the callback request processing task, and verify the correctness of the response data returned by the service under test.
[0085] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0086] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0087] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An interface testing method, characterized in that: include: Obtain task data for tasks to be executed in the task queue; wherein, for an asynchronous interface test task, the task data includes a unique identifier of the asynchronous interface test task, test case parameters, a callback address, and a task type; for a callback request processing task, the task data includes a unique identifier of the callback request processing task, the unique identifier of the asynchronous interface test task of the corresponding asynchronous interface test task, callback request parameters, response data, and task type; In response to determining that the task to be executed is the asynchronous interface test task according to the task type, generating an interface call request according to the asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task, and sending the interface call request to the service under test; In response to determining that the task to be executed is a callback request processing task according to the task type, according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, the test case parameters corresponding to the asynchronous interface test task unique identifier are obtained by querying the task data pre-stored in a database, an expected response is obtained according to the test case parameters, an assertion operation is performed according to the expected response and the response data of the callback request processing task, and the correctness of the response data returned by the service under test is verified.
2. The interface testing method according to claim 1, characterized in that: Before generating an interface call request according to the asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task, the method further includes: Acquire a pre-code segment based on the test case parameters, and perform data preparation or environment configuration by executing the pre-code segment; and / or, Variable initialization information is obtained based on the test case parameters, and variables in the variable pool are initialized according to the variable initialization information.
3. The interface testing method according to claim 2, characterized in that: The method further comprises: According to the execution process of the preceding code segment and the generation process of the interface call request, interface test context data is generated and stored in a database; wherein the interface test context data includes an interface test context data unique identifier, the asynchronous interface test task unique identifier and context object data.
4. The interface testing method according to claim 3, characterized in that: In response to determining, according to the task type, that the task to be executed is a callback request processing task, the method further includes: According to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, the corresponding interface test context data is obtained, and the corresponding context object data is obtained by querying the interface test context data; Data processing is performed according to the context object data or the correctness of the callback request parameters is verified.
5. The interface testing method according to claim 3, characterized in that: In the interface test context data, the asynchronous interface test task unique identifier is included in the interface test context data unique identifier.
6. The interface testing method according to claim 1, characterized in that: In the task data of the asynchronous interface test task, the unique identifier of the asynchronous interface test task is spliced into the callback address; and / or, In the callback request processing task, the asynchronous interface test task unique identifier is included in the callback request processing task unique identifier.
7. The interface testing method according to claim 1, characterized in that: The task data of the task to be executed is generated by the client after responding to the trigger operation of the test case execution based on the currently input test case parameters and is stored in the database and added to the task queue.
8. The interface testing method according to claim 1, characterized in that: The task data of the callback request processing task is generated by the client after receiving the callback request of the service under test and added to the task queue.
9. An asynchronous interface testing device, characterized in that: include: An acquisition module is used to: acquire task data of tasks to be executed in a task queue; wherein, for an asynchronous interface test task, the task data includes a unique identifier of the asynchronous interface test task, test case parameters, a callback address, and a task type; for a callback request processing task, the task data includes a unique identifier of the callback request processing task, the unique identifier of the asynchronous interface test task of the corresponding asynchronous interface test task, callback request parameters, response data, and task type; An asynchronous interface test task execution module, used for: in response to determining that the task to be executed is the asynchronous interface test task according to the task type, generating an interface call request according to the asynchronous interface test task unique identifier, the test case parameters and the callback address of the asynchronous interface test task, and sending the interface call request to the service under test; A callback request processing task execution module is used to: in response to determining that the task to be executed is a callback request processing task according to the task type, obtain the test case parameters corresponding to the asynchronous interface test task unique identifier by querying the task data pre-stored in a database according to the asynchronous interface test task unique identifier of the asynchronous interface test task corresponding to the callback request processing task, obtain the expected response according to the test case parameters, perform an assertion operation according to the expected response and the response data of the callback request processing task, and verify the correctness of the response data returned by the tested service.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the interface testing method according to any one of claims 1 to 8 is implemented.
11. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the interface testing method according to any one of claims 1 to 8 is implemented.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the interface testing method according to any one of claims 1 to 8 is implemented.