CN116820978A - Microservice automatic testing method based on Redis database - Google Patents
Microservice automatic testing method based on Redis database Download PDFInfo
- Publication number
- CN116820978A CN116820978A CN202310794416.4A CN202310794416A CN116820978A CN 116820978 A CN116820978 A CN 116820978A CN 202310794416 A CN202310794416 A CN 202310794416A CN 116820978 A CN116820978 A CN 116820978A
- Authority
- CN
- China
- Prior art keywords
- mock
- aop
- annotation
- class
- remote
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000012360 testing method Methods 0.000 title claims abstract description 27
- 238000000034 method Methods 0.000 claims abstract description 66
- 238000010998 test method Methods 0.000 claims abstract description 12
- 238000004590 computer program Methods 0.000 claims description 3
- 238000011161 development Methods 0.000 abstract description 3
- 230000009286 beneficial effect Effects 0.000 abstract description 2
- 238000005516 engineering process Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/3644—Software debugging by instrumenting at runtime
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/366—Software debugging using diagnostics
Abstract
The application provides a microservice automatic test method based on a Redis database, which comprises the following steps: s1, setting a Mock annotation for an AOP method required to be called by a remote service; s2, setting a remote annotation class associated with the class signature, wherein the remote annotation class is used for marking a method which is remotely called in the class; s3, setting interception classes for intercepting all remote call AOP methods, and returning corresponding different results according to the judgment of whether the called AOP methods are allowed to be subjected to the Mock test or not; s4, after intercepting a request for remotely calling the AOP method, judging whether the AOP method is allowed to be subjected to a Mock test, if so, dynamically splicing key values, acquiring a required Mock object from a Redis database, and otherwise, directly executing the AOP method; s5, returning the Mock object or the internal object to output. The application has the beneficial effects that: the method is simple to operate, only the mock data to be tested is required to be put into the Redis database, and a baffle program is not required to be developed. Compared with the existing baffle program test scheme, the development time and the deployment cost of the baffle program are directly saved.
Description
Technical Field
The application belongs to the technical field of testing, and particularly relates to a micro-service automatic testing method based on a Redis database.
Background
With the field of internet distributed technology, the architecture mode of micro services has gradually taken the mainstream place. After splitting the application module into micro-services, the dependency between services and the collaboration network become complicated, how to improve the testability of the micro-services with external dependencies, which directly affects the cycle and quality of software delivery. In the existing micro-service test technology, an interface baffle program is often developed to solve the external dependence problem. But there are significant limitations to using the baffle procedure itself. Firstly, the baffle program is not flexible enough, the result returned by calling the baffle program is a static result, and a specific response cannot be returned according to different inputs. Secondly, when the interface of the micro-service to be tested changes, the baffle program needs to be modified and upgraded in a targeted mode, and the changing frequency of the interface is high in the initial stage of development. Third, the baffle program needs to be deployed separately, and needs to occupy hardware resources. It is therefore desirable to propose a new testing method to solve the above-mentioned problems.
Disclosure of Invention
In view of this, the present application aims to provide a micro-service automation test method based on a dis database, which enables a micro-service to perform dynamic Mock test with a lightweight structure, thereby improving the flexibility of the test and reducing the cost and difficulty of developing a test program.
In order to achieve the above purpose, the technical scheme of the application is realized as follows:
a micro-service automatic test method based on a Redis database comprises the following steps:
s1, setting a Mock annotation for an AOP method required to be called by a remote service;
s2, setting a remote annotation class associated with the class signature, wherein the remote annotation class is used for marking a method which is remotely called in the class;
s3, setting interception classes for intercepting all remote call AOP methods, and returning corresponding different results according to the judgment of whether the called AOP methods are allowed to be subjected to the Mock test or not;
s4, after intercepting a request for remotely calling the AOP method, judging whether the AOP method is allowed to be subjected to a Mock test, if so, dynamically splicing key values, acquiring a required Mock object from a Redis database, and otherwise, directly executing the AOP method;
s5, returning the Mock object or the internal object to output.
Further, in S1, the Mock annotation class includes a parameter key for acquiring data in the Redis database, and a remote service name corresponding to the AOP method, where the remote service name is used to mark whether the AOP method is allowed to be Mock tested.
Further, in S4, after intercepting the request for remotely calling the AOP method, when the AOP method allows the class where the AOP method is tested by the Mock, when the remote annotation and the Mock annotation exist, dynamically splicing the class into a key according to the key value in the Mock annotation and the request parameter of the calling method, acquiring a result in the Redis database according to the key, and serializing the result into a Mock object required by service logic and returning the Mock object.
Further, in S4, after intercepting the request for remotely calling the AOP method, when the AOP method is not allowed to be tested by the Mock, the AOP method does not contain the Mock annotation, or when the class name corresponding to the AOP method is not in the configuration list allowed to be tested by the Mock, the remote calling logic is directly executed, and the obtained internal object to be actually used is returned.
Further, the scheme discloses electronic equipment, which comprises a processor and a memory, wherein the memory is in communication connection with the processor and is used for storing executable instructions of the processor, and the processor is used for executing a micro-service automatic test method based on a Redis database.
Further, the present solution discloses a server comprising at least one processor and a memory communicatively connected to the processor, the memory storing instructions executable by the at least one processor, the instructions being executable by the processor to cause the at least one processor to perform a method for automatically testing micro services based on a Redis database.
Further, the present solution discloses a computer readable storage medium storing a computer program which when executed by a processor implements a micro-service automation test method based on a Redis database.
Compared with the prior art, the micro-service automatic testing method based on the Redis database has the following beneficial effects:
(1) The microservice automatic test method based on the Redis database is simple to operate, only the mock data to be tested is required to be placed in the Redis database, and a baffle program is not required to be developed. Compared with the existing baffle program test scheme, the development time and the deployment cost of the baffle program are directly saved;
(2) According to the micro-service automatic test method based on the Redis database, the Mock result is dynamic content, the result can be dynamically changed at any time according to the test requirement, the test scene of complex service can be completely met, and the automatic test script is conveniently written;
(3) According to the micro-service automatic test method based on the Redis database, the study cost of the testers is very low, and only simple Redis operation commands are learned, so that the requirements of the testers on program development skills are greatly reduced, the software delivery period is shortened, and the delivery quality is improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application. In the drawings:
fig. 1 is a schematic diagram of a micro-service automation test method based on a dis database according to an embodiment of the present application.
Detailed Description
It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other.
The application will be described in detail below with reference to the drawings in connection with embodiments.
In order to solve the technical problems, the application provides a micro-service automatic test method based on a Redis database, which enables micro-service to perform dynamic Mock test by a lightweight structure, improves test flexibility and reduces cost and difficulty of developing test programs.
As shown in fig. 1, the present application provides a micro-service automation test method based on a Redis database, which includes:
1. setting a Mock annotation for an AOP method (section-oriented programming, extending of oop) to be called by a remote service, wherein the Mock annotation class comprises a parameter key for acquiring data in a Redis database and a remote service name corresponding to the AOP method, and the remote service name is used for marking whether the AOP method is allowed to be subjected to a Mock test;
2. setting a remote annotation class associated with the class signature, wherein the remote annotation class is used for marking a method containing remote call in the class;
3. setting interception classes for intercepting all remote call AOP methods, and returning corresponding different results according to the judgment of whether the called AOP methods are allowed to be subjected to the Mock test or not;
4. after intercepting a request to remotely invoke an AOP method, the AOP method allows the case of being Mock tested: when the remote annotation and the Mock annotation exist in the class where the AOP method is, dynamically splicing a key according to a key value in the Mock annotation and a request parameter of a calling method, acquiring a result in a Redis database according to the key, and serializing the result into a Mock object required by service logic and returning the Mock object;
5. after intercepting a request for remotely calling an AOP method, the AOP method is not allowed to be tested by the Mock: and when the AOP method does not contain the Mock annotation or the class name corresponding to the AOP method is not in the configuration list allowed to be tested by the Mock, directly executing remote call logic, and returning the obtained internal object to be actually used.
Those of ordinary skill in the art will appreciate that the elements and method steps of each example described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the elements and steps of each example have been described generally in terms of functionality in the foregoing description to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the several embodiments provided in the present application, it should be understood that the disclosed methods and systems may be implemented in other ways. For example, the above-described division of units is merely a logical function division, and there may be another division manner when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted or not performed. The units may or may not be physically separate, and components shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment of the present application.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the application, and are intended to be included within the scope of the appended claims and description.
The foregoing description of the preferred embodiments of the application is not intended to be limiting, but rather is intended to cover all modifications, equivalents, alternatives, and improvements that fall within the spirit and scope of the application.
Claims (7)
1. A method for automatically testing micro services based on a dis database, comprising the steps of:
s1, setting a Mock annotation for an AOP method required to be called by a remote service;
s2, setting a remote annotation class associated with the class signature, wherein the remote annotation class is used for marking a method which is remotely called in the class;
s3, setting interception classes for intercepting all remote call AOP methods, and returning corresponding different results according to the judgment of whether the called AOP methods are allowed to be subjected to the Mock test or not;
s4, after intercepting a request for remotely calling the AOP method, judging whether the AOP method is allowed to be subjected to a Mock test, if so, dynamically splicing key values, acquiring a required Mock object from a Redis database, and otherwise, directly executing the AOP method;
s5, returning the Mock object or the internal object to output.
2. The method according to claim 1, wherein in S1, the Mock annotation class includes a parameter key for acquiring data in the Redis database, and a remote service name corresponding to the AOP method, where the remote service name is used to mark whether the AOP method is allowed to be Mock tested.
3. The method according to claim 1, wherein in S4, after intercepting the request for remotely calling the AOP method, the AOP method allows the class where the AOP method is located to be tested by the Mock, and when there are the remote annotation and the Mock annotation, a key is dynamically spliced according to a key value in the Mock annotation and a request parameter of the calling method, a result is obtained in the Redis database according to the key, and a Mock object required by the service logic is serialized to return.
4. The method according to claim 1, wherein in S4, after intercepting a request for remotely calling an AOP method, when the AOP method is not allowed to be Mock tested, the AOP method does not contain a Mock annotation, or when a class name corresponding to the AOP method is not in a configuration list allowed to be Mock tested, remote call logic is directly executed, and the obtained internal object to be actually used is returned.
5. An electronic device comprising a processor and a memory communicatively coupled to the processor for storing processor-executable instructions, characterized in that: the processor is configured to perform a method for automatically testing micro services based on a dis database as claimed in any one of claims 1 to 4.
6. A server, characterized by: comprising at least one processor and a memory communicatively coupled to the processor, the memory storing instructions executable by the at least one processor to cause the at least one processor to perform a Redis database-based micro-service automation test method as claimed in any one of claims 1-4.
7. A computer-readable storage medium storing a computer program, characterized in that: the computer program, when executed by a processor, implements a method for automatically testing micro services based on a Redis database as claimed in any one of claims 1 to 4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310794416.4A CN116820978A (en) | 2023-06-30 | 2023-06-30 | Microservice automatic testing method based on Redis database |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310794416.4A CN116820978A (en) | 2023-06-30 | 2023-06-30 | Microservice automatic testing method based on Redis database |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116820978A true CN116820978A (en) | 2023-09-29 |
Family
ID=88114273
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310794416.4A Pending CN116820978A (en) | 2023-06-30 | 2023-06-30 | Microservice automatic testing method based on Redis database |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116820978A (en) |
-
2023
- 2023-06-30 CN CN202310794416.4A patent/CN116820978A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110147326B (en) | Microservice automatic test method based on Redis database | |
CN107979508B (en) | Micro-service test method and device | |
US8677327B2 (en) | Service testing method and service testing system | |
US8978015B2 (en) | Self validating applications | |
US20040205406A1 (en) | Automatic test system for testing remote target applications on a communication network | |
US20180322037A1 (en) | Impersonation in test automation | |
CN105302722B (en) | CTS automatic testing method and device | |
CN107832207A (en) | Interface performance test method, apparatus, storage medium and computer equipment | |
TW201917569A (en) | Android dynamic framework and method thereof | |
CN105389263A (en) | Method, system and equipment for monitoring application software permissions | |
US20200379742A1 (en) | Validation of configurations of factory installations | |
CN111782519A (en) | Test method and device and electronic equipment | |
CN106897223A (en) | A kind of software kit delivery method and device based on continuous integrating | |
CN107391362A (en) | Application testing method, mobile terminal and storage medium | |
CN113687858A (en) | Configuration file checking method and device, electronic equipment and storage medium | |
CN116627849B (en) | System test method, device, equipment and storage medium | |
CN116820978A (en) | Microservice automatic testing method based on Redis database | |
CN108536429B (en) | Method and device for developing software, storage medium and electronic equipment | |
CN111782518A (en) | Test method and device and electronic equipment | |
CN113448853A (en) | Unit testing method, unit testing device, testing equipment and storage medium | |
CN114237634A (en) | Application release risk identification method, device, equipment, medium and program product | |
CN112965733A (en) | Component library updating method and device, electronic equipment and readable storage medium | |
CN112685071A (en) | Application program repairing method, device, equipment and storage medium | |
CN106648797A (en) | Method and system for installing test software, test server and shared server | |
CN113050962A (en) | Mobile service upgrading method, device and terminal |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |