Mock test method and system based on byte code injection, computer equipment and medium
By injecting preset rules into the client or server JVM of the financial trading platform to determine target test scenarios and strategies, the problem of upstream and downstream data inconsistency caused by existing mock tests is solved, and data consistency and system stability are achieved.
Patent Information
- Application Number
- CN202410728153.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-08-23
AI Technical Summary
The existing mock testing method causes inconsistency in upstream and downstream transaction data in financial trading platforms, affecting the stability of the platform and the friendliness of system interaction.
Use the mock testing method based on bytecode injection to determine the target test scenario and test strategy by injecting preset rules into the JVM of the client or server, generate and display test results, and ensure that exception handling is performed within the server or client. , thereby maintaining data consistency.
It effectively ensures the data consistency in testing of banking, insurance, order and other trading systems under the financial trading platform, avoids the problem of upstream and downstream data inconsistency, and ensures the stability and interaction friendliness of the system.
Smart Images

Figure CN118535477A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computers and financial technology, and in particular to a mock testing method, system, computer equipment and medium based on bytecode injection. Background Art
[0002] With the popularity of microservice frameworks, in the operation of financial trading platform projects, the actual business logic will lead to very complex calling relationships between different microservices. Therefore, it is particularly important to pre-test the exceptions generated by calling these services (such as UnionPay services and transaction supervision services) to provide financial services. In the process of testing the financial trading platform, a large number of testing methods are required to ensure the correctness of the transaction logic of the code and the robustness of the system. In the above verification process, a test method called mock testing is used to create a virtual transaction object for testing.
[0003] In the prior art, the mock test is performed by selecting an open source mock tool, and its test process is as follows: Figure 3 As shown in the figure, the consumer's client sends a test request to the mock tool, which sets the fixed baffle and dynamic baffle strategies. If the test request hits the baffle, the baffle result will be returned, and if it does not hit the baffle, it will be forwarded to the server. Since all test requests are sent to the mock tool, the consumer's client system has already performed relevant operations, causing the actual data to change, while those that hit the baffle are not forwarded to the server. At this time, the clearing party's server system has not performed relevant operations, which will not cause changes in the actual transaction data, resulting in inconsistencies in upstream and downstream transaction data, and the stability of the financial transaction platform and the friendliness of system interaction cannot be guaranteed.
[0004] Therefore, how to ensure the consistency of upstream and downstream transaction data while ensuring the stability of the financial transaction platform and the friendliness of system interaction is an urgent problem to be solved. Summary of the invention
[0005] Based on this, it is necessary to provide a mock testing method, system, computer equipment and medium based on bytecode injection to address the problem of inconsistency between upstream and downstream data.
[0006] A mock test method based on bytecode injection, the method comprising: upon receiving a mock test request, determining a target test scenario corresponding to the mock test request; judging whether there is a target test strategy corresponding to the target test scenario in a mapping relationship between pre-generated test scenarios and test strategies, and obtaining a judgment result; wherein the test strategy is generated by injecting preset rules into a JVM of a client system or a server system through a command line and bytecode injection technology; and generating a test result based on the judgment result, and sending it to a client for display.
[0007] In one of the embodiments, before determining the target test scenario corresponding to the mock test request, it also includes: determining each test scenario; starting a command line control panel for the JVM of the client system or the server system; receiving a target control command entered in the command line control panel for each test scenario; executing the target control command and generating a test strategy; establishing each test scenario and its test strategy, and obtaining a mapping relationship between a pre-generated test scenario identifier and a test strategy.
[0008] In one of the embodiments, a target control command entered in a command line control panel for each test scenario is received, including: when the test scenario is to simulate a specified return value of a function interface, determining a first rule for modifying the return value of an interface function in a server system, and entering the first rule as a target control command into the command line control panel to simulate different return values of the function interface in the server system; or, when the test scenario is to simulate a request timeout of a function interface, determining a second rule for a client system or a server system for specifying a timeout for calling a function interface, and entering the second rule as a target control command into the command line control panel to simulate the client or server discarding a request when a function interface request times out; or, when the test scenario is to simulate an interface call exception, determining a third rule for a client system for specifying a call to a function interface to throw an exception or for a server system for specifying a return of an exception to a function interface, and entering the third rule as a target control command into the command line control panel to simulate exception handling by the client or the server.
[0009] In one of the embodiments, determining a target test scenario corresponding to a mock test request includes: parsing the mock test request to obtain parsed data; matching data content corresponding to a preset test scenario keyword in the parsed data; and determining the target test scenario based on the matched data content.
[0010] In one of the embodiments, a test result is generated based on the judgment result, including: when there is a target test strategy corresponding to the target test scenario identifier, executing the exception handling logic corresponding to the target test strategy to generate an exception handling result; or, when there is no target test strategy corresponding to the target test scenario identifier, executing the original processing logic corresponding to the mock test request to generate a normal processing result.
[0011] In one of the embodiments, in the mapping relationship between pre-generated test scenarios and test policies, determining whether there is a target test policy corresponding to the target test scenario includes: determining whether there is a test scenario consistent with the target test scenario in the mapping relationship between pre-generated test scenarios and test policies; if there is a test scenario consistent with the target test scenario, determining whether there is a target test policy corresponding to the target test scenario in the mapping relationship between pre-generated test scenarios and test policies; or, if there is no test scenario consistent with the target test scenario, executing the original processing logic corresponding to the mock test request to generate a normal processing result.
[0012] In one of the embodiments, the method further includes: obtaining the exception type in each exception processing result; determining the exception level according to the exception type; and issuing an alarm message when the exception level is greater than a preset level threshold.
[0013] A mock test system based on bytecode injection, the system comprises: a target test scenario identification determination module, which is used to determine the target test scenario corresponding to the mock test request when receiving the mock test request; a target test strategy determination module, which is used to determine whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtain a determination result; wherein the test strategy is generated by injecting preset rules into the JVM of a client system or a server system through a command line and bytecode injection technology; and a test result display module, which is used to generate a test result based on the determination result and send it to a client for display.
[0014] A computer device includes a memory and a processor. The memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor executes the steps of the above-mentioned mock testing method based on bytecode injection.
[0015] A medium storing computer-readable instructions, when the computer-readable instructions are executed by one or more processors, causes the one or more processors to execute the steps of the above-mentioned mock testing method based on bytecode injection.
[0016] The above-mentioned mock test method, system, device and medium based on bytecode injection, the mock test system based on bytecode injection first determines the target test scenario corresponding to the mock test request when receiving the mock test request, and then judges whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtains the judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through the command line and bytecode injection technology, and finally generates the test result based on the judgment result and sends it to the client for display. Since the preset rules are directly injected into the JVM of the client system or the server system through the command line and bytecode injection technology during the mock test of the financial trading platform, the respective abnormal simulations of the bank, insurance, order and other trading systems under the financial trading platform during the test are controlled within the server system or the client system, thereby ensuring the consistency of upstream and downstream data. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0018] Figure 1 This is a diagram of an implementation environment of a mock testing method based on bytecode injection provided in one embodiment of the present application;
[0019] Figure 2 This is a schematic diagram of the internal structure of a computer device in one embodiment of the present application;
[0020] Figure 3 A schematic diagram of a mock test process in the prior art provided by the present application;
[0021] Figure 4 A schematic diagram of a mock testing method flow based on bytecode injection provided in one embodiment of the present application;
[0022] Figure 5 A schematic diagram of a test scenario provided in one embodiment of the present application for specifying a return value of a simulation function interface;
[0023] Figure 6 A test scenario provided in one embodiment of the present application is a schematic diagram of a situation where a function interface request times out;
[0024] Figure 7 Another test scenario provided in one embodiment of the present application is a schematic diagram of a situation where a function interface request times out;
[0025] Figure 8A test scenario provided in one embodiment of the present application is a schematic diagram of a situation in which an abnormal interface call is simulated;
[0026] Fig. 9 A test scenario provided in one embodiment of the present application is a schematic diagram of a situation in which an abnormal interface call is simulated;
[0027] Fig.10 A schematic diagram of a mock test process in an actual application scenario provided in one embodiment of the present application;
[0028] Fig.11 This is a schematic diagram of another mock testing method based on bytecode injection in this application;
[0029] Fig.12 It is a schematic diagram of the system structure of a mock testing system based on bytecode injection provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0031] It can be understood that the terms "first", "second", etc. used in the present application can be used in this article to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from another element.
[0032] Figure 1 FIG. 1 is an implementation environment diagram of a mock test method based on bytecode injection provided in an embodiment, such as Figure 1 As shown, in this implementation environment, a server 110 and a client 120 are included.
[0033] The server 110 can be a server, which can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms, such as a server device that performs mock test steps based on bytecode injection. When receiving a mock test request, the server 110 determines the target test scenario corresponding to the mock test request; the server 110 determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtains a judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through the command line and bytecode injection technology; the server 110 generates a test result based on the judgment result, and sends it to the client 120 for display.
[0034] It should be noted that the client 120 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The server 110 and the client 120 can be connected via Bluetooth, USB (Universal Serial Bus) or other communication connection methods, and the present invention does not limit this.
[0035] Figure 2 FIG. 1 is a schematic diagram of the internal structure of a computer device in one embodiment. Figure 2 As shown, the computer device includes a processor, a medium, a memory and a network interface connected via a system bus. Among them, the medium of the computer device stores an operating system, a database and computer-readable instructions, and the database may store a control information sequence. When the computer-readable instructions are executed by the processor, the processor can implement a mock testing method based on bytecode injection. The processor of the computer device is used to provide computing and control capabilities to support the operation of the entire device. The memory of the computer device may store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can execute a mock testing method based on bytecode injection. The network interface of the computer device is used to connect and communicate with a terminal. Those skilled in the art can understand that Figure 2 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components. The medium is a readable storage medium.
[0036] The following will be combined with the attached Figure 4-11 , a mock test method based on bytecode injection provided in an embodiment of the present application is introduced in detail. The method can be implemented by a computer program and can be run on a mock test system based on bytecode injection based on the von Neumann system. The computer program can be integrated into an application or run as an independent tool application.
[0037] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0038] The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, large-scale mock testing technology based on bytecode injection, operation / interaction systems, mechatronics, etc. Artificial intelligence software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0039] See also Figure 4 , which is a flowchart of a mock testing method based on bytecode injection for an embodiment of the present application. Figure 4 As shown, the method of the embodiment of the present application may include the following steps:
[0040] S101, upon receiving a mock test request, determining a target test scenario corresponding to the mock test request;
[0041] Among them, the mock test request is an instruction generated by the user according to the actual business scenario for the relevant functions triggered by the business system of the financial transaction platform. The financial service platform can be the system of different banks such as Bank of Beijing, Ping An Bank, and Pudong Development Bank. The instruction can be issued for different test scenarios (such as transaction scenarios, clearing scenarios, and transaction data security scenarios). The test scenarios can include simulated function interface specified return values, simulated function interface request timeouts, and simulated interface call exceptions, and can also be other test scenarios, which are not listed one by one here.
[0042] In an embodiment of the present application, when determining the target test scenario corresponding to the mock test request, the mock test request is first parsed to obtain parsed data, and then the data content corresponding to the preset test scenario keyword is matched in the parsed data, and finally the target test scenario is determined based on the matched data content.
[0043] Specifically, when determining the target test scene based on the matched data content, a pre-trained test scene recognition model can be called, and then the matched data content is input into the pre-trained test scene recognition model for semantic recognition, and the target test scene can be obtained after recognition. In addition, other test scene recognition methods in the prior art can also be used, which will not be repeated here.
[0044] In one possible implementation, the user generates a mock test request on the client side according to the relevant functions triggered by the actual business scenario, and sends the request to the server side. When the server side receives the mock test request, it can parse the mock test request and finally determine the target test scenario corresponding to the mock test request based on the parsed data.
[0045] S102, judging whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and test strategies, and obtaining a judgment result;
[0046] Among them, the test strategy is generated by injecting preset rules into the JVM of the client system or server system through command line and bytecode injection technology; it should be noted that the client system in this application is the requester system in the microservice, and the server system is the service provider system in the microservice.
[0047] In an embodiment of the present application, when constructing a mapping relationship between pre-generated test scenarios and test strategies, each test scenario is first determined, and then the command line control panel is started for the JVM of the client system or the server system. Next, the target control command entered in the command line control panel for each test scenario is received, and then the target control command is executed to generate a test strategy. Finally, each test scenario and its test strategy are established to obtain a mapping relationship between the pre-generated test scenario identifier and the test strategy.
[0048] Specifically, when receiving the target control command entered in the command line control panel for each test scenario, when the test scenario is to simulate the return value of the function interface, a first rule for modifying the return value of the interface function in the server system is determined, and the first rule is input into the command line control panel as the target control command to simulate different return values of the function interface in the server system; or, when the test scenario is to simulate the timeout of the function interface request, a second rule for specifying the timeout of calling the function interface for the client system or the server system is determined, and the second rule is input into the command line control panel as the target control command to simulate the client or server discarding the request when the function interface request times out; or, when the test scenario is to simulate the interface call exception, a third rule for specifying the throwing of an exception for calling the function interface for the client system or the returning of an exception for the specified function interface for the server system is determined, and the third rule is input into the command line control panel as the target control command to simulate exception handling of the client or the server.
[0049] For example Figure 5 As shown, Figure 5 This application provides a test scenario for simulating the specified return value of a function interface. The user injects the specified function return value into the JVM (Java Virtual Machine) of the service system through the command line to achieve the purpose of simulating different return values of the interface, thereby ensuring the integrity of the interface return value test. Since the function return value is modified on the service side through the behavior injection mode, the consistency of the request data between the service side and the requester can be guaranteed, and there will be no inconsistency in the upstream and downstream data status.
[0050] For example Figure 6 As shown, Figure 6 The present application provides a test scenario for simulating a function interface request timeout situation, in which the requester times out and the service provider does not receive the request; the user injects a command into the requester's JVM and specifies a timeout for calling the interface function; after the actual request is sent, the injection rule is hit, the requester calls the timeout and discards the request, completing the timeout simulation.
[0051] For example Figure 7 As shown, Figure 7 Another test scenario provided by this application is to simulate the timeout of a function interface request. The service party times out. After receiving the request, the service party processes the timeout. There are many possibilities for the actual processing result, including success, failure, and processing. By injecting the command line into the service party's JVM, the function delay parameter is specified to achieve the simulated interface processing timeout. By modifying the return value of the processing function through combined injection, the actual execution result after the timeout can be specified.
[0052] For example Figure 8 As shown, Figure 8The present application provides a test scenario for simulating an interface call exception, in which the requester calls the exception and the service provider does not receive the request. The command line is injected into the requester's JVM to specify that the calling interface throws an exception (the exception type can be specified). After the actual request is sent, the injection rule is hit, triggering the interface call exception, and the exception handling logic can be tested.
[0053] For example Fig. 9 As shown, Fig. 9 The present application provides a test scenario to simulate an interface call exception. The service party returns a specific exception and injects it into the service party's jvm through the command line, and specifies the interface to return an exception (the exception type can be specified). After the service party receives the interface request, it hits the injection rule and directly returns the exception specified by the caller, which can test the exception handling logic.
[0054] In an embodiment of the present application, when determining whether there is a target test policy corresponding to the target test scenario in the mapping relationship between pre-generated test scenarios and test policies, it is determined whether there is a test scenario consistent with the target test scenario in the mapping relationship between pre-generated test scenarios and test policies; if there is a test scenario consistent with the target test scenario, it is determined whether there is a target test policy corresponding to the target test scenario in the mapping relationship between pre-generated test scenarios and test policies; alternatively, if there is no test scenario consistent with the target test scenario, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
[0055] S103, generating a test result based on the judgment result, and sending it to the client for display.
[0056] In an embodiment of the present application, when generating test results based on the judgment results, when there is a target test strategy corresponding to the target test scenario identifier, the exception handling logic corresponding to the target test strategy is executed to generate an exception handling result; or, when there is no target test strategy corresponding to the target test scenario identifier, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
[0057] Furthermore, after obtaining the exception handling result, firstly, the exception type in each exception handling result is obtained, then the exception level is determined according to the exception type, and finally, when the exception level is greater than a preset level threshold, an alarm message is issued.
[0058] For example Fig.10 As shown, Fig.10It is a mock test process in an actual application scenario provided by this application. At this time, the client system (i.e., the requesting system) is the points payment system, and the server system (i.e., the service system) is the points core system. At this time, the user injects fault rules into the points core system, and then the points payment system issues a deduction request to the points core system, and draws numbers from the points payment system to obtain daily deduction transactions. At this time, it is determined whether the fault rule is hit. If so, the exception processing logic is performed. If not, the normal processing logic is performed. After the result is finally obtained, it is convenient for the enterprise to settle. Finally, the settlement records and daily deduction transactions are reconciled and scheduled on a daily basis, and the final result is fed back to the client.
[0059] In an embodiment of the present application, the mock test system based on bytecode injection first determines the target test scenario corresponding to the mock test request when receiving the mock test request, and then determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtains the judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through the command line and bytecode injection technology, and finally generates the test result based on the judgment result, and sends it to the client for display. Since the preset rules are directly injected into the JVM of the client system or the server system through the command line and bytecode injection technology during the mock test of the financial trading platform, the respective abnormal simulations of the trading systems such as banks, insurance, and orders under the financial trading platform in the test are controlled in the server system or the client system, thereby ensuring the consistency of upstream and downstream data.
[0060] See also Fig.11 , which is a flowchart of a mock testing method based on bytecode injection for an embodiment of the present application. Fig.11 As shown, the method of the embodiment of the present application may include the following steps:
[0061] S201, determining each test scenario;
[0062] S202, starting a command line control panel for the JVM of the client system or the server system;
[0063] S203, receiving a target control command input in the command line control panel for each test scenario;
[0064] S204, executing the target control command and generating a test strategy;
[0065] S205, establishing each test scenario and its test strategy, and obtaining a mapping relationship between a pre-generated test scenario identifier and a test strategy;
[0066] S206, upon receiving the mock test request, determining a target test scenario corresponding to the mock test request;
[0067] S207, judging whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtaining a judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through command line and bytecode injection technology;
[0068] S208, when there is a target test strategy corresponding to the target test scenario identifier, execute the exception handling logic corresponding to the target test strategy to generate an exception handling result; or, when there is no target test strategy corresponding to the target test scenario identifier, execute the original processing logic corresponding to the mock test request to generate a normal processing result.
[0069] In an embodiment of the present application, the mock test system based on bytecode injection first determines the target test scenario corresponding to the mock test request when receiving the mock test request, and then determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtains the judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through the command line and bytecode injection technology, and finally generates the test result based on the judgment result, and sends it to the client for display. Since the preset rules are directly injected into the JVM of the client system or the server system through the command line and bytecode injection technology during the mock test of the financial trading platform, the respective abnormal simulations of the trading systems such as banks, insurance, and orders under the financial trading platform in the test are controlled in the server system or the client system, thereby ensuring the consistency of upstream and downstream data.
[0070] The following is a system embodiment of the present invention, which can be used to implement the method embodiment of the present invention. For details not disclosed in the system embodiment of the present invention, please refer to the method embodiment of the present invention.
[0071] See also Fig.12 , which shows a schematic diagram of the structure of a mock test system based on bytecode injection provided by an exemplary embodiment of the present invention. The mock test system based on bytecode injection can be implemented as all or part of a device through software, hardware or a combination of both. The system 1 includes a target test scenario identification determination module 10, a target test strategy determination module 20, and a test result display module 30.
[0072] A target test scenario identification determination module 10 is used to determine the target test scenario corresponding to the mock test request when a mock test request is received;
[0073] The target test strategy determination module 20 is used to determine whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and test strategies, and obtain a determination result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through command line and bytecode injection technology;
[0074] The test result display module 30 is used to generate the test result based on the judgment result and send it to the client for display.
[0075] It should be noted that the mock test system based on bytecode injection provided in the above embodiment only uses the division of the above functional modules as an example when executing the mock test method based on bytecode injection. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the mock test system based on bytecode injection provided in the above embodiment and the mock test method based on bytecode injection belong to the same concept. The implementation process is detailed in the method embodiment, which will not be repeated here.
[0076] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0077] In an embodiment of the present application, the mock test system based on bytecode injection first determines the target test scenario corresponding to the mock test request when receiving the mock test request, and then determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtains the judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through the command line and bytecode injection technology, and finally generates the test result based on the judgment result, and sends it to the client for display. Since the preset rules are directly injected into the JVM of the client system or the server system through the command line and bytecode injection technology during the mock test of the financial trading platform, the respective abnormal simulations of the trading systems such as banks, insurance, and orders under the financial trading platform in the test are controlled in the server system or the client system, thereby ensuring the consistency of upstream and downstream data.
[0078] In one embodiment, a computer device is provided, the device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0079] When receiving a mock test request, determine the target test scenario corresponding to the mock test request;
[0080] In the mapping relationship between the pre-generated test scenarios and test strategies, it is determined whether there is a target test strategy corresponding to the target test scenario, and a determination result is obtained; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through command line and bytecode injection technology;
[0081] Generate test results based on the judgment results and send them to the client for display.
[0082] In one embodiment, before the processor determines the target test scenario corresponding to the mock test request, the processor further performs the following operations:
[0083] Identify each test scenario;
[0084] Launch the command line control panel for the JVM of the client system or server system;
[0085] receiving target control commands input in the command line control panel for each test scenario;
[0086] Execute target control commands and generate test strategies;
[0087] Each test scenario and its test strategy are established to obtain a mapping relationship between a pre-generated test scenario identifier and a test strategy.
[0088] In one embodiment, when the processor receives the target control command input in the command line control panel for each test scenario, the processor specifically performs the following operations:
[0089] In the case where the test scenario specifies a return value for a simulated function interface, a first rule for modifying the return value of the interface function in the server system is determined, and the first rule is input into the command line control panel as a target control command to simulate different return values of the function interface in the server system; or
[0090] In the case where the test scenario is to simulate a function interface request timeout, determine a second rule for the client system or the server system for specifying a timeout for calling the function interface, and input the second rule into the command line control panel as a target control command to simulate the client or the server discarding the request when the function interface request times out; or,
[0091] When the test scenario is to simulate an interface call exception, determine a third rule for throwing an exception on the client system for specifying a call function interface or for returning an exception on the server system for specifying a function interface, and enter the third rule as a target control command into the command line control panel to simulate exception handling on the client or server.
[0092] In one embodiment, when the processor determines the target test scenario corresponding to the mock test request, the following operations are specifically performed:
[0093] Parse the mock test request and obtain the parsed data;
[0094] Match the data content corresponding to the preset test scenario keywords in the parsed data;
[0095] Determine the target test scenario based on the matched data content.
[0096] In one embodiment, when the processor generates a test result based on the judgment result, the processor specifically performs the following operations:
[0097] When there is a target test strategy corresponding to the target test scenario identifier, the exception handling logic corresponding to the target test strategy is executed to generate an exception handling result;
[0098] or,
[0099] When there is no target test strategy corresponding to the target test scenario identifier, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
[0100] In one embodiment, when the processor determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and the test strategies, the processor specifically performs the following operations:
[0101] Determine whether there is a test scenario consistent with the target test scenario in the mapping relationship between the pre-generated test scenarios and the test strategies;
[0102] If there is a test scenario that is consistent with the target test scenario, determine whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and test strategies;
[0103] or,
[0104] If there is no test scenario that is consistent with the target test scenario, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
[0105] In one embodiment, the processor further performs the following operations:
[0106] Get the exception type in each exception handling result;
[0107] Determine the abnormality level according to the abnormality type;
[0108] When the abnormal level is greater than the preset level threshold, an alarm message is issued.
[0109] In an embodiment of the present application, the mock test system based on bytecode injection first determines the target test scenario corresponding to the mock test request when receiving the mock test request, and then determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtains the judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through the command line and bytecode injection technology, and finally generates the test result based on the judgment result, and sends it to the client for display. Since the preset rules are directly injected into the JVM of the client system or the server system through the command line and bytecode injection technology during the mock test of the financial trading platform, the respective abnormal simulations of the trading systems such as banks, insurance, and orders under the financial trading platform in the test are controlled in the server system or the client system, thereby ensuring the consistency of upstream and downstream data.
[0110] In one embodiment, a medium storing computer-readable instructions is provided. When the computer-readable instructions are executed by one or more processors, the one or more processors perform the following steps:
[0111] When receiving a mock test request, determine the target test scenario corresponding to the mock test request;
[0112] In the mapping relationship between the pre-generated test scenarios and test strategies, it is determined whether there is a target test strategy corresponding to the target test scenario, and a determination result is obtained; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through command line and bytecode injection technology;
[0113] Generate test results based on the judgment results and send them to the client for display.
[0114] In one embodiment, before the processor determines the target test scenario corresponding to the mock test request, the processor further performs the following operations:
[0115] Identify each test scenario;
[0116] Launch the command line control panel for the JVM of the client system or server system;
[0117] receiving target control commands input in the command line control panel for each test scenario;
[0118] Execute target control commands and generate test strategies;
[0119] Each test scenario and its test strategy are established to obtain a mapping relationship between the pre-generated test scenario identifier and the test strategy.
[0120] In one embodiment, when the processor receives the target control command input in the command line control panel for each test scenario, the processor specifically performs the following operations:
[0121] In the case where the test scenario specifies a return value for a simulated function interface, a first rule for modifying the return value of the interface function in the server system is determined, and the first rule is input into the command line control panel as a target control command to simulate different return values of the function interface in the server system; or
[0122] In the case where the test scenario is to simulate a function interface request timeout, determine a second rule for the client system or the server system for specifying a timeout for calling the function interface, and input the second rule into the command line control panel as a target control command to simulate the client or the server discarding the request when the function interface request times out; or,
[0123] When the test scenario is to simulate an interface call exception, determine a third rule for throwing an exception on the client system for specifying a call function interface or for returning an exception on the server system for specifying a function interface, and enter the third rule as a target control command into the command line control panel to simulate exception handling on the client or server.
[0124] In one embodiment, when the processor determines the target test scenario corresponding to the mock test request, the following operations are specifically performed:
[0125] Parse the mock test request and obtain the parsed data;
[0126] Match the data content corresponding to the preset test scenario keywords in the parsed data;
[0127] Determine the target test scenario based on the matched data content.
[0128] In one embodiment, when the processor generates a test result based on the judgment result, the processor specifically performs the following operations:
[0129] When there is a target test strategy corresponding to the target test scenario identifier, the exception handling logic corresponding to the target test strategy is executed to generate an exception handling result;
[0130] or,
[0131] When there is no target test strategy corresponding to the target test scenario identifier, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
[0132] In one embodiment, when the processor determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and the test strategies, the processor specifically performs the following operations:
[0133] Determine whether there is a test scenario consistent with the target test scenario in the mapping relationship between the pre-generated test scenarios and the test strategies;
[0134] If there is a test scenario that is consistent with the target test scenario, determine whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and test strategies;
[0135] or,
[0136] If there is no test scenario that is consistent with the target test scenario, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
[0137] In one embodiment, the processor further performs the following operations:
[0138] Get the exception type in each exception handling result;
[0139] Determine the abnormality level according to the abnormality type;
[0140] When the abnormal level is greater than the preset level threshold, an alarm message is issued.
[0141] In an embodiment of the present application, the mock test system based on bytecode injection first determines the target test scenario corresponding to the mock test request when receiving the mock test request, and then determines whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtains the judgment result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through the command line and bytecode injection technology, and finally generates the test result based on the judgment result, and sends it to the client for display. Since the preset rules are directly injected into the JVM of the client system or the server system through the command line and bytecode injection technology during the mock test of the financial trading platform, the respective abnormal simulations of the trading systems such as banks, insurance, and orders under the financial trading platform in the test are controlled in the server system or the client system, thereby ensuring the consistency of upstream and downstream data.
[0142] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The above-mentioned medium can be a non-volatile medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0143] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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.
[0144] The above embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present invention. It should be pointed out that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention patent shall be subject to the attached claims.
Claims
1. A mock testing method based on bytecode injection, It is characterized in that The method comprises: Upon receiving a mock test request, determining a target test scenario corresponding to the mock test request; In the mapping relationship between the pre-generated test scenario and the test strategy, determine whether there is a target test strategy corresponding to the target test scenario, and obtain a determination result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through command line and bytecode injection technology; A test result is generated based on the judgment result and sent to the client for display.
2. The method according to claim 1, It is characterized in that Before determining the target test scenario corresponding to the mock test request, the method further includes: Identify each test scenario; Launching a command line control panel for the JVM of the client system or the server system; Receiving a target control command input in the command line control panel for each test scenario; Execute the target control command to generate a test strategy; Each test scenario and its test strategy are established to obtain a mapping relationship between the pre-generated test scenario identifier and the test strategy.
3. The method according to claim 2, It is characterized in that The receiving a target control command input in the command line control panel for each test scenario includes: In the case where the test scenario specifies a return value for a simulated function interface, determining a first rule for modifying the return value of an interface function in the server system, and inputting the first rule as a target control command into the command line control panel to simulate different return values of the function interface in the server system; or In the case where the test scenario is to simulate a function interface request timeout, determining a second rule for the client system or the server system for specifying a timeout for calling a function interface, and inputting the second rule into the command line control panel as a target control command to simulate the client or server discarding the request when the function interface request times out; or When the test scenario is to simulate an interface call exception, a third rule is determined for throwing an exception on the client system for specifying a call function interface or for returning an exception on the server system for specifying a function interface, and the third rule is input into the command line control panel as a target control command to simulate exception handling on the client or server.
4. The method according to claim 1, It is characterized in that The determining a target test scenario corresponding to the mock test request includes: Parse the mock test request to obtain parsed data; Matching data content corresponding to preset test scenario keywords in the parsed data; Determine the target test scenario based on the matched data content.
5. The method according to claim 1, It is characterized in that The generating of the test result based on the judgment result comprises: When there is a target test strategy corresponding to the target test scenario identifier, executing the exception handling logic corresponding to the target test strategy to generate an exception handling result; or, When there is no target test strategy corresponding to the target test scenario identifier, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
6. The method according to claim 1, It is characterized in that The determining whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and the test strategies includes: Determine whether there is a test scenario consistent with the target test scenario in the mapping relationship between the pre-generated test scenarios and the test strategies; If there is a test scenario that is consistent with the target test scenario, determining whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenarios and test strategies; or, If there is no test scenario consistent with the target test scenario, the original processing logic corresponding to the mock test request is executed to generate a normal processing result.
7. The method according to claim 5, It is characterized in that The method further comprises: Get the exception type in each exception handling result; Determining an abnormality level according to the abnormality type; When the abnormal level is greater than the preset level threshold, an alarm message is issued.
8. A mock testing system based on bytecode injection, It is characterized in that The system comprises: A target test scenario identification determination module is used to determine the target test scenario corresponding to the mock test request when receiving the mock test request; A target test strategy determination module is used to determine whether there is a target test strategy corresponding to the target test scenario in the mapping relationship between the pre-generated test scenario and the test strategy, and obtain a determination result; wherein the test strategy is generated by injecting preset rules into the JVM of the client system or the server system through command line and bytecode injection technology; The test result display module is used to generate the test result based on the judgment result and send it to the client for display.
9. A computer device, It is characterized in that The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the steps of the mock testing method based on bytecode injection as claimed in any one of claims 1 to 7.
10. A medium storing computer-readable instructions, It is characterized in that When the computer-readable instructions are executed by one or more processors, the one or more processors are caused to perform the steps of the mock test based on bytecode injection as claimed in any one of claims 1 to 7.
