A microservice gateway mock testing method, device and storage medium
The mock testing method based on the microservice gateway solves the problem of low testing efficiency caused by incomplete or unregistered target microservices. It also enables data to be obtained through mock services when microservices are not registered, ensuring the normal progress of testing and improving efficiency.
Patent Information
- Application Number
- CN202310006083.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-04
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2043-01-04
AI Technical Summary
In a microservice architecture, incomplete or unregistered target microservices lead to low mock testing efficiency, affecting the normal progress of development and testing.
Through the mock testing method based on the microservice gateway, the request message is received, the identifier is parsed, and the registration status of the target microservice label is queried. If it is not registered, the request message is sent to the mock service to obtain data to ensure that the data is returned.
This improves the efficiency of mock testing, avoids the situation where data cannot be returned due to the target microservice not being registered, and ensures the normal progress of the test.
Smart Images

Figure CN116016271B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automatic programming, and in particular to a microservice gateway mock testing method, device and storage medium. Background Art
[0002] As system workloads and complexity increase, the backend transitions from a monolithic service architecture to a microservices architecture, making front-end and back-end development, debugging, and integration testing increasingly challenging. To improve development and testing efficiency, mock testing of dependent services and interfaces is necessary.
[0003] During the mock test process, if the target microservice is not properly registered with the registration center because it has not been completed or the development progress has been delayed, calling the target microservice will result in the target microservice not being found in the registration center. As a result, a microservice in the series of tests cannot return data, affecting the normal progress of the mock test and resulting in low test efficiency. Summary of the Invention
[0004] In response to the above-mentioned problems in the prior art, the purpose of this article is to provide a mock testing method, device and storage medium based on a microservice gateway to solve the problem in the prior art that the target microservice is not completed, affecting the normal progress of the mock test and thus leading to low test efficiency.
[0005] In order to solve the above technical problems, the specific technical solutions of this article are as follows:
[0006] On the one hand, this article provides a microservice gateway mock testing method, including:
[0007] Receive a request message, wherein the request message is used to call a microservice;
[0008] Parsing the identifier of the request message, and when the identifier is a first-class identifier, parsing to obtain a list of microservices called by the request message, the list of microservices including several target microservice labels;
[0009] Query whether all the target microservice labels are registered in the microservice gateway. If there are unregistered microservices, send the microservice label corresponding to the unregistered microservice and the request message to the mock service to obtain the data returned by the mock service.
[0010] As an embodiment of this invention, after querying whether all the target microservice labels are registered in the microservice gateway, the method includes:
[0011] If the target microservice number is registered in the microservice gateway, the request message is sent to the corresponding target microservice according to the microservice number corresponding to the microservice, and the data returned by the target microservice is obtained.
[0012] As an embodiment of this article, the data returned by the target microservice further includes:
[0013] When the time threshold is exceeded and no data returned by the target microservice is received, the microservice label corresponding to the target microservice and the request message are sent to the mock service to obtain the data returned by the mock service.
[0014] As an embodiment of this document, after parsing the identifier of the request message, the method includes:
[0015] When the identifier is a second type identifier, the request message is forwarded to the mock service to obtain data returned by the mock service.
[0016] As an embodiment of this invention, obtaining the data returned by the mock service further includes:
[0017] When the time threshold is exceeded and no data returned by the mock service is received, first mock service exception information is reported.
[0018] As an embodiment of this invention, after obtaining the data returned by the mock service, the method includes:
[0019] Perform regular expression matching on the data returned by the mock service and the preset result corresponding to the request message;
[0020] If no match is found, the second mock service exception information is reported.
[0021] As an embodiment of this invention, the querying whether all the target microservice labels are registered in the microservice gateway further includes:
[0022] Use the target microservice label to match the microservice label pre-stored in the microservice gateway;
[0023] If the match is successful, the target microservice number is registered in the microservice gateway;
[0024] If the match is unsuccessful, the target microservice number is not registered in the microservice gateway.
[0025] On the other hand, this article also provides a microservice gateway mock test device, including:
[0026] A receiving unit, configured to receive a request message, wherein the request message is used to call a microservice;
[0027] a parsing unit, configured to parse the identifier of the request message, and when the identifier is a first type identifier, parse to obtain a list of microservices invoked by the request message, the list of microservices including a number of target microservice labels;
[0028] The query unit is used to query whether all the target microservice labels are registered in the microservice gateway. If there are unregistered microservices, the microservice label corresponding to the unregistered microservice and the request message are sent to the mock service to obtain the data returned by the mock service.
[0029] On the other hand, this article also provides a computer device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor, wherein when the processor executes the computer program, any one of the microservice gateway mock testing methods described is implemented.
[0030] On the other hand, this article also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements any one of the microservice gateway mock testing methods described above.
[0031] By adopting the above technical solution, by receiving a request message, wherein the request message is used to call a microservice, it is possible to obtain a request message for calling a series of microservices; by parsing the identifier of the request message, when the identifier is a first-class identifier, the list of microservices called by the request message is obtained by parsing, and the microservice list includes several target microservice labels, which can achieve distinguishing and parsing request messages and improve parsing efficiency; by querying whether all the target microservice labels are registered in the microservice gateway, if there is an unregistered microservice, the microservice label corresponding to the unregistered microservice and the request message are sent to the mock service, and the data returned by the mock service is obtained. When the microservice is not registered, the request message can be forwarded to the mock service, and then the data required for the mock test can be obtained, thereby avoiding the situation where data cannot be returned, improving the test efficiency, and ensuring the normal progress of the mock test.
[0032] In order to make the above and other purposes, features and advantages of this article more obvious and easy to understand, the following specifically cites preferred embodiments and provides detailed descriptions in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of this article or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of this article. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0034] Figure 1 This figure shows an overall system diagram of a microservice gateway mock testing method according to an embodiment of this invention;
[0035] Figure 2 The following is a schematic diagram showing the steps of a microservice gateway mock testing method according to an embodiment of the present invention;
[0036] Figure 3 A schematic diagram of the microservice number query process according to the embodiment of this article is shown;
[0037] Figure 4 A schematic diagram of a mock testing device based on a microservice gateway according to an embodiment of this invention is shown;
[0038] Figure 5 A schematic diagram of a computer device according to an embodiment of the present invention is shown.
[0039] Description of the accompanying symbols:
[0040] 101. First microservice gateway;
[0041] 102. Second microservice gateway;
[0042] 103. Microservice side;
[0043] 104. mock end;
[0044] 401, receiving unit;
[0045] 402, parsing unit;
[0046] 403, query unit;
[0047] 502. Computer equipment;
[0048] 504, processor;
[0049] 506. Memory;
[0050] 508, driving mechanism;
[0051] 510, input / output module;
[0052] 512. Input devices;
[0053] 514. Output device;
[0054] 516. Presentation equipment;
[0055] 518. Graphical User Interface;
[0056] 520, network interface;
[0057] 522, communication link;
[0058] 524. Communication bus. DETAILED DESCRIPTION
[0059] The following will be combined with the accompanying drawings to clearly and completely describe the technical solutions in the embodiments of this document. Obviously, the embodiments described are only part of the embodiments of this document, not all of the embodiments. Based on the embodiments of this document, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this document.
[0060] It should be noted that the terms "first," "second," and the like in the specification and claims herein and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, apparatus, product, or device comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or devices.
[0061] like Figure 1 The overall system diagram shown is based on a microservice gateway mock testing method, including: a first microservice gateway 101, a second microservice gateway 102, a microservice end 103 and a mock end 104.
[0062] The first microservice gateway 101 is used to receive the request message and forward it to the second microservice gateway 102.
[0063] The second microservice gateway 102 is used to receive the request message and determine the identifier of the request message. In this article, the identifier includes a first-class identifier and a second-class identifier. The first-class identifier indicates that the request message includes a series of test requests. For example, the request message belonging to the first-class identifier is a loan request. When processing a loan for a customer, the customer needs to be verified, the loan amount is measured, and the loan process is carried out in sequence. In this article, the verification process uses an independent microservice, the loan amount measurement process uses an independent microservice, and the loan process uses an independent microservice. The second microservice gateway 102 is connected to all microservice terminals 103 and mock terminals 104, and can send request messages to the microservice terminals 103 and mock terminals 104, and obtain data from the microservice terminals 103 and mock terminals 104. After receiving the request message, if the request message is a first-class identifier, the second microservice gateway 102 determines whether all the microservices required by the request message are registered. If all are registered, the request message is sent to the corresponding microservice end 103. If there is an unregistered microservice, the request message is forwarded to the mock end 104 to use the mock service to replace the unregistered microservice to respond to the request message.
[0064] The microservice end 103 is used to run microservices.
[0065] The mock terminal 104 is used to run the mock service.
[0066] During the mock test process, if the target microservice is not properly registered with the registration center because it has not been completed or the development progress has been delayed, calling the target microservice will result in the target microservice not being found in the registration center. As a result, a microservice in the series of tests cannot return data, affecting the normal progress of the mock test and resulting in low test efficiency.
[0067] In order to solve the above problems, the embodiment of this article provides a mock testing method based on a microservice gateway, which can solve the problem in the prior art that the target microservice is not completed, affecting the normal progress of the mock test, and thus resulting in low test efficiency. Figure 2 This is a step diagram of a microservice gateway mock test method provided in the embodiment of this article. This specification provides the method operation steps as described in the embodiment or flowchart, but it may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the steps among many steps, and does not represent the only execution order. When the actual system or device product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiment or the accompanying drawings. Specifically, Figure 2 As shown, the method may include:
[0068] Step 201: Receive a request message, where the request message is used to call a microservice.
[0069] Step 202: Parse the identifier of the request message. When the identifier is a first-class identifier, parse to obtain a list of microservices called by the request message. The list of microservices includes several target microservice labels.
[0070] Step 203: Check whether all the target microservice labels are registered in the microservice gateway. If there are unregistered microservices, send the microservice label corresponding to the unregistered microservice and the request message to the mock service to obtain the data returned by the mock service.
[0071] By adopting the above technical solution, by receiving a request message, wherein the request message is used to call a microservice, it is possible to obtain a request message for calling a series of microservices; by parsing the identifier of the request message, when the identifier is a first-class identifier, the list of microservices called by the request message is obtained by parsing, and the microservice list includes several target microservice labels, which can achieve distinguishing and parsing request messages and improve parsing efficiency; by querying whether all the target microservice labels are registered in the microservice gateway, if there is an unregistered microservice, the microservice label corresponding to the unregistered microservice and the request message are sent to the mock service, and the data returned by the mock service is obtained. When the microservice is not registered, the request message can be forwarded to the mock service, and then the data required for the mock test can be obtained, thereby avoiding the situation where data cannot be returned, improving the test efficiency, and ensuring the normal progress of the mock test.
[0072] In this article, the request message includes a request segment, an identification segment and a microservice list. The request segment includes several request parameters. After sending the request segment to the microservice end or the mock end, the microservice end or the mock end can calculate and return the corresponding data based on the request parameters. The identification segment is composed of UID, which represents the type of the request message. The microservice list includes several target microservice labels. In this article, the microservice label can correspond to the interface label of each microservice end. The microservice gateway can use the interface label to forward the request segment to the corresponding microservice end, and then obtain the data returned by each microservice. Of course, in some cases, if some microservices are not completed, the microservice gateway can send the request parameters sent to the microservice end to the mock end, so that the mock takes over the microservice response request message and returns the data.
[0073] As an embodiment of this invention, in step 202, the identifier of the request message is parsed. When the identifier is a first-class identifier, the microservice list called by the request message is obtained by parsing. The microservice list includes several target microservice labels and further includes:
[0074] In this step, after parsing the identifier of the request message, a first-class identifier or a second-class identifier can be obtained. In this article, the first-class identifier indicates that the request message requires the cooperation of multiple microservices to complete and obtain a series of data. The second-class identifier indicates that the request message only requires a microservice to return a separate data to complete. For example, the request message requires the microservice to return a status value, and the status value can make the web page present a different page. Since the tester does not need to generate a real web page during the test process, a status value can be provided by the mock service when a separate status value needs to be returned. Therefore, when the request message is the second-class identifier, the request parameters in the request message can be redirected to the mock service to complete the test, which greatly improves the test efficiency of the tester.
[0075] Specifically, when the identifier is a second type identifier, the request message is forwarded to the mock service, and data returned by the mock service is obtained.
[0076] Of course, in some cases, the mock service may fail to return data within the specified time, so this article provides a solution. Specifically:
[0077] When the time threshold is exceeded and no data returned by the mock service is received, the first mock service exception information is reported. In this way, the tester can be reminded that the mock service has an exception and needs to be operated and maintained. In this article, the first mock service exception information indicates that the mock service has a delayed response.
[0078] In this article, all request messages fall into the first category. Therefore, each request message contains at least two server labels in the microservice list. Therefore, the request parameters must be sent to the two microservices sequentially, in parallel, or randomly. To ensure that the request message can successfully retrieve data and complete its execution, both microservices must provide at least two pieces of data. If one microservice encounters an exception or is incomplete, another service must take over and return data to complete the request message.
[0079] To achieve the above effect, the microservice gateway in this paper stores a dynamically updated registry. When a microservice is online or completed, its number is registered in the registry. Conversely, if a microservice is not registered in the registry, it is not completed.
[0080] like Figure 3 The microservice label query process diagram shown in the figure is an embodiment of this article. The steps of querying whether all the target microservice labels are registered in the microservice gateway specifically include:
[0081] Step 301: Use the target microservice label to match the microservice label pre-stored in the microservice gateway;
[0082] Step 302: If the match is successful, the target microservice number is registered in the microservice gateway;
[0083] Step 303: If the match is unsuccessful, the target microservice number is not registered in the microservice gateway.
[0084] The registration table is shown in Table 1.
[0085] Table 1
[0086] Microservice label Interface address 01 198.***.0.0 02 198.***.0.1 03 198.***.1.0 04 198.***.1.1
[0087] In the table, you can see that each registered microservice has its own unique label, and each microservice corresponds to an interface address. After the microservice gateway receives the request parameters, it can send the request parameters to the corresponding microservice end according to the interface address.
[0088] Table 2 shows the microservice list of a request message.
[0089] Table 2
[0090] Target microservice label 01 02 05
[0091] On the other hand, if the target microservice number is registered in the microservice gateway, the request message is sent to the corresponding target microservice according to the microservice number corresponding to the microservice, and the data returned by the target microservice is obtained.
[0092] Specifically, the microservice number corresponds to the interface IP of the microservice end, so it is only necessary to send the request parameters to the corresponding microservice end through the interface IP, and the microservice in the microservice end can use the request parameters to perform operations and obtain data.
[0093] Similarly, if a microservice encounters an exception and cannot obtain data, the request parameters can be sent to the mock end to obtain the data returned by the mock service. Specifically, if the time threshold is exceeded and no data is received from the target microservice, the microservice label corresponding to the target microservice and the request message are sent to the mock service to obtain the data returned by the mock service.
[0094] In one case, as can be seen from Table 2, the target microservices of the request message are numbered 01, 02, and 05.
[0095] Traverse and match 01, 02, and 05 with all the microservice labels in Table 1 in turn. Finally, according to Table 1, the microservice with microservice label 01 has completed registration, the microservice with microservice label 02 has completed registration, and the microservice with microservice label 05 has not completed registration. Therefore, a mock service needs to be used to replace the microservice with microservice label 05 to return data.
[0096] As an embodiment of this invention, in some cases, due to an error in the mock service or microservice, although each service can return data, the returned data may be erroneous. Therefore, after obtaining the data returned by the mock service, the following steps are included:
[0097] Perform regular expression matching on the data returned by the mock service and the preset result corresponding to the request message;
[0098] If no match is found, the second mock service exception information is reported. In this article, the second mock service exception information indicates a mock service operation error.
[0099] In this way, the probability of errors can be further reduced and the testing efficiency can be improved.
[0100] like Figure 4 The schematic diagram of a microservice gateway mock test device shown includes:
[0101] The receiving unit 401 is configured to receive a request message, wherein the request message is used to call a microservice;
[0102] The parsing unit 402 is configured to parse the identifier of the request message, and when the identifier is a first type identifier, parse to obtain a list of microservices invoked by the request message, the list of microservices including a number of target microservice labels;
[0103] The query unit 403 is used to query whether all the target microservice labels are registered in the microservice gateway. If there are unregistered microservices, the microservice label corresponding to the unregistered microservice and the request message are sent to the mock service to obtain the data returned by the mock service.
[0104] By adopting the above technical solution, by receiving a request message, wherein the request message is used to call a microservice, it is possible to obtain a request message for calling a series of microservices; by parsing the identifier of the request message, when the identifier is a first-class identifier, the list of microservices called by the request message is obtained by parsing, and the microservice list includes several target microservice labels, which can achieve distinguishing and parsing request messages and improve parsing efficiency; by querying whether all the target microservice labels are registered in the microservice gateway, if there is an unregistered microservice, the microservice label corresponding to the unregistered microservice and the request message are sent to the mock service, and the data returned by the mock service is obtained. When the microservice is not registered, the request message can be forwarded to the mock service, and then the data required for the mock test can be obtained, thereby avoiding the situation where data cannot be returned, improving the test efficiency, and ensuring the normal progress of the mock test.
[0105] like Figure 5 As shown, a computer device provided in an embodiment of this invention is used to run the microservice gateway mock testing method described herein. The computer device 502 may include one or more processors 504, such as one or more central processing units (CPUs), each of which may implement one or more hardware threads. The computer device 502 may also include any memory 506 for storing any type of information, such as code, settings, data, etc. Without limitation, for example, the memory 506 may include any one or more combinations of the following: any type of RAM, any type of ROM, a flash memory device, a hard disk, an optical disk, etc. More generally, any memory may use any technology to store information. Furthermore, any memory may provide volatile or non-volatile retention of information. Furthermore, any memory may represent a fixed or removable component of the computer device 502. In one embodiment, when the processor 504 executes associated instructions stored in any memory or combination of memories, the computer device 502 may perform any operation of the associated instructions. The computer device 502 also includes one or more drive mechanisms 508 for interacting with any memory, such as a hard disk drive mechanism, an optical disk drive mechanism, etc.
[0106] The computer device 502 may also include an input / output module 510 (I / O) for receiving various inputs (via input devices 512) and for providing various outputs (via output devices 514). A specific output mechanism may include a presentation device 516 and an associated graphical user interface (GUI) 518. In other embodiments, the input / output module 510 (I / O), input devices 512, and output devices 514 may not be included, and the computer device 502 may simply be a computer device in a network. The computer device 502 may also include one or more network interfaces 520 for exchanging data with other devices via one or more communication links 522. One or more communication buses 524 couple the components described above together.
[0107] The communication link 522 may be implemented in any manner, for example, via a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 522 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.
[0108] Corresponding to Figures 2 to 3 The embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which executes the steps of the above method when executed by a processor.
[0109] The embodiment of the present invention also provides a computer readable instruction, wherein when the processor executes the instruction, the program causes the processor to execute the following Figures 2 to 3 The method shown.
[0110] This article also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the microservice gateway-based mock testing method is implemented.
[0111] It should be understood that in the various embodiments of this document, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this document.
[0112] It should also be understood that in the embodiments herein, the term "and / or" merely describes an association between associated objects, indicating that three possible relationships exist. For example, "A and / or B" could represent: A alone, A and B simultaneously, or B alone. Furthermore, the character " / " in this document generally indicates an "or" relationship between the associated objects.
[0113] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the composition and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this document.
[0114] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0115] In the several embodiments provided herein, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices, or units, or can be an electrical, mechanical, or other form of connection.
[0116] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments herein.
[0117] In addition, the functional units in the various embodiments herein may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0118] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this article is essentially or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of this article. The aforementioned storage medium includes: various media that can store program code, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0119] This article uses specific embodiments to illustrate the principles and implementation methods of this article. The description of the above embodiments is only used to help understand the methods and core ideas of this article. At the same time, for those skilled in the art, based on the ideas of this article, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation to this article.
Claims
1. A microservice gateway mock testing method, characterized in that: include: Receive a request message, wherein the request message is used to call a microservice and includes a request segment, an identification segment, and a microservice list; Parse the identifier of the request message. When the identifier is a first type identifier, parse and obtain a list of microservices called by the request message, and the list of microservices includes several target microservice labels. When the identifier is a second type identifier, forward the request message to the mock service and obtain the data returned by the mock service. The first type identifier indicates that the request message is completed by the cooperation of multiple microservices, while the second type identifier indicates that the request message is completed by a single microservice returning separate data. Query whether all the target microservice labels are registered in the microservice gateway. If the target microservice label is registered in the microservice gateway, send the request message to the corresponding target microservice according to the microservice label corresponding to the microservice. When the time threshold is exceeded and the data returned by the target microservice is not obtained, send the microservice label corresponding to the target microservice and the request message to the mock service to obtain the data returned by the mock service. If there is an unregistered microservice, the microservice number corresponding to the unregistered microservice and the request message are sent to the mock service to obtain the data returned by the mock service.
2. The microservice gateway mock testing method according to claim 1 is characterized in that: The obtaining of data returned by the mock service further includes: When the time threshold is exceeded and no data returned by the mock service is received, first mock service exception information is reported.
3. The microservice gateway mock testing method according to claim 1 is characterized in that: After obtaining the data returned by the mock service, the following steps are included: Perform regular expression matching on the data returned by the mock service and the preset result corresponding to the request message; If no match is found, the second mock service exception information is reported.
4. The microservice gateway mock testing method according to claim 1 is characterized in that: The querying whether all the target microservice labels are registered in the microservice gateway further includes: Use the target microservice label to match the microservice label pre-stored in the microservice gateway; If the match is successful, the target microservice number is registered in the microservice gateway; If the match is unsuccessful, the target microservice number is not registered in the microservice gateway.
5. A mock testing device based on a microservice gateway, characterized in that: include: A receiving unit, configured to receive a request message, wherein the request message is used to call a microservice and includes a request segment, an identification segment, and a microservice list; A parsing unit, configured to parse the identifier of the request message, and when the identifier is a first type identifier, parse to obtain a list of microservices called by the request message, the list of microservices including a number of target microservice labels; and when the identifier is a second type identifier, forward the request message to a mock service and obtain data returned by the mock service; the first type identifier indicates that the request message is completed by the cooperation of multiple microservices, while the second type identifier indicates that the request message is completed by a single microservice returning separate data; A query unit is configured to query whether all target microservice labels are registered in the microservice gateway. If the target microservice label is registered in the microservice gateway, the request message is sent to the corresponding target microservice according to the microservice label corresponding to the microservice. When the time threshold is exceeded and the data returned by the target microservice is not obtained, the microservice label corresponding to the target microservice and the request message are sent to the mock service to obtain the data returned by the mock service. If there is an unregistered microservice, the microservice number corresponding to the unregistered microservice and the request message are sent to the mock service to obtain the data returned by the mock service.
6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the microservice gateway mock testing method according to any one of claims 1 to 4 is implemented.
7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the microservice gateway mock testing method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Micro-service-based Mock test method and system, storage medium and computing device
CN112306864A
Micro-service Mock test method and device, computer equipment and storage medium
CN113986760A
Method and system for micro-service testing, and storage medium
US20220382936A1