Method for testing environment to simulate external interface to return data
By using interceptors to simulate the return data of external interfaces in the test environment, the problem of test delay in online ride-hailing business is solved, and the testing efficiency is improved and the rapid functional iteration of external service interfaces is achieved.
Patent Information
- Application Number
- CN202411460326.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-02-07
AI Technical Summary
In the online ride-hailing business scenario, the call relationship of the external interface in the test environment is complex, which makes the testers unable to obtain cooperation from external company technicians in a timely manner, resulting in delayed tests.
Design a method to simulate data return of external interfaces through an interceptor. If the mockResData parameter exists, its value is used as the return value of the external service interface, skip remote calls, and implement data simulation.
Simulate external interface return data in the test environment, avoiding test delays caused by the inability of external company technicians to cooperate in time, improving testing efficiency, and supporting rapid functional iteration of external service interfaces.
Smart Images

Figure CN119396727A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of online car-hailing, and specifically relates to a method for simulating an external interface to return data in a test environment. Background Art
[0002] In the online car-hailing business scenario that cooperates with external company channels, a complete business link often involves multiple internal and external interfaces. In the early stage of joint debugging with new channels or the process of joint debugging of business upgrades required by old channels, when testing related functional points in the test environment, due to the calling relationship of the interface, the cooperation of external company technicians is often required to complete the following contents: including but not limited to creating test data, configuring service interface addresses, IP whitelists, etc. However, due to the work schedule restrictions or temporary leave of the other party's technicians, they are unable to cooperate with us to complete the above contents in time, which often results in our testers being unable to complete the functional internal testing within the specified time. How to circumvent external factors that cause us to delay has become a problem that must be solved.
[0003] To this end, the present invention designs a method for a test environment to simulate external interface return data. Summary of the invention
[0004] The object of the present invention is to provide a method for simulating external interface return data in a test environment to solve the problems raised in the above background technology.
[0005] To achieve the above object, the present invention provides the following technical solution: a method for simulating external interface return data in a test environment, and the specific execution steps are as follows:
[0006] S1: The internal interface starts processing and receiving request parameters;
[0007] S2: parse the parameters in the request;
[0008] S3: Determine whether the current execution environment is a test environment; if so, execute step S4;
[0009] S4: Determine whether there is a mockResData request parameter; if so, execute step S5;
[0010] S5: Determine whether the mockResData parameter has a value; if so, execute step S6;
[0011] S6: Call the underlying API interface of the thread and put the value of the mockResData parameter into the thread context;
[0012] S7: Continue to process the original logic of the internal interface;
[0013] S8: The interceptor intercepts calls to external service interfaces;
[0014] S9: Call the underlying API interface of the thread and try to obtain the mockResData parameter from the thread context;
[0015] S10: Determine whether the mockResData parameter value is empty; if it is not empty, execute step S11, otherwise execute step S12;
[0016] S11: skip the execution of the remote call to the external service interface, use the mockResData parameter value as the return value of the external service interface, and continue to execute step S13;
[0017] S12: Remotely call the external service interface according to the original logic;
[0018] S13: Continue with the subsequent logic and end;
[0019] S14: Execute the original interface logic and end.
[0020] Preferably, in step S6, the advantage of putting the parameters into the thread context is that the thread can take out the parameters at any time during the execution process, which is a way to access the parameter values.
[0021] Preferably, in step S3, when the current execution environment is not a test environment, the original interface logic is executed and ends.
[0022] Preferably, in step S4, if the mockResData request parameter does not exist, the original interface logic is executed and ends.
[0023] Preferably, in step S5, if the mockResData parameter has no value, the original interface logic is executed and ends.
[0024] Compared with the prior art, the beneficial effects of the present invention are: when the method designed by the present invention is internally tested by us, the internal testing will not be delayed due to the inability of technical personnel of external companies to cooperate in time; the upgrading of old internal business logic involving external service interfaces is conducive to its rapid functional iteration. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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.
[0027] See also Figure 1 , the present invention provides a technical solution: a method for simulating the return data of an external interface in a test environment, which is implemented by an interceptor, intercepting all requests to the external interface, and if there are agreed parameters in the request parameters and the parameter name has a value, the service interface of the external company is no longer requested, and the value corresponding to the agreed parameter name is directly used as the return value of the external service interface and the logic processing is continued based on it, and finally the internal test of the function is completed;
[0028] The specific steps are as follows:
[0029] S1: The internal interface starts processing and receiving request parameters;
[0030] S2: parse the parameters in the request;
[0031] S3: Determine whether the current execution environment is a test environment; if so, execute step S4; otherwise, execute step S14;
[0032] S4: Determine whether there is a mockResData request parameter; if so, execute step S5, otherwise execute step S14;
[0033] S5: Determine whether the mockResData parameter has a value; if so, execute step S6; otherwise, execute step S14;
[0034] S6: Call the underlying API interface of the thread and put the value of the mockResData parameter into the thread context;
[0035] The advantage of putting it in the thread context is that the thread can use the parameters at any time during execution, which is a very convenient way to store and access parameter values;
[0036] S7: Continue to process the original logic of the internal interface;
[0037] S8: The interceptor intercepts calls to external service interfaces;
[0038] S9: Call the underlying API interface of the thread and try to obtain the mockResData parameter from the thread context;
[0039] S10: Determine whether the mockResData parameter value is empty. If it is not empty, execute step S11, otherwise execute step S12;
[0040] S11: skip the execution of the remote call to the external service interface, use the mockResData parameter value as the return value of the external service interface, and continue to execute step S13;
[0041] S12: Remotely call the external service interface according to the original logic;
[0042] S13: Continue with the subsequent logic and end;
[0043] S14: Execute the original interface logic and end.
[0044] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for simulating external interface return data in a test environment, characterized in that: The specific steps are as follows: S1: The internal interface starts processing and receiving request parameters; S2: parse the parameters in the request; S3: Determine whether the current execution environment is a test environment; if so, execute step S4; S4: Determine whether there is a mockResData request parameter; if so, execute step S5; S5: Determine whether the mockResData parameter has a value; if so, execute step S6; S6: Call the underlying API interface of the thread and put the value of the mockResData parameter into the thread context; S7: Continue to process the original logic of the internal interface; S8: The interceptor intercepts calls to external service interfaces; S9: Call the underlying API interface of the thread and try to obtain the mockResData parameter from the thread context; S10: Determine whether the mockResData parameter value is empty; if it is not empty, execute step S11, otherwise execute step S12; S11: skip the execution of the remote call to the external service interface, use the mockResData parameter value as the return value of the external service interface, and continue to execute step S13; S12: Remotely call the external service interface according to the original logic; S13: Continue with the subsequent logic and end; S14: Execute the original interface logic and end.
2. The method for simulating external interface return data in a test environment according to claim 1, characterized in that: In step S6, the advantage of putting the parameters into the thread context is that the thread can use the parameters at any time during the execution process, which is a way to access parameter values.
3. The method for simulating external interface returning data in a test environment according to claim 1, characterized in that: In step S3, when the current execution environment is not a test environment, the original interface logic is executed and ends.
4. The method for simulating external interface returning data in a test environment according to claim 1, characterized in that: In step S4, if the mockResData request parameter does not exist, the original interface logic is executed and the process ends.
5. The method for simulating external interface returning data in a test environment according to claim 1, characterized in that: In step S5, if the mockResData parameter has no value, the original interface logic is executed and the process ends.