Interface test method and device, computer device, storage medium and program product

CN116401161BActive Publication Date: 2026-09-22IND BANK CO
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310337336.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-31
Publication Date
2026-09-22
Estimated Expiration
2043-03-31

AI Technical Summary

Technical Problem

然而,在复杂的业务场景下,每个测试接口之间的调用不是独立进行的,而是具有一定的关联性

Benefits of technology

[0037]上述接口测试方法、装置、计算机设备、存储介质和计算机程序产品,通过响应于接口测试请求,获取与每个待测试接口对应的接口测试报文以及与每个待测试接口对应的接口测试顺序;按照接口测试顺序依次向每个待测试接口转发对应的接口测试报文,以指示每个待测试接口在接收到对应的接口测试报文时执行相应的接口调用操作,并生成与接口调用操作对应的目标响应报文,接收每个待测试接口返回的目标响应报文;根据目标响应报文,生成每个待测试接口的测试结果,能够同时实现对每个待测试接口的功能响应测试以及接口调用测试,从而提高接口测试方法的全面性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116401161B_ABST
    Figure CN116401161B_ABST
Patent Text Reader

Abstract

The application relates to an interface test method and device, computer equipment, a storage medium and a computer program product. The method comprises the following steps: in response to an interface test request, obtaining an interface test message and an interface test sequence; forwarding the interface test message to a plurality of to-be-tested interfaces in sequence according to the interface test sequence, so as to instruct each to-be-tested interface to perform a corresponding interface calling operation when receiving the corresponding interface test message, and generate a target response message corresponding to the interface calling operation; receiving the target response message returned by each to-be-tested interface; and generating a test result of each to-be-tested interface according to the target response message. The method can simultaneously realize function response testing and interface calling testing of each to-be-tested interface, thereby improving the comprehensiveness of the interface test method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automated testing technology, and in particular to an interface testing method, apparatus, computer equipment, storage medium, and computer program product. Background Technology

[0002] Before a new business feature goes live, developers and testers typically need to test it to ensure its proper functioning. For example, they can trigger business requests by clicking on page components to verify the business flow. However, when the business feature to be tested involves multiple interfaces, the testing workload is significant, leading to low efficiency in manual testing.

[0003] In traditional technologies, testing platforms can automate unit testing for each test interface to determine whether its response status is normal. However, in complex business scenarios, the calls between each test interface are not independent but rather interconnected. In such cases, traditional testing methods struggle to accurately determine the retention rates and functionality of multiple test interfaces, leading to incomplete test results. Summary of the Invention

[0004] Therefore, it is necessary to provide an interface testing method, apparatus, computer equipment, computer-readable storage medium, and computer program product with more comprehensive testing functions to address the above-mentioned technical problems.

[0005] Firstly, this application provides an interface testing method. The method includes:

[0006] In response to an interface test request, obtain the interface test message corresponding to each interface to be tested and the interface test order corresponding to each interface to be tested;

[0007] According to the interface test order, the corresponding interface test message is forwarded to each interface to be tested in sequence, so as to instruct each interface to be tested to perform the corresponding interface call operation when it receives the corresponding interface test message, and generate a target response message corresponding to the interface call operation;

[0008] Receive the target response message returned by each of the interfaces to be tested;

[0009] Based on the target response message, generate test results for each of the interfaces to be tested.

[0010] In one embodiment, the method further includes:

[0011] Retrieve the test case record corresponding to the interface test request;

[0012] The test case response message corresponding to each interface to be tested and the interface test message is obtained from the test case record;

[0013] The step of generating test results for each interface to be tested based on the target response message includes:

[0014] Compare the test case response message and the target response message for each of the interfaces to be tested to obtain the message comparison result for each interface to be tested;

[0015] The test results for each interface under test are generated by comparing the messages of each interface under test.

[0016] In one embodiment, the method for generating the test case record includes:

[0017] Retrieve test cases in recording mode;

[0018] According to the test case, call the corresponding multiple interfaces to be tested to perform the corresponding test operations;

[0019] In response to the recording mode, the gateway records the interface test messages forwarded to each interface to be tested, the interface test order, and the test case response messages returned by each interface to be tested, thereby obtaining test case records corresponding to the test cases.

[0020] In one embodiment, the method further includes:

[0021] In response to the playback operation of the test case record, the interface test request is triggered.

[0022] In one embodiment, the method further includes:

[0023] Obtain the service message identifier carried in the interface test message;

[0024] In response to the result that the service message identifier meets the service diversion condition, the interface call information corresponding to the interface test message is recorded.

[0025] In one embodiment, the method further includes:

[0026] When at least one of the interfaces to be tested is an external interface, determine the test mode corresponding to the test message of the interface.

[0027] When the test mode is recording mode, the interface test message is sent to the external interface and the target response message returned by the external interface is received.

[0028] When the test mode is replay mode, intercept the interface test message sent to the external interface, obtain the response message record corresponding to the external interface, and use the response message record as the target response message.

[0029] Secondly, this application also provides an interface testing apparatus. The apparatus includes:

[0030] The request and response module is used to respond to interface test requests, obtain the interface test message corresponding to each interface to be tested, and the interface test order corresponding to each interface to be tested;

[0031] The message sending module is used to forward the corresponding interface test message to each interface to be tested in sequence according to the interface test order, so as to instruct each interface to be tested to perform the corresponding interface call operation when it receives the corresponding interface test message, and generate a target response message corresponding to the interface call operation;

[0032] The message receiving module is used to receive the target response message returned by each of the interfaces to be tested;

[0033] The result generation module is used to generate test results for each of the interfaces to be tested based on the target response message.

[0034] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the interface testing method described in any of the embodiments of the first aspect.

[0035] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the interface testing method described in any of the embodiments of the first aspect above.

[0036] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the interface testing method described in any of the embodiments of the first aspect.

[0037] The aforementioned interface testing method, apparatus, computer equipment, storage medium, and computer program product, in response to an interface testing request, acquire the interface test message corresponding to each interface to be tested and the interface test sequence corresponding to each interface to be tested; forward the corresponding interface test message to each interface to be tested sequentially according to the interface test sequence, so as to instruct each interface to be tested to perform the corresponding interface call operation upon receiving the corresponding interface test message, and generate a target response message corresponding to the interface call operation, and receive the target response message returned by each interface to be tested; and generate the test result for each interface to be tested based on the target response message. This enables simultaneous functional response testing and interface call testing of each interface to be tested, thereby improving the comprehensiveness of the interface testing method.

[0038] Furthermore, the interface testing method provided in this application, by sequentially triggering the corresponding interface call operation of each interface to be tested using the interface testing sequence, can also ensure the successful function call between multiple interfaces to be tested, thereby improving the accuracy of the test results. Attached Figure Description

[0039] Figure 1 This is a flowchart illustrating an interface testing method in one embodiment;

[0040] Figure 2 This is a schematic diagram of the interface test message forwarding steps in one embodiment;

[0041] Figure 3 This is a flowchart illustrating the test result generation steps in one embodiment;

[0042] Figure 4 This is a flowchart illustrating the steps involved in generating test case records in one embodiment.

[0043] Figure 5 This is a schematic diagram illustrating the test case execution steps in one embodiment;

[0044] Figure 6 This is a flowchart illustrating the interface testing method in another embodiment;

[0045] Figure 7 This is a structural block diagram of an interface testing device in one embodiment;

[0046] Figure 8 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0047] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0048] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0049] In one embodiment, such as Figure 1 As shown, an interface testing method is provided. This embodiment uses the application of this method to a server as an example for illustration. It can be understood that this method can also be applied to terminals, and can also be applied to systems including terminals and servers, and implemented through the interaction between the terminal and the server. The terminal can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can be smart TVs, smart in-vehicle devices, etc. Portable wearable devices can be smartwatches, smart bracelets, head-mounted devices, etc. The server can be implemented using a standalone server or a server cluster composed of multiple servers.

[0050] In this embodiment, the method includes the following steps:

[0051] Step S102: In response to the interface test request, obtain the interface test message corresponding to each interface to be tested and the interface test order corresponding to each interface to be tested.

[0052] The interfaces to be tested can include, but are not limited to, one or more functional interfaces such as microservice call interfaces, database query interfaces, application layer protocol conversion interfaces, and presentation layer visualization conversion interfaces. The specific interfaces to be tested can be determined based on the specific interface testing requirements.

[0053] Specifically, the server can respond to interface test requests triggered for multiple interfaces to be tested, parse the interface test requests to obtain the interface test message corresponding to each interface to be tested and the interface test order corresponding to each interface to be tested. The interface test messages corresponding to each interface to be tested can be the same, or they can be different; the specific interface test messages can be customized according to the user's actual interface testing requirements.

[0054] Alternatively, the server can respond to an interface test request, determine the functional logic to be tested corresponding to the interface test request, obtain multiple interfaces to be tested required to implement the functional logic to be tested, generate an interface test message corresponding to each interface to be tested, and configure and determine the interface test order corresponding to each interface to be tested according to the calling order of the multiple interfaces to be tested required to implement the functional logic to be tested.

[0055] Alternatively, the server can parse the interface test requests to obtain the corresponding test case identifiers. These test case identifiers are then used to retrieve the corresponding interface test messages and the interface test order for each interface under test from a local database or the internet.

[0056] Step S104: Forward the corresponding interface test message to each interface to be tested in sequence according to the interface test order.

[0057] The interface call operation can be a call from one interface under test to another interface under test, or it can be a call from one interface under test to a functional interface other than the interface under test. The specific interface call object can be customized according to the user's actual interface testing needs.

[0058] The target response message may include, but is not limited to, any one or more of the following data: the response status of the interface under test (e.g., response success or response failure), response time, response result, and interface call status (e.g., interface call success or interface call failure).

[0059] In one example, when an interface call operation requires message forwarding, the target response message may also include an interface call request message to instruct the corresponding message forwarder, such as a gateway, to forward the interface call request to the corresponding interface to complete the call operation on that interface.

[0060] Specifically, the server can forward corresponding interface test messages to each interface under test sequentially according to the interface testing order. This instructs each interface under test to process the interface test message upon receiving it, execute the corresponding interface call operation, and generate a target response message corresponding to the interface call operation. The interval between each forwarding of the interface test message can be a preset period, which can be determined based on the average response time of the interface under test. Alternatively, the server can forward messages to the next interface under test only after receiving the target response message returned by the interface under test.

[0061] In one example, an interface test message can be used to test the data query and display functionality of an interface. In this case, implementing the data query and display functionality requires calling application layer interface A, database interface B, and presentation layer interface C. The interface testing order is application layer interface A → database interface B → presentation layer interface C. The interface test messages corresponding to application layer interface A, database interface B, and presentation layer interface C can be query and display test messages.

[0062] like Figure 2As shown, the server can, according to the interface testing sequence, first send the corresponding query display test message to the application layer interface A under test through the gateway. Upon receiving the query display test message, application layer interface A converts the query conditions in the message into query keys that the database can recognize, and then executes a call to database interface B. Since application layer interface A and database interface B are not on the same software logic layer, application layer interface A can return a target response message carrying the query key and the database interface call request to the gateway, instructing the gateway to forward the query key and the database interface call request to database interface B, thereby realizing the interface call operation.

[0063] The server can send corresponding query and display test messages to database interface B according to the interface test sequence through the gateway. This allows database interface B to retrieve the corresponding query results from its local database using the query key and then execute a call to presentation layer interface C. Since database interface B and presentation layer interface C are not at the same software logic layer, presentation layer interface C can return a target response message carrying the query results and the presentation layer interface call request to the gateway. This instructs the gateway to forward the query results and the presentation layer interface call request to presentation layer interface C, thereby enabling the interface call.

[0064] The server can send corresponding query and display test messages to the presentation layer interface C through the gateway according to the interface test order, so that the presentation layer interface C can perform visualization processing on the query results to obtain the visualization results, directly call the front-end rendering interface to render and display the visualization interface, and return a target response message to the gateway carrying the visualization results and the interface call status as successful.

[0065] Step S106: Receive the target response message returned by each interface to be tested.

[0066] Specifically, the server can receive and store the target response message returned by each interface to be tested. Optionally, in some embodiments, the server can also store the target response messages returned by each interface to be tested in order according to the order in which they were received. In another example, when the server responds to multiple interface test requests, it can classify and store the target response messages returned by each interface to be tested according to the request identifier corresponding to each interface test request.

[0067] Step S108: Generate test results for each interface to be tested based on the target response message.

[0068] Specifically, when the target response message carries both the response status and the API call status, the server can generate test results for each API under test based on these two statuses. For example, if the response is successful but the API call fails, the generated test result for the API under test is "Response function test passed, API call test failed." If both the response and the API call are successful, the generated test result for the API under test is "Response function test passed, API call test passed." If the response fails, the generated test result for the API under test is simply "Failed."

[0069] If the target response message carries a response result, the server can compare the response result with the response result returned by the interface under normal operation that corresponds to the interface test message. If the comparison result is consistent, the test result is generated as "interface test passed"; otherwise, the test result is generated as "interface test failed".

[0070] If the target response message carries the response time, the server can compare the response time with a preset time threshold. If the response time is less than or equal to the preset time threshold, the server will generate a test result indicating that the interface test has passed; otherwise, the server will generate a test result indicating that the interface test has failed.

[0071] The aforementioned interface testing method, in response to interface testing requests, obtains the interface test message and the corresponding interface test order for each interface to be tested; it forwards the corresponding interface test message to each interface to be tested sequentially according to the interface test order, instructing each interface to perform the corresponding interface call operation upon receiving the corresponding interface test message, and generates a target response message corresponding to the interface call operation, and receives the target response message returned by each interface to be tested; based on the target response message, it generates the test result for each interface to be tested, thus simultaneously achieving functional response testing and interface call testing for each interface to be tested, thereby improving the comprehensiveness of the interface testing method.

[0072] Furthermore, the interface testing method provided in this application, by sequentially triggering the corresponding interface call operation of each interface to be tested using the interface testing sequence, can also ensure the successful function call between multiple interfaces to be tested, thereby improving the accuracy of the test results.

[0073] In one embodiment, such as Figure 3 As shown, the interface testing method provided in this application may also include:

[0074] Step S302: Obtain the test case record corresponding to the interface test request.

[0075] Step S304: Query the test case record to obtain the test case response message corresponding to each interface to be tested and the interface test message.

[0076] The test case record can be used to store the test order among multiple interfaces to be tested triggered when the test case is executed, the messages sent to each interface to be tested, the messages returned by each interface to be tested, the test case identifier, and any one or more of the following data:

[0077] Test case response messages can be used to characterize the response message returned by each interface under test when the test case is executed, corresponding to the interface test message.

[0078] Specifically, the server can retrieve the test case record corresponding to the test case identifier from a local database or the internet based on the test case identifier obtained from parsing the interface test request. Then, based on the interface test message currently sent to each interface under test, the server can retrieve the test case response message corresponding to each interface under test from the test case record. In one example, the test case record could be a small text file (cookie) recorded by the tester in the front-end page component when performing a click test operation.

[0079] Step S306: Compare the test case response message and the target response message for each interface to be tested to obtain the message comparison result for each interface to be tested.

[0080] Step S308: Use the message comparison results of each interface to be tested to generate the test results for each interface to be tested.

[0081] Specifically, the server can use string matching to compare the test case response message and the target response message returned by each interface under test with the corresponding interface test message to determine whether the interface fields and response data are consistent, thereby obtaining the message comparison result corresponding to each interface under test. If the message comparison result shows that the test case response message and the target response message match, the test result for the interface under test is generated as "test passed"; otherwise, the test result for the interface under test is generated as "test failed".

[0082] In this embodiment, by obtaining the test case record corresponding to the interface test request, comparing the test case response message corresponding to each interface to be tested and the interface test message stored in the test case record with the target response message returned by each interface to be tested and the interface test message, and generating the test result of the interface to be tested based on the message comparison result, the accuracy of test result generation can be improved.

[0083] In one embodiment, such as Figure 4 The diagram illustrates a method for generating test case records, including:

[0084] Step S402: Obtain test cases in recording mode.

[0085] Specifically, the server can obtain the test cases input by the user and the corresponding test mode identifiers. Based on the test mode identifiers, it determines the test mode corresponding to the test cases, automatically generates test case identifiers, and establishes the association between test cases, test modes, and test case identifiers. When the test mode identifier is "R", it can be determined that the test mode corresponding to the current test case is recording mode, in which case the execution of the test case needs to be recorded. When the test mode identifier is "P", it can be determined that the test mode corresponding to the current test case is replay mode, in which case the executed test cases need to be replayed. When the test mode identifier is "U", it can be determined that the test mode corresponding to the current test case is general mode, in which case there is no need to record or replay the test cases.

[0086] Step S404: Based on the test cases, call the corresponding multiple interfaces to be tested to perform the corresponding test operations.

[0087] Specifically, such as Figure 5 As shown, when the test case involves interface X and interface Y to be tested, the server can generate corresponding functional test requests based on the functional control logic in the test case.

[0088] The gateway forwards functional test requests to the corresponding interface X to be tested, instructing interface X to perform the corresponding test operations in response to the functional test requests, and return a functional call request to the next interface Y to be tested. Similarly, the gateway forwards functional call requests to interface Y to be tested, instructing interface Y to perform the corresponding test operations in response to the functional call requests, and return the corresponding functional response results. This completes the testing process for the test cases.

[0089] Step S406: In response to the recording mode, the gateway records the interface test messages forwarded to each interface to be tested, the interface test order, and the test case response messages returned by each interface to be tested, thereby obtaining the test case record corresponding to the test case.

[0090] Specifically, in recording mode, the server can record the functional test request message while forwarding it to the interface under test X through the gateway, thereby obtaining the interface test message corresponding to interface X. Similarly, while receiving the functional call request for the next interface under test Y returned by interface X through the gateway, the server can record the functional call request message for interface Y, thereby obtaining the test case response message corresponding to interface X.

[0091] By forwarding the function call request to the interface Y under test through the gateway, and simultaneously recording the function call request message, the gateway obtains the interface test message corresponding to interface Y. Similarly, by receiving the function response result returned by interface Y under test through the gateway, and simultaneously recording the function response result, the gateway obtains the test case response message corresponding to the interface under test.

[0092] Based on the forwarding times of the recorded functional test requests and functional call requests, the interface test order corresponding to interface X and interface Y under test is determined. Using the interface test message, interface test order, and test case response message corresponding to each interface under test, test case records are generated. In one example, the gateway-forwarded request can carry a test case identifier and a test mode identifier, facilitating the identification of the corresponding test case execution status.

[0093] In this embodiment, by acquiring test cases carrying recording identifiers, interface test messages corresponding to each interface to be tested are generated based on the test cases. In response to the recording identifier, the gateway records the interface test messages, interface test order, and test case response messages corresponding to each interface to be tested while forwarding or receiving messages, thereby generating test case records corresponding to the test cases. The recording identifier can be used to record the execution of the entire test case process, thereby improving the comprehensiveness of the test case records.

[0094] In one embodiment, the interface testing method provided in this application may further include: triggering an interface testing request in response to a playback operation of test case records.

[0095] Specifically, the server can trigger interface test requests in response to the replay operation of the test case record via the gateway. In response to the interface test request, it retrieves the interface test message corresponding to each interface to be tested and the corresponding interface test order from the test case record. It then forwards the corresponding interface test messages to each interface to be tested sequentially according to the interface test order. It receives the target response message corresponding to the interface test message returned by each interface to be tested. It compares the test case response message corresponding to the interface test message in the test case record with the currently received target response message to obtain the message comparison result for each interface to be tested. Based on the message comparison result, it generates the test result corresponding to each interface to be tested.

[0096] In this embodiment, by responding to the replay operation of the test case record, an interface test request is triggered. The request is re-initiated in sequence according to the interface test order and interface test message recorded in the test case record. The currently received target response message is compared with the previously recorded test case response message to determine the test result of the interface to be tested. This enables automatic replay of the test case record, which greatly improves the testing efficiency and the comprehensiveness of the testing function.

[0097] In one embodiment, the interface testing method provided in this application may further include: obtaining the business message identifier corresponding to the interface test message, and recording the interface call information corresponding to the interface test message in response to the result that the business message identifier meets the business diversion condition.

[0098] The business message identifier can be determined based on the business function to be tested, or it can be determined based on the microservice that implements the business function to be tested. For example, if the business function to be tested is the object storage service (CloudObject Service), the corresponding business message identifier can be cos.

[0099] The interface call information may include, but is not limited to, any one or more of the following: the interface to be tested corresponding to the interface test message, the response result returned by the interface to be tested, or the interface call request returned by the interface to be tested.

[0100] Specifically, the server can pre-store business traffic splitting conditions to enable recording of test processes for specific business functions. When the gateway receives and forwards an interface test message, it can obtain the Uniform Resource Identifier (URI) of the interface test message, retrieve the business message identifier carried in the interface test message from the URI, and judge the business message identifier using the business traffic splitting conditions. If the business message identifier matches the splitting identifier in the business traffic splitting conditions, in response to the result that the business message identifier meets the business traffic splitting conditions, the interface call information corresponding to the interface test message is recorded. In one example, the operations of "obtaining the business message identifier corresponding to the interface test message, and recording the interface call information corresponding to the interface test message in response to the result that the business message identifier meets the business traffic splitting conditions" performed by the above server can be implemented by compiling the Lua scripting language (a lightweight, extensible scripting language that supports procedural and object-oriented programming).

[0101] In one example, the traffic splitting condition could include forwarding interface test messages carrying the splitting identifier "cos" to the interface of the application http: / / cos_uat. This ensures that the gateway records the corresponding interface call information each time it receives an interface test message carrying "cos".

[0102] In this embodiment, by determining whether the business message identifier carried by the interface test message meets the business diversion conditions, the corresponding interface call information is recorded. This enables the recording of interface call information for specific business function testing processes, thereby reducing the amount of data of the recorded interface call information.

[0103] In one embodiment, the interface testing method provided in this application may further include: when there is at least one interface to be tested that is an external interface, determining the test mode corresponding to the interface test message.

[0104] Specifically, the server can determine whether the interface to be tested corresponding to the interface test message is an external interface based on the Uniform Resource Identifier (URI) in the interface test message. For example, if the interface to be tested identifier in the URI carries the name of an external system, it can be determined that the interface to be tested corresponding to the interface test message is an external interface.

[0105] When the server determines that at least one interface to be tested is an external interface, it can determine the test mode corresponding to the interface test message based on the test mode identifier carried in the interface test message. In recording mode, the gateway can send interface test messages to the external interface and receive the target response message returned by the external interface. In playback mode, the gateway can intercept interface test messages sent to the external interface, obtain the response message record corresponding to the external interface (e.g., the test case response message corresponding to the external interface stored in the test case record), and use the currently obtained response message record as the target response message corresponding to the external interface.

[0106] In one example, the operations performed by the server in this embodiment of the application can be implemented by compiling a mock script (a script written in the Lua scripting language that has recording and interception functions).

[0107] In one example, when the test mode is in general mode, the gateway can forward the interface test messages normally without interception or recording.

[0108] In one example, in recording mode, the server can also save user information that triggered the interface test request and a list of requests corresponding to multiple interfaces to be tested through the gateway.

[0109] In this embodiment, by performing corresponding operations based on the test mode corresponding to the interface test message when forwarding the interface test message to the external interface, the testing flexibility of the external interface can be improved.

[0110] In one embodiment, such as Figure 6 As shown, a flowchart of an interface testing method is provided, including:

[0111] Step S602: Obtain test cases in recording mode and record the corresponding test case records through the gateway.

[0112] Specifically, the server can run a gateway capable of recording and replaying test cases (e.g., a test platform gateway built on OpenResty (a high-performance network platform) using the Lua scripting language to implement recording and playback functions). It retrieves the test mode identifier and test cases input by developers or testers from the front-end page. In response to the test mode being set to recording mode, the gateway records the corresponding test cases.

[0113] Step S604: In response to the replay operation of the test case record, trigger the interface test request and obtain the interface test message, interface test order and test case response message corresponding to each interface to be tested.

[0114] Specifically, the server can trigger interface test requests corresponding to multiple interfaces under test in response to the replay operation of the test case record. It can then retrieve the interface test message, the interface test order, and the corresponding test case message for each interface under test from the test case record.

[0115] Step S606: Forward the interface test messages to the corresponding multiple interfaces to be tested in sequence according to the interface test order.

[0116] Specifically, the server can forward corresponding interface test messages to multiple interfaces to be tested in sequence through the gateway according to the interface test order, so as to instruct each interface to be tested to perform corresponding interface test message processing and interface call operation when it receives the corresponding interface test message, and generate target response messages corresponding to the interface test message processing and interface call operation.

[0117] Step S608: Receive the target response message returned by each interface to be tested, and compare the target response message and the test case response message of each interface to be tested.

[0118] Step S610: Use the message comparison results of each interface to be tested to generate the test results for each interface to be tested.

[0119] Specifically, the server can receive the target response message returned by each interface under test, and perform string matching on the interface fields and response data in the target response message and the test case response message to obtain the message comparison result for each interface under test. If the message comparison result shows that the target response message and the test case response message are the same, the test result for the interface under test can be generated as "pass"; otherwise, the test result is generated as "fail". This yields the test result corresponding to each interface under test.

[0120] In this embodiment, test case records are recorded through a gateway. In response to the playback operation of the test case records, an interface test request is triggered. The corresponding interface test messages are forwarded to each interface to be tested in sequence according to the interface test order stored in the test case records. The target response message returned by each interface to be tested is compared with the test case response message stored in the test case records, thereby obtaining the test result of the interface to be tested. This enables the recording and automatic playback of test cases, thereby significantly improving the efficiency of interface testing. Furthermore, by using the messages forwarded in sequence according to the interface test order, it is possible to test the calling functions between multiple interfaces to be tested while testing a single interface to be tested, thereby improving the comprehensiveness of interface testing.

[0121] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the steps or stages of other steps.

[0122] Based on the same inventive concept, this application also provides an interface testing apparatus for implementing the interface testing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more interface testing apparatus embodiments provided below can be found in the limitations of the interface testing method described above, and will not be repeated here.

[0123] In one embodiment, such as Figure 7 As shown, an interface testing device 700 is provided, including: a request-response module 702, a message sending module 704, a message receiving module 706, and a result generation module 708, wherein:

[0124] The request and response module 702 is used to respond to the interface test request, obtain the interface test message corresponding to each interface to be tested and the interface test order corresponding to each interface to be tested;

[0125] The message sending module 704 is used to forward the corresponding interface test message to each interface to be tested in sequence according to the interface test order, so as to instruct each interface to be tested to perform the corresponding interface call operation when it receives the corresponding interface test message, and generate the target response message corresponding to the interface call operation;

[0126] The message receiving module 706 is used to receive the target response message returned by each interface to be tested.

[0127] The result generation module 708 is used to generate test results for each interface to be tested based on the target response message.

[0128] In one embodiment, the interface testing apparatus 700 further includes: a record acquisition module, used to acquire test case records corresponding to the interface test request; a message acquisition module, used to query the test case response message corresponding to each interface to be tested and the interface test message from the test case records; and a result generation module 708, used to compare the test case response message and the target response message corresponding to each interface to be tested to obtain the message comparison result of each interface to be tested, and to generate the test result of each interface to be tested using the message comparison result of each interface to be tested.

[0129] In one embodiment, the interface testing device 700 further includes: a record generation module, used to obtain test cases with the test mode set to recording mode; to call multiple corresponding interfaces to be tested according to the test cases to perform corresponding test operations; and in response to the recording mode, to record the interface test messages forwarded to each interface to be tested, the interface test order, and the test case response messages returned by each interface to be tested through the gateway, thereby obtaining test case records corresponding to the test cases.

[0130] In one embodiment, the request response module 702 is further configured to trigger an interface test request in response to a playback operation of the test case record.

[0131] In one embodiment, the interface testing device 700 further includes: a service diversion module, used to obtain the service message identifier carried by the interface test message; and in response to the result that the service message identifier meets the service diversion condition, to record the interface call information corresponding to the interface test message.

[0132] In one embodiment, the interface testing apparatus 700 further includes: an interface routing module, configured to determine the test mode corresponding to the interface test message when at least one interface to be tested is an external interface; when the test mode is recording mode, send the interface test message to the external interface and receive the target response message returned by the external interface; when the test mode is playback mode, intercept the interface test message sent to the external interface, obtain the response message record corresponding to the external interface, and use the response message record as the target response message.

[0133] Each module in the aforementioned interface testing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0134] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data such as interface test messages, interface test sequences, and target response messages. The network interface is used for communication with external terminals via a network connection. When executed by the processor, the computer program implements an interface testing method.

[0135] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0136] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0137] In one embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the steps in the above method embodiments.

[0138] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.

[0139] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0140] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0141] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. An interface testing method, characterized in that, The method includes: In response to an interface test request, obtain the interface test message corresponding to each interface to be tested and the interface test order corresponding to each interface to be tested; According to the interface test order, the corresponding interface test message is forwarded to each interface to be tested in sequence, so as to instruct each interface to be tested to perform the corresponding interface call operation when it receives the corresponding interface test message, and generate a target response message corresponding to the interface call operation; Receive the target response message returned by each of the interfaces to be tested; wherein, the interval between each forwarding of the interface test message is a preset period, or, after receiving the target response message returned by the interface to be tested, the server forwards the message to the next interface to be tested; Based on the target response message, generate test results for each of the interfaces to be tested; The method further includes: When at least one of the interfaces to be tested is an external interface, determine the test mode corresponding to the test message of the interface. When the test mode is recording mode, the interface test message is sent to the external interface and the target response message returned by the external interface is received. When the test mode is replay mode, intercept the interface test message sent to the external interface, obtain the response message record corresponding to the external interface, and use the response message record as the target response message.

2. The method according to claim 1, characterized in that, The method further includes: Retrieve the test case record corresponding to the interface test request; The test case response message corresponding to each interface to be tested and the interface test message is obtained from the test case record; The step of generating test results for each interface to be tested based on the target response message includes: Compare the test case response message and the target response message for each of the interfaces to be tested to obtain the message comparison result for each interface to be tested; The test results for each interface under test are generated by comparing the messages of each interface under test.

3. The method according to claim 2, characterized in that, The method for generating the test case records includes: Retrieve test cases in recording mode; According to the test case, call the corresponding multiple interfaces to be tested to perform the corresponding test operations; In response to the recording mode, the gateway records the interface test messages forwarded to each interface to be tested, the interface test order, and the test case response messages returned by each interface to be tested, thereby obtaining test case records corresponding to the test cases.

4. The method according to claim 3, characterized in that, The method further includes: In response to the playback operation of the test case record, the interface test request is triggered.

5. The method according to claim 1, characterized in that, The method further includes: Obtain the service message identifier carried in the interface test message; In response to the result that the service message identifier meets the service diversion condition, the interface call information corresponding to the interface test message is recorded.

6. An interface testing device, characterized in that, The device includes: The request and response module is used to respond to interface test requests, obtain the interface test message corresponding to each interface to be tested, and the interface test order corresponding to each interface to be tested; The message sending module is used to forward the corresponding interface test message to each interface to be tested in sequence according to the interface test order, so as to instruct each interface to be tested to perform the corresponding interface call operation when it receives the corresponding interface test message, and generate a target response message corresponding to the interface call operation; The message receiving module is used to receive the target response message returned by each of the interfaces to be tested; wherein, the interval between each forwarding of the interface test message is a preset period, or, after receiving the target response message returned by the interface to be tested, the server forwards the message to the next interface to be tested. The result generation module is used to generate test results for each of the interfaces to be tested based on the target response message. It is also used to: determine the test mode corresponding to the test message of the interface when at least one of the interfaces to be tested is an external interface; When the test mode is recording mode, the interface test message is sent to the external interface and the target response message returned by the external interface is received. When the test mode is replay mode, intercept the interface test message sent to the external interface, obtain the response message record corresponding to the external interface, and use the response message record as the target response message.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.

9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Test case processing method, apparatus and device, and storage medium

    CN110928777A

  • Interface testing method and device, storage medium and electronic device

    CN115543770A