CN111625442B - Mock testing method and device - Google Patents
Mock testing method and device Download PDFInfo
- Publication number
- CN111625442B CN111625442B CN201910151958.3A CN201910151958A CN111625442B CN 111625442 B CN111625442 B CN 111625442B CN 201910151958 A CN201910151958 A CN 201910151958A CN 111625442 B CN111625442 B CN 111625442B
- Authority
- CN
- China
- Prior art keywords
- mock
- request
- sub
- service
- python
- 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.)
- Active
Links
- 238000012360 testing method Methods 0.000 title claims abstract description 57
- 238000000034 method Methods 0.000 claims abstract description 25
- 238000004806 packaging method and process Methods 0.000 claims description 10
- 239000000284 extract Substances 0.000 claims description 6
- 238000013515 script Methods 0.000 abstract description 8
- 230000006870 function Effects 0.000 description 29
- 238000004590 computer program Methods 0.000 description 7
- 238000010586 diagram Methods 0.000 description 6
- 238000012546 transfer Methods 0.000 description 6
- 238000004891 communication Methods 0.000 description 5
- 238000005538 encapsulation Methods 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 4
- 238000012545 processing Methods 0.000 description 3
- 230000009471 action Effects 0.000 description 2
- 230000010354 integration Effects 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 239000000835 fiber Substances 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012544 monitoring process Methods 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000000926 separation method Methods 0.000 description 1
- 238000013522 software testing 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/3668—Software testing
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
Abstract
The invention provides a method and a device for mock testing, wherein the method comprises the following steps: creating a request object library and a mock object library, defining a set of request objects as request object classes, defining the set of request object classes as the request object library, defining the set of mock objects as the mock object classes, and defining the set of mock object classes as the mock object library; the mock object class inherits the mock characteristics of a mock base class; and completing the test of the service according to the request object library and the mock object library. The method and the device realize full-flow automatic test of the mock object without manual intervention; the mock service packaged according to the request message classification is provided, script writers do not pay attention to the content of the underlying message, and the difficulty of writing and maintaining the automatic script is reduced.
Description
Technical Field
The invention relates to the field of software testing, in particular to a mock testing method and a mock testing device.
Background
With the development of software technology, communications between software systems are more frequent, and more testing of business scenarios relies on external systems or interfaces, which need to be simulated by means of mock services to complete testing when they cannot be provided in a testing phase. The current main mock service tool cannot meet the requirements of frequent call and rapid deployment of the mock service and full-automatic execution of scripts, and mainly has the following technical problems:
1. integration of the mock service and the test script is not realized, joint debugging of the test script and the mock tool configuration file is difficult, and the efficiency is low;
2. the mock service is required to be manually started before script operation, and is manually closed after the completion of the operation, so that continuous integration cannot be supported;
3. the mock service configuration separation is not realized according to the service, and the mock configuration is shared by multiple services, so that the corresponding relationship between the input and the output of the configuration is easy to conflict, and the accuracy of the test result is influenced.
Disclosure of Invention
In view of the foregoing drawbacks or shortcomings of the prior art, it is desirable to provide a method and apparatus for mock testing that addresses the problems set forth in the background art.
In a first aspect, the present application provides a method for mock testing, which is characterized by comprising:
creating a request object library and a mock object library, defining a set of request object components as request object classes, defining the set of request object class components as the request object library,
defining a set of mock object components as a mock object class, and defining the set of mock object class components as the mock object library;
the mock object class inherits the mock characteristics of a mock base class;
and completing the test of the service according to the request object library and the mock object library.
Further, the request object is the request object formed by encapsulating a request message, and the mock object is the mock object formed by encapsulating a sub-service.
Further, one of the request messages corresponds to one of the sub-services one by one, and one of the mock objects corresponds to one of the sub-services one by one.
Further, one of the request objects corresponds to one of the mock objects one by one.
Further, the mock features include a mock start, a mock configuration, and a mock stop.
Further, the mock object class is provided with features of the mock start, the mock configuration and the mock stop.
Further, the business test is performed using python multithreading, the business test comprising the steps of:
1) Turning on a python sub-thread;
2) Receiving the external request object by using a routing management function of flash, and forwarding the received request object to the python sub-thread by using the routing management function of flash;
3) The python sub-thread monitors and extracts the content of the request object;
4) Calling the corresponding mock object according to the request object;
5) The system actively throws an exception to the python sub-thread, stopping the python sub-thread.
Further, invoking the mock object according to the request object includes the following steps:
according to the request object, matching the corresponding request object class in the request object library, and matching the corresponding request object in the request object class;
one of the request objects corresponds to one of the mock objects one by one;
and according to the mock object, matching the corresponding mock object class in the mock object library, and matching the corresponding mock object in the mock object class.
In a second aspect, the present application provides a device for mock testing, which is characterized in that the device includes:
a creation module for creating a request object library and a mock object library, defining a set of request object components as request object classes, defining the set of request object class components as the request object library,
defining a set of mock object components as a mock object class, and defining the set of mock object class components as the mock object library;
the inheritance module inherits the mock characteristics of the mock basic class by the mock object class;
and the testing module is used for completing the testing of the service according to the request object library and the mock object library.
Further, in the creation module, the request object is a request object formed by packaging a request message, and the mock object is a mock object formed by packaging a sub-service;
one of the request messages corresponds to one of the sub-services one by one, and one of the mock objects corresponds to one of the sub-services one by one;
one of the request objects corresponds to one of the mock objects one to one.
The technical scheme provided by the invention has at least one of the following beneficial technical effects: the mock object class inherits the mock characteristics of the mock basic class, so that the full-flow automatic test related to the mock object is realized, and no manual intervention is needed; the method comprises the steps of creating a request object library and a mock object library, and completing the test of the service according to the request object library and the mock object library, so that mock service packaged according to request message classification is provided, script writers do not pay attention to the content of underlying messages, and the difficulty of writing and maintaining an automatic script is reduced.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the detailed description of non-limiting embodiments made with reference to the following drawings.
FIG. 1 is a flow chart of a method for mock testing according to an embodiment of the present invention;
FIG. 2 is a flow chart of a create request object library of an embodiment of the present invention;
FIG. 3 is a flow chart of creating a mock object library according to an embodiment of the present invention;
FIG. 4 is a mock object class inheritance diagram of an embodiment of the invention;
FIG. 5 is a flow chart of a service B test of an embodiment of the present invention;
FIG. 6 is a flow chart of a request message B1 matching a mock object B1 according to an embodiment of the present invention;
FIG. 7 is a flow chart of an apparatus for mock testing according to an embodiment of the present invention;
fig. 8 is a computer flow diagram of an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Embodiment one:
the present embodiments provide a method of mock testing, it being noted that the method may be performed in a computer system such as a set of computer executable instructions, and that although a logical sequence is illustrated in the flowchart of the method, in some cases the steps illustrated or described may be performed in a different order than that illustrated herein.
Referring to fig. 1, the present embodiment provides a method for mock testing, which includes the following steps:
step S101, creating a request object library and creating a mock object library.
The services to be tested are generally of different types, and any one type of service to be tested can derive at least one sub-service, wherein each sub-service corresponds to a preset request message one by one. For any one sub-service, the request message corresponding to the sub-service is packaged into a request object, so that each sub-service corresponds to one request object one by one.
For any type of service to be tested, the request objects corresponding to all sub-services derived from the service belong to the same type, the set of request object components corresponding to all sub-services derived from the service is defined as a request object class corresponding to the service, and the set of request object class components corresponding to all types of service to be tested is defined as a request object library.
For example, as shown in fig. 2, the services to be tested include three service types, service a, service B, and service C. The service A derives a sub-service A1, a sub-service A2 and a sub-service A3; the service B derives a sub-service B1; the service C derives a sub-service C1 and a sub-service C2. According to the one-to-one correspondence of each sub-service and one preset request message, the sub-service A1 and the preset request message A1 are in one-to-one correspondence, the sub-service A2 and the preset request message A2 are in one-to-one correspondence, the sub-service A3 and the preset request message A3 are in one-to-one correspondence, the sub-service B1 and the preset request message B1 are in one-to-one correspondence, the sub-service C1 and the preset request message C1 are in one-to-one correspondence, and the sub-service C2 and the preset request message C2 are in one-to-one correspondence.
And packaging the request message corresponding to the sub-service into a request object, so that each sub-service corresponds to one request object one by one. Request message a1 is encapsulated as request object a1, request message a2 is encapsulated as request object a2, request message a3 is encapsulated as request object a3, request message b1 is encapsulated as request object b1, request message c1 is encapsulated as request object c1 and request message c2 is encapsulated as request object c2.
Since the request object a1, the request object a2 and the request object a3 correspond to three sub-services of the service a, the request object a1, the request object a2 and the request object a3 are defined as a type a request object, and a set formed by the request object a1, the request object a2 and the request object a3 is defined as a request object class a;
since the request object B1 corresponds to one sub-service of the service B, the request object B1 is defined as a B-type request object, and a set formed by the request objects B1 is defined as a request object class B;
since the request object C1 and the request object C2 correspond to two sub-services of the service C, the request object C1 and the request object C2 are defined as C-type request objects, and the set of the request object C1 and the request object C2 is defined as a request object class C. The set of request object class a, request object class b, and request object class c is defined as a request object library.
For any type of service to be tested, each sub-service derived from the service is packaged as a mock object, so that the sub-services are in one-to-one correspondence with the mock objects. For any type of service to be tested, the mock objects corresponding to all sub-services derived from the service belong to the same type, and a set formed by the mock objects corresponding to all sub-services derived from the service is defined as a mock object class. And defining a set consisting of mock object classes corresponding to all the services to be tested as a mock object library.
For example, as shown in fig. 3, for a service a to be tested, on the basis of the routing management function of flash, the encapsulation sub-service A1 is a mock object A1, the encapsulation sub-service A2 is a mock object A2, and the encapsulation sub-service A3 is a mock object A3. Since the mock object A1, the mock object A2 and the mock object A3 correspond to the sub-service of the service a, the mock object A1, the mock object A2 and the mock object A3 are defined as a type a mock object, and a set of the mock object A1, the mock object A2 and the mock object A3 is defined as a mock object class a corresponding to the service a.
For the service B to be tested, the encapsulation sub-service B1 is the mock object B1. Since the mock object B1 corresponds to a sub-service of the service B, the mock object B1 is defined as a B-type mock object, and a set of the mock objects B1 is defined as a mock object class B corresponding to the service B.
For the service C to be tested, the encapsulated sub-service C1 is the mock object C1, and the encapsulated sub-service C2 is the mock object C2. Since the mock object C1 and the mock object C2 correspond to sub-services of the service C, the mock object C1 and the mock object C2 are defined as a type a mock object, the set of the mock object C1 and the mock object C2 is defined as a mock object class C corresponding to the service B,
the set of mock object class A, mock object class B and mock object class C is defined as a mock object library.
According to the one-to-one correspondence between each sub-service and a preset request message and the fact that each sub-service is a mock object, the one-to-one correspondence between the sub-service and the mock object can be deduced, the one-to-one correspondence between a request message (request object) and a mock object can be deduced, and the sub-service corresponding to the request message and the sub-service corresponding to the mock object are the same sub-service.
In step S102, the mock object class inherits the mock characteristics of the mock base class.
The mock base class is provided with mock features including a mock start, a mock configuration and a mock stop. The mock object class inherits the mock characteristics of the mock base class, so that each mock object class has the mock characteristics, namely, each mock object class has the characteristics of a mock start, a mock configuration and a mock stop.
Before the service test starts, starting a mock; and after the service test is finished, starting the mock to stop. mock is configured to increase or decrease the number of sub-services for any one type of service.
Referring to fig. 4, for example, the mock object class A, mock object class B, mock object class C inherits the mock characteristics of the mock base class, so that the mock object class a has the mock characteristics, that is, the mock object class a has the characteristics of mock start, mock configuration and mock stop; the mock object class B has the mock characteristics, namely the mock object class B has the characteristics of mock starting, mock configuration and mock stopping; the mock object class C has the features of mock start, mock configuration and mock stop.
And performing mock configuration on the service B, adding the sub-service B2 as the sub-service of the service B, wherein the request message B2 corresponds to the sub-service B2 one by one, and packaging the sub-service B2 as a mock object B1. The request object class B includes a request message B1 and a request message B2, and the mock object class B includes a mock object B1 and a mock object B2.
Step S103, completing the test of the service according to the request object library and the mock object library, and specifically comprising the following substeps:
s1031, testing the service by using the python multithread, wherein one service can derive at least one sub-service, one sub-service corresponds to one request message, the number of the corresponding python threads is matched according to the number of the request messages, one request message corresponds to one python thread, two request messages correspond to two python threads, and a plurality of request messages correspond to a plurality of python threads.
And starting the mock start of the test sub-service in each python sub-thread, so that any two python sub-threads cannot influence each other when a plurality of python sub-threads are started simultaneously, and preparing for receiving the request message by the python sub-threads.
S1032, receiving external request messages by using the routing management function of flash, transferring the received request messages to python sub-threads by the routing management function of flash, and transferring the plurality of request messages to the python sub-threads respectively by the routing management function of flash when the routing management function of flash receives a plurality of external request messages simultaneously.
S1033, the python sub-thread listens for and extracts the content of the request message.
S1034, for any request message, calling a corresponding mock object according to the request message, wherein the method specifically comprises the following sub-steps:
s10341, for any request message, determining what type the request message belongs to, finding out a corresponding request object class in the request object library, and finding out a corresponding request object in the corresponding request object class, namely, finding out the request message identical to the external request message in the corresponding request object class.
S10342, according to the one-to-one correspondence between a request message and a mock object in step S101, the request message corresponds to a specific sub-service, and the specific sub-service corresponds to a specific mock object.
S10343, judging what type a specific mock object belongs to, finding out a corresponding mock object class in a mock object library, and finding out the specific mock object in the corresponding mock object class.
S1035, starting the mock stop of the tested service in each python sub-thread, so that any two python sub-threads cannot influence each other when the multiple python sub-threads feed back the respective mock objects at the same time, and the system actively throws out an exception for the python sub-threads to stop the python sub-threads.
The method comprises the steps that a flow route management function receives mock objects fed back by a plurality of python sub-threads, and the flow route management function transfers the mock objects to a system.
S1036, when the mock object received by the routing management function of the flash is a mock object for packaging the specific sub-service, the service test is successful;
when the mock object received by the routing management function of flash is not the mock object encapsulating the specific sub-service, the service test fails.
Referring to FIG. 5, for example, when python multithreading tests service B, service B includes sub-service B1, and python sub-threads test sub-service B1 as follows:
1) The mock start of the python sub-thread is turned on in preparation for the python sub-thread to receive the request message. The route management function of flash receives an external request message b1;
2) The route management function of flash forwards the request message b1 to the python sub-thread;
3) The python sub-thread listens for and extracts the content of request message b1;
4) Matching the corresponding mock object B1 according to the request message B1, specifically comprising the following steps:
referring to fig. 6, according to the request message b1 belonging to the request object class b, the request object class b is found in the request object library, the request object b1 identical to the external request message b1 is found in the request object class b, that is, the request message b1 is found in the request object class b;
according to the one-to-one correspondence of each sub-service with a request message and the one-to-one correspondence of each sub-service with a mock object, the request message B1 corresponds to the sub-service B1, the sub-service B1 corresponds to the mock object B1, a mock object class B corresponding to the sub-service B1 is found in a mock object library, and a mock object B1 encapsulating the sub-service B1 is found in the mock object class B.
5) And after the flow route management function receives the mock object B1 fed back by the python sub-thread, the python sub-thread starts the mock to stop after finishing transferring the mock object B1 to the flow route management function of the flow, and the system actively throws an exception to the python sub-thread to stop the python sub-thread.
The flow route management function transfers the mock object B1 to the system, and the sub-service B1 is tested successfully.
Embodiment two:
referring to fig. 7, an apparatus for mock testing in this embodiment includes:
s701, creating a request object library and a mock object library.
The services to be tested are generally of different types, and any one type of service to be tested can derive at least one sub-service, wherein each sub-service corresponds to a preset request message one by one. For any one sub-service, the request message corresponding to the sub-service is packaged into a request object, so that each sub-service corresponds to one request object one by one.
For any type of service to be tested, the request objects corresponding to all sub-services derived from the service belong to the same type, the set of request object components corresponding to all sub-services derived from the service is defined as a request object class corresponding to the service, and the set of request object class components corresponding to all types of service to be tested is defined as a request object library.
For any type of service to be tested, each sub-service derived from the service is packaged as a mock object, so that the sub-services are in one-to-one correspondence with the mock objects. For any type of service to be tested, the mock objects corresponding to all sub-services derived from the service belong to the same type, and a set formed by the mock objects corresponding to all sub-services derived from the service is defined as a mock object class corresponding to the service. And defining a set consisting of mock object classes corresponding to all the services to be tested as a mock object library.
According to the one-to-one correspondence between each sub-service and a preset request message and the fact that each sub-service is a mock object, the one-to-one correspondence between the sub-service and the mock object can be deduced, the one-to-one correspondence between a request message (request object) and a mock object can be deduced, and the sub-service corresponding to the request message and the sub-service corresponding to the mock object are the same sub-service.
S702 inheritance module, the mock object class inherits the mock characteristics of the mock base class.
The mock base class is provided with mock features including a mock start, a mock configuration and a mock stop. The mock object class inherits the mock characteristics of the mock base class, so that each mock object class has the mock characteristics, namely, each mock object class has the characteristics of a mock start, a mock configuration and a mock stop.
Before the service test starts, starting a mock; and after the service test is finished, starting the mock to stop. mock is configured to increase or decrease the number of sub-services for any one type of service.
S703, a testing module for completing the service test according to the request object library and the mock object library, specifically comprising the following submodules:
s7031, testing services by using python multithreading, wherein one service can derive at least one sub-service, one sub-service corresponds to one request message, the number of the request messages is matched with the corresponding number of python multithreading, one request message corresponds to one python multithreading, two request messages correspond to two python multithreading, and a plurality of request messages correspond to a plurality of python multithreading.
And starting the mock start of the test sub-service in each python sub-thread, so that any two python sub-threads cannot influence each other when a plurality of python sub-threads are started simultaneously, and preparing for receiving the request message by the python sub-threads.
S7032, a receiving module receives external request messages by using a routing management function of flash, the routing management function of flash transfers the received request messages to python sub-threads, and when the routing management function of flash receives a plurality of external request messages at the same time, the routing management function of flash transfers the plurality of request messages to python sub-threads with corresponding numbers respectively.
S7033, a monitoring and extracting module monitors and extracts the content of the request message by the python sub-thread.
S7034, a matching module calls a mock object corresponding to any request message according to the request message, and specifically comprises the following submodules:
s70341, a request object module determines what type the request message belongs to for any one request message, finds a corresponding request object class in a request object library, and finds a corresponding request object in the corresponding request object class, that is, finds a request message identical to an external request message in the corresponding request object class.
S70342, a pairing module is used for corresponding one request message to one mock object one by one according to the step S701, wherein the request message corresponds to a specific sub-service, and the specific sub-service corresponds to one specific mock object.
S70343, a mock object module judges what type a specific mock object belongs to, a corresponding mock object class is found in a mock object library, and the specific mock object is found in the corresponding mock object class.
S7035, a transfer module starts the mock stop of the service tested in each python sub-thread, so that any two python sub-threads cannot influence each other when a plurality of python sub-threads feed back respective mock objects at the same time, and the system actively throws out an exception to the python sub-threads and stops the python sub-threads.
The method comprises the steps that a flow route management function receives mock objects fed back by a plurality of python sub-threads, and the flow route management function transfers the mock objects to a system.
S7036, a stopping module, wherein when a mock object received by a routing management function of flash is a mock object for packaging a specific sub-service, service test is successful;
when the mock object received by the routing management function of flash is not the mock object encapsulating the specific sub-service, the service test fails.
Embodiment III:
referring to fig. 8, the computer system includes a Central Processing Unit (CPU) 801 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 802 or a program loaded from a storage section into a Random Access Memory (RAM) 803. In the RAM803, various programs and data required for system operation are also stored. The CPU 801, ROM 802, and RAM803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to the bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, mouse, etc.; an output section including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk or the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. The drives are also connected to the I/O interface 805 as needed. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as needed so that a computer program read out therefrom is mounted into the storage section 808 as needed.
In particular, the process described above with reference to flowchart 8 may be implemented as a computer software program according to an embodiment of the invention. For example, embodiments of the present invention include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such embodiments, the computer program may be downloaded and installed from a network via a communication portion, and/or installed from a removable medium. The above-described functions defined in the system of the present application are performed when the computer program is executed by a Central Processing Unit (CPU) 801.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present invention may be implemented by software, or may be implemented by hardware, and the described units may also be provided in a processor. Wherein the names of the units do not constitute a limitation of the units themselves in some cases. The described units or modules may also be provided in a processor, for example, as: a mock testing device comprises a creation module, an inheritance module and a testing module. Where the names of the units or modules do not constitute a limitation on the units or modules themselves in some cases, for example, the creation module may also be described as "for creating a request object library and creating a mock object library".
As another aspect, the present application also provides a computer-readable medium that may be contained in the electronic device described in the above embodiment; or may exist alone without being incorporated into the electronic device. The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to implement the method of mock testing as in the above embodiments.
For example, the electronic device may implement the method as shown in fig. 1: step S101, creating a request object library and a mock object library; step S102, a mock object class inherits the mock characteristics of a mock basic class; and step S103, completing service testing according to the request object library and the mock object library. As another example, the electronic device may implement the various steps as shown in fig. 2, 3, 4, 5, and 6.
It should be noted that although in the above detailed description several modules or units of a device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit in accordance with embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into a plurality of modules or units to be embodied.
Furthermore, although the steps of the methods in the present disclosure are depicted in a particular order in the drawings, this does not require or imply that the steps must be performed in that particular order or that all illustrated steps be performed in order to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step to perform, and/or one step decomposed into multiple steps to perform, etc.
From the above description of embodiments, those skilled in the art will readily appreciate that the example embodiments described herein may be implemented in software, or may be implemented in software in combination with the necessary hardware.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are mutually referred to, so that each embodiment is mainly different from other embodiments. For the modular embodiment, the description is relatively simple, as it is based on an embodiment similar to the method, with reference to the partial description of the method embodiment.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims (3)
1. A method of mock testing, comprising: creating a request object library and a mock object library, defining a set of request objects as request object classes, defining the set of request object classes as the request object library, defining the set of mock objects as the mock object classes, and defining the set of mock object classes as the mock object library; the mock object class inherits the mock characteristics of a mock base class; completing the test of the service according to the request object library and the mock object library;
the request object is formed by packaging request messages, the mock object is formed by packaging sub-services, one request message corresponds to one sub-service one by one, one mock object corresponds to one sub-service one by one,
one of the request objects corresponds to one of the mock objects one by one;
the mock features include a mock start, a mock configuration and a mock stop;
the business test is performed by using python multithreading, and comprises the following steps: 1) Turning on a python sub-thread; 2) Receiving the external request object by using a routing management function of flash, and forwarding the received request object to the python sub-thread by using the routing management function of flash; 3) The python sub-thread monitors and extracts the content of the request object; 4) Calling the corresponding mock object according to the request object; 5) The system actively throws an exception to the python sub-thread, stopping the python sub-thread.
2. The method according to claim 1, wherein: invoking the corresponding mock object according to the request object comprises the following steps: according to the request object, matching the corresponding request object class in the request object library, and matching the corresponding request object in the request object class; one of the request objects corresponds to one of the mock objects one by one; and according to the mock object, matching the corresponding mock object class in the mock object library, and matching the corresponding mock object in the mock object class.
3. A mock testing device, characterized in that: the device comprises: the creation module creates a request object library and a mock object library, defines a set of request objects as request object classes, defines the set of request object classes as the request object library, defines the set of mock objects as a mock object class, and defines the set of mock object classes as the mock object library; the inheritance module inherits the mock characteristics of the mock basic class by the mock object class; the test module is used for completing the test of the service according to the request object library and the mock object library;
in the creation module, the request object is a request object formed by packaging a request message, and the mock object is a mock object formed by packaging a sub-service; one of the request messages corresponds to one of the sub-services one by one, and one of the mock objects corresponds to one of the sub-services one by one; one of the request objects corresponds one-to-one to one with one of the mock objects, the mock features including a mock start, a mock configuration and a mock stop,
the business test is performed by using python multithreading, and comprises the following steps: 1) Turning on a python sub-thread; 2) Receiving the external request object by using a routing management function of flash, and forwarding the received request object to the python sub-thread by using the routing management function of flash; 3) The python sub-thread monitors and extracts the content of the request object; 4) Calling the corresponding mock object according to the request object; 5) The system actively throws an exception to the python sub-thread, stopping the python sub-thread.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910151958.3A CN111625442B (en) | 2019-02-28 | 2019-02-28 | Mock testing method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910151958.3A CN111625442B (en) | 2019-02-28 | 2019-02-28 | Mock testing method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111625442A CN111625442A (en) | 2020-09-04 |
CN111625442B true CN111625442B (en) | 2024-03-26 |
Family
ID=72272467
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910151958.3A Active CN111625442B (en) | 2019-02-28 | 2019-02-28 | Mock testing method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111625442B (en) |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102855177A (en) * | 2011-06-30 | 2013-01-02 | 阿里巴巴集团控股有限公司 | Unit test method and device |
CN103984628A (en) * | 2014-05-15 | 2014-08-13 | 中国南方航空股份有限公司 | Automatic function test method and system applied to BS (browser/server) framework |
US9201767B1 (en) * | 2013-12-23 | 2015-12-01 | Nationwide Mutual Insurance Company | System and method for implementing a testing framework |
CN106547681A (en) * | 2015-09-18 | 2017-03-29 | 北京京东尚科信息技术有限公司 | The method and apparatus that data load simultaneously multiplexed analog service testing automatically |
CN106970873A (en) * | 2017-01-10 | 2017-07-21 | 阿里巴巴集团控股有限公司 | Mock method of testings, apparatus and system on line |
CN107368405A (en) * | 2016-05-11 | 2017-11-21 | 腾讯科技(北京)有限公司 | Test system, method of testing, mock platforms, blocker and client |
CN109359149A (en) * | 2018-10-08 | 2019-02-19 | 网宿科技股份有限公司 | A kind of analog detection method and relevant apparatus |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8935573B2 (en) * | 2012-08-29 | 2015-01-13 | International Business Machines Corporation | Reliable unit testing through cached mocking |
US9870311B2 (en) * | 2014-09-04 | 2018-01-16 | Home Box Office, Inc. | Mock object generation |
-
2019
- 2019-02-28 CN CN201910151958.3A patent/CN111625442B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102855177A (en) * | 2011-06-30 | 2013-01-02 | 阿里巴巴集团控股有限公司 | Unit test method and device |
US9201767B1 (en) * | 2013-12-23 | 2015-12-01 | Nationwide Mutual Insurance Company | System and method for implementing a testing framework |
CN103984628A (en) * | 2014-05-15 | 2014-08-13 | 中国南方航空股份有限公司 | Automatic function test method and system applied to BS (browser/server) framework |
CN106547681A (en) * | 2015-09-18 | 2017-03-29 | 北京京东尚科信息技术有限公司 | The method and apparatus that data load simultaneously multiplexed analog service testing automatically |
CN107368405A (en) * | 2016-05-11 | 2017-11-21 | 腾讯科技(北京)有限公司 | Test system, method of testing, mock platforms, blocker and client |
CN106970873A (en) * | 2017-01-10 | 2017-07-21 | 阿里巴巴集团控股有限公司 | Mock method of testings, apparatus and system on line |
CN109359149A (en) * | 2018-10-08 | 2019-02-19 | 网宿科技股份有限公司 | A kind of analog detection method and relevant apparatus |
Non-Patent Citations (1)
Title |
---|
陈丽萍 ; 张勇 ; 丁智敏 ; .自动化单元测试框架EasyMock分析及其应用.巢湖学院学报.2014,(06),第40-44页. * |
Also Published As
Publication number | Publication date |
---|---|
CN111625442A (en) | 2020-09-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110032400A (en) | A kind of method and electric terminal loading plug-in unit | |
CN114064208A (en) | Method and device for detecting application service state, electronic equipment and storage medium | |
CN112035344A (en) | Multi-scenario test method, device, equipment and computer readable storage medium | |
CN112948272A (en) | Production environment-based data test system function method and device and related equipment | |
CN112579569A (en) | Data migration method and device | |
CN113076153A (en) | Interface calling method and device | |
CN113282444B (en) | Visualization method and device for debugging business process | |
CN111625442B (en) | Mock testing method and device | |
CN110795331A (en) | Software testing method and device | |
CN112887355B (en) | Service processing method and device for abnormal server | |
CN111414154A (en) | Method and device for front-end development, electronic equipment and storage medium | |
CN111538717B (en) | Data processing method, device, electronic equipment and computer readable medium | |
CN113742235A (en) | Method and device for checking codes | |
CN112948195A (en) | Interface testing method and device, electronic equipment and storage medium | |
CN113704079A (en) | Interface testing method and device based on Protobuf | |
CN112613955A (en) | Order processing method and device, electronic equipment and storage medium | |
CN107463438B (en) | Information processing method, device and system for multi-Openstack environment | |
CN109840073B (en) | Method and device for realizing business process | |
CN113448602A (en) | Version updating method and device | |
CN112783903A (en) | Method and device for generating update log | |
CN112131095A (en) | Pressure testing method and device | |
CN109376023B (en) | Method and equipment for generating calling information and issuing return code group | |
CN112783753B (en) | Testing method and device for stream data processing system | |
CN113127051B (en) | Application resource packaging process monitoring method, device, equipment and medium | |
CN110825438B (en) | Method and device for simulating data processing of artificial intelligence chip |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |