CN109614322A - Unit test method, device, equipment and readable storage medium storing program for executing based on Mock - Google Patents

Unit test method, device, equipment and readable storage medium storing program for executing based on Mock Download PDF

Info

Publication number
CN109614322A
CN109614322A CN201811431921.8A CN201811431921A CN109614322A CN 109614322 A CN109614322 A CN 109614322A CN 201811431921 A CN201811431921 A CN 201811431921A CN 109614322 A CN109614322 A CN 109614322A
Authority
CN
China
Prior art keywords
mapping
mock
mapping method
test
class
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
Application number
CN201811431921.8A
Other languages
Chinese (zh)
Inventor
杨宽
赖韬
任弘
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Financial Technology Holding Co Ltd
Original Assignee
Beijing Jingdong Financial Technology Holding Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Financial Technology Holding Co Ltd filed Critical Beijing Jingdong Financial Technology Holding Co Ltd
Priority to CN201811431921.8A priority Critical patent/CN109614322A/en
Publication of CN109614322A publication Critical patent/CN109614322A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45575Starting, stopping, suspending or resuming virtual machine instances
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45591Monitoring or debugging support

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application discloses a kind of unit test method based on Mock, device, equipment and readable storage medium storing program for executing.This method comprises: searching whether there is mapping class corresponding with Mock object and mapping method at least one pre-configured test case when Mock object is created;And if finding mapping class and mapping method, obtain mapping method;And when calling the method for Mock object, mapping method is executed, and return to corresponding Mock data.This method can concentrate test case and manage, and coding cost is effectively reduced.

Description

Unit test method, device, equipment and readable storage medium storing program for executing based on Mock
Technical field
The present invention relates to field of computer technology, in particular to a kind of unit test method based on Mock, dress It sets, equipment and readable storage medium storing program for executing.
Background technique
Unit testing (Unit Testing) refers to that can survey unit to the minimum in software is checked and verified, usually by Developer or tester implement in the process of development or after the completion of exploitation.It can be a method that minimum, which can survey unit, Or function a, or window or menu etc..
Unit testing usually need independently be carried out in the case where the other parts with program are isolated.But it is surveyed in minimum The method for trying to may rely on a large amount of object in unit, and call relied on object.These objects relied on and its method, Mostly it is not easy directly to be manufactured, needs virtually to manufacture.Mock frame is exactly for virtually manufacturing pair As and its method, data.Mock object is called by the object that Visual Manufacturing comes out.Mock frame can be used to that dependence is isolated Object, the system that also can isolate dependence, so that it is guaranteed that the independence that unit testing executes.In addition, working as multi-party joint development not When with module and system, other side only provides interface, and one's own side can carry out joint debugging exploitation by Mock, to realize concurrent working. When the later period, then carry out the test of integrated and connection.When the change of inline system demand, it can be tested by assembled unit and carry out recurrence survey Examination, strong guarantee mass of system.
But existing Mock frame needs a large amount of hard coded, cost and test case (the Test Case) of hard coded Complexity is directly proportional, and the coverage rate of unit testing is higher, then the cost of Mock hard coded is also corresponding higher.Test is in turn resulted in use Example is difficult to effectively manage and maintain, especially when demand changes.In addition, existing Mock frame is difficult to and with integration testing Based on unit testing blend.
Above- mentioned information are only used for reinforcing the understanding to background of the invention, therefore it disclosed in the background technology part It may include the information not constituted to the prior art known to persons of ordinary skill in the art.
Summary of the invention
The present invention provides a kind of unit test method based on Mock, device, equipment and readable storage medium storing program for executing, can be to survey Example centralized management on probation, is effectively reduced coding cost.
Other characteristics and advantages of the invention will be apparent from by the following detailed description, or partially by the present invention Practice and acquistion.
According to an aspect of the present invention, a kind of unit test method based on Mock is provided, comprising: when Mock object is created When building, search whether there is mapping class corresponding with Mock object and mapping at least one pre-configured test case Method;And if finding mapping class and mapping method: obtain mapping method;And when calling the method for Mock object, Mapping method is executed, and returns to corresponding Mock data.
According to an embodiment of the present invention, at least one test case is configured by scripting language.
According to an embodiment of the present invention, obtaining mapping method includes: to be enhanced by bytecode, obtains mapping method.
According to an embodiment of the present invention, obtaining mapping method includes: to obtain mapping side by Java dynamic proxy Method.
According to an embodiment of the present invention, searched whether at least one pre-configured test case exist with Before the corresponding mapping class of Mock object and mapping method, further includes: at least one test of request from remote database Use-case.
According to another aspect of the present invention, a kind of unit test method is provided, comprising: the test pair in Spring container When as being injected, search whether there is mapping class corresponding with test object at least one pre-configured test case And mapping method;And if finding mapping class and mapping method: obtain mapping method;And when calling test object When method, mapping method is executed, and return to corresponding result data.
According to an embodiment of the present invention, at least one test case is configured by scripting language.
According to an embodiment of the present invention, obtaining mapping method includes: to obtain mapping side by Java dynamic proxy Method.
In accordance with a further aspect of the present invention, a kind of unit testing device based on Mock is provided, comprising: method searches mould Block, for when Mock object is created, searching whether to exist at least one pre-configured test case and Mock The corresponding mapping class of object and mapping method;And method execution module, for when method searching module find mapping class and When mapping method, mapping method is obtained;And when calling the method for Mock object, mapping method is executed, and is returned corresponding Mock data.
In accordance with a further aspect of the present invention, a kind of unit testing device is provided, comprising: method searching module, for working as When test object in Spring container is injected, searched whether at least one pre-configured test case exist with The corresponding mapping class of test object and mapping method;And method execution module, for finding mapping when method searching module When class and mapping method, mapping method is obtained;And when calling the method for test object, mapping method is executed, and is returned corresponding Result data.
In accordance with a further aspect of the present invention, a kind of computer equipment is provided, comprising: memory, processor and be stored in In reservoir and the executable instruction that can run in the processor, processor realize such as above-mentioned any base when executing executable instruction In the unit test method of Mock.
In accordance with a further aspect of the present invention, a kind of computer equipment is provided, comprising: memory, processor and be stored in In reservoir and the executable instruction that can run in the processor, processor realize such as above-mentioned any list when executing executable instruction First test method.
In accordance with a further aspect of the present invention, a kind of computer readable storage medium is provided, being stored thereon with computer can hold Row instruction, realizes such as above-mentioned any unit test method based on Mock when executable instruction is executed by processor.
In accordance with a further aspect of the present invention, a kind of computer readable storage medium is provided, being stored thereon with computer can hold Row instruction, realizes such as above-mentioned any unit test method when executable instruction is executed by processor.
On the one hand, the unit test method according to the present invention based on Mock, can be by configuring, and nothing is intrusively surveyed with unit It tries program code to combine, and previous unit testing is seamless merges, and coding cost is effectively reduced.
On the other hand, unit test method according to the present invention can formulate class to any in the starting of Spring container Bean carry out Mock object broker, thus and the unit testing seamless combination based on integration testing, become based on Mock's Unit testing.
It should be understood that the above general description and the following detailed description are merely exemplary, this can not be limited Invention.
Detailed description of the invention
Its example embodiment is described in detail by referring to accompanying drawing, above and other target of the invention, feature and advantage will It becomes more fully apparent.
Fig. 1 is a kind of flow chart of unit test method based on Mock shown according to an illustrative embodiments.
Fig. 2 is the flow chart according to another unit test method based on Mock shown in an illustrative embodiments.
Fig. 3 is the flow chart of the unit test method according to another shown in an illustrative embodiments based on Mock.
Fig. 4 is the interaction signal of the unit test method according to another shown in an illustrative embodiments based on Mock Figure.
Fig. 5 is a kind of flow chart of unit test method shown according to an illustrative embodiments.
Fig. 6 is a kind of block diagram of unit testing device based on Mock shown according to an illustrative embodiments.
Fig. 7 is a kind of block diagram of unit testing device shown according to an illustrative embodiments.
Fig. 8 is a kind of structural schematic diagram of computer system shown according to an illustrative embodiments.
Specific embodiment
Example embodiment is described more fully with reference to the drawings.However, example embodiment can be with a variety of shapes Formula is implemented, and is not understood as limited to example set forth herein;On the contrary, thesing embodiments are provided so that the present invention will more Fully and completely, and by the design of example embodiment comprehensively it is communicated to those skilled in the art.Attached drawing is only the present invention Schematic illustrations, be not necessarily drawn to scale.Identical appended drawing reference indicates same or similar part in figure, thus Repetition thereof will be omitted.
In addition, described feature, structure or characteristic can be incorporated in one or more implementations in any suitable manner In mode.In the following description, many details are provided to provide and fully understand to embodiments of the present invention.So And it will be appreciated by persons skilled in the art that technical solution of the present invention can be practiced and omit one in the specific detail Or more, or can be using other methods, constituent element, device, step etc..In other cases, it is not shown in detail or describes Known features, method, apparatus, realization, material or operation are to avoid a presumptuous guest usurps the role of the host and each aspect of the present invention is made to become mould Paste.
Fig. 1 is a kind of flow chart of unit test method based on Mock shown according to an illustrative embodiments.Such as Shown in Fig. 1, method 10 includes:
In step s 102, it when Mock object is created, is searched at least one pre-configured test case With the presence or absence of mapping class corresponding with Mock object and mapping method.
When unit testing program is activated, Mock object is usually shown or implicitly creates.When Mock object is shown It, can be by pre-configured corresponding relationship, at least one pre-configured test case when showing or implicitly creating In search whether exist mapping class corresponding with Mock object and mapping method.For example, when in the test case pre-defined In, when the defined corresponding class and method function of the Mock object, then it can find the mapping class and mapping method.
In step S104, if finding the mapping class and mapping method, the mapping method is obtained;As calling Mock When the method for object, the mapping method is executed, and returns to corresponding Mock data.
When unit testing program needs to call the method for executing Mock object, the mapping method is actually executed, and according to It inputs parameter and returns to corresponding Mock data, so that unit testing program continues to execute use.
In some embodiments, the test case in unit testing can carry out centralized management configuration by scripting language, from And the increasing of test case is fast implemented, deletes, change.When actually executing above-mentioned mapping method, by the corresponding script of Mock object class Content (script name can be set as consistent with class name) is read out, and by the script engine of calling Java Virtual Machine, then executes foot Corresponding mapping method in this.The script method returns to expected data by input parameter.Different input parameters, can generate Different response datas, therefore a large amount of test case can be configured in script.The response data of script method return is executed, It is returned by the serializing operation of Java at specific object, can be used as result data and continue to hold down in tested method Row.Above-mentioned scripting language, such as can be the Java Virtual Machines script engine branch such as Groovy, Python, JavaScript, Ruby The scripting language held.Further, it is also possible to realize the voluntarily verifying to test case in script.
The unit test method based on Mock of embodiment according to the present invention, can by configuring, without intrusively with unit Test program code combines, and previous unit testing is seamless merges, and coding cost is effectively reduced.
It will be clearly understood that the present disclosure describe how being formed and using particular example, but the principle of the present invention is not limited to These exemplary any details.On the contrary, the introduction based on present disclosure, these principles can be applied to many other Embodiment.
Fig. 2 is the flow chart according to another unit test method based on Mock shown in an illustrative embodiments. Fig. 2 shows when in unit testing by implicitly creating Mock object, skill is enhanced by bytecode inside Java Virtual Machine Art non-intrusion type is that unit testing use-case constructs corresponding Mock object, thus the method for carrying out unit testing based on Mock. As shown in Fig. 2, method 20 includes:
In step S202, entry program is executed by Java Virtual Machine (Java Virtual Machine, JVM).
The test class of unit testing is before start unit test, addition javaagent configuration, when it starts start unit When test.Pmock framing program for executing present embodiment method executes premain entrance journey by Java Virtual Machine Sequence.
In step S204, all methods of the class in loading unit test program are traversed.
In step S206, search whether exist and above-mentioned loading classes at least one pre-configured test case Corresponding mapping class and mapping method.
In step S208, if finding the mapping class and mapping method, is enhanced by bytecode, obtain the mapping class Corresponding Mock object and mapping method;When calling the method for loading classes, the mapping method is executed, and return to corresponding result Data.
Java bytecode enhancing technology refers to modifying to it after Java bytecode generates, enhancing its function. This mode, which is equivalent to, directly modifies to the binary file of application program.For there are mapping class and mapping method plus Class is carried, is enhanced by bytecode, is modified to its bytecode.When the loading method of unit testing routine call to the loading classes When, Java Virtual Machine can identify its enhanced bytecode, thereby executing the enhanced bytecode, and return corresponding Result data, so that unit testing program continues to execute use.
Similarly, in some embodiments, the test case in unit testing can be managed concentratedly by scripting language Configuration, to fast implement the increasing of test case, delete, change.It is when actually executing above-mentioned mapping method, Mock object class is corresponding Content for script (script name can be set as consistent with class name) read out, by call Java Virtual Machine script engine, then Corresponding mapping method in perform script.The script method returns to expected data by input parameter.Different input parameters, Different response datas can be generated, therefore a large amount of test case can be configured in script.Execute the sound of script method return Data are answered, is returned by the serializing operation of Java at specific object, be can be used as result data and continue in tested method In execute down.Above-mentioned scripting language, such as can be the Java Virtual Machines feet such as Groovy, Python, JavaScript, Ruby The scripting language that this engine is supported.Further, it is also possible to realize the voluntarily verifying to test case in script.
The unit test method based on Mock of embodiment according to the present invention, can be hidden to passing through in unit testing program The Mock object that formula mode creates with carrying out non-intrusion type code enhancing promotes code efficiency to reach reduction coding cost Purpose.
Fig. 3 is the flow chart of the unit test method according to another shown in an illustrative embodiments based on Mock. Fig. 3 is shown when showing statement Mock object in unit testing, how to pass through Java dynamic proxy inside Java Virtual Machine, The practical method for executing agent object when calling the method in Mock object, to carry out the side of unit testing based on Mock Method.As shown in figure 3, method 30 includes:
In step s 302, starting executes the unit testing class in the Pmock frame of present embodiment method.
Wherein, Mock object needed for the unit testing program is defined in a manner of statement by showing.
When unit testing program is after initializing Mock object and creating Mock object broker, on the one hand starting executes this reality Apply the unit testing class in the Pmock frame of methods;It on the other hand is all methods setting agency of Mock object broker Method.
In step s 304, at least one pre-configured test case is loaded, and is configured in Java Virtual Machine In memory.
Similarly, in some embodiments, the test case in unit testing can be managed concentratedly by scripting language Configuration, to fast implement the increasing of test case, delete, change.It is when actually executing above-mentioned mapping method, Mock object class is corresponding Content for script (script name can be set as consistent with class name) read out, by call Java Virtual Machine script engine, then Corresponding mapping method in perform script.The script method returns to expected data by input parameter.Different input parameters, Different response datas can be generated, therefore a large amount of test case can be configured in script.Execute the sound of script method return Data are answered, is returned by the serializing operation of Java at specific object, be can be used as result data and continue in tested method In execute down.Above-mentioned scripting language, such as can be the Java Virtual Machines feet such as Groovy, Python, JavaScript, Ruby The scripting language that this engine is supported.Further, it is also possible to realize the voluntarily verifying to test case in script.
In step S306, when unit testing routine call Mock object method, it is above-mentioned it is pre-configured at least One test case searches whether there is mapping class corresponding with Mock object and mapping method.
In step S308, if finding the mapping class and mapping method, by Java dynamic proxy, the mapping is obtained Method;When calling the method for loading classes, the mapping method is executed, and return to corresponding result data.
The mapping method is the Proxy Method in Java dynamic proxy technology.Agency is a kind of design pattern, is provided The access mode other to target object;Pass through agent object access target object.The advantage of doing so is that can be in mesh On the basis of marking object implementatio8, enhances additional feature operation, that is, extend the function of target object.In the present embodiment, lead to Java dynamic proxy technology is crossed, can be reached by corresponding mapping method in pre-configured test case to target pair As the purpose of (creating Mock object i.e. in unit testing program) modification enhancing.To in unit testing routine call loading classes When method, what is actually executed is the Proxy Method.
Similarly, in some embodiments, the test case in unit testing can be managed concentratedly by scripting language Configuration, to fast implement the increasing of test case, delete, change.It is when actually executing above-mentioned mapping method, Mock object class is corresponding Content for script (script name can be set as consistent with class name) read out, by call Java Virtual Machine script engine, then Corresponding mapping method in perform script.The script method returns to expected data by input parameter.Different input parameters, Different response datas can be generated, therefore a large amount of test case can be configured in script.Execute the sound of script method return Data are answered, is returned by the serializing operation of Java at specific object, be can be used as result data and continue in tested method In execute down.Above-mentioned scripting language, such as can be the Java Virtual Machines feet such as Groovy, Python, JavaScript, Ruby The scripting language that this engine is supported.Further, it is also possible to realize the voluntarily verifying to test case in script.
The unit test method based on Mock of embodiment according to the present invention, can be to side explicit in unit testing program The Mock object of formula statement, it is practical when calling the Mock object to execute modified agency by Java dynamic proxy technology Method promotes the purpose of code efficiency to reach reduction coding cost.
Fig. 4 is the interaction signal of the unit test method according to another shown in an illustrative embodiments based on Mock Figure.In the respective embodiments described above, test case is in technical interior off-line arrangement.And in method 40 shown in Fig. 4, Above-mentioned test case can also be obtained by Configuration Online center 404.It Configuration Online center 404, can be in actual implementation One and the independent application of unit testing engineering is activated individually, and disposes a database (such as MySQL database) wherein.? Line configuration center 404 can with configuration script editor module, with provide test case script typing, editor and store function and Online verification function.
As shown in figure 4, the Pmock frame 402 and Configuration Online center 404 for executing present embodiment method are only respectively It erects and sets, provide communication interface between the two, such as can be for using the communication interface of Http agreement.When in Pmock frame 402 The starting of Mock object when, corresponding test case foot can be obtained by sending Http request to Configuration Online center 404 This.Inside Configuration Online center 404, script read module is sent for receiving Mock object-request module in Pmock frame 402 Http request, and correspondingly from database obtain test case script.Script editor module is connect with database, will be edited Save in the database to good test case script persistence.
Fig. 5 is a kind of flow chart of unit test method shown according to an illustrative embodiments.Method shown in fig. 5 50 be suitable for phase of integration testing is used in combination with Spring container, can by based on Mock unit testing and integration testing ring Border blends.As shown in figure 5, method 50 includes:
In step S502, when the test object in Spring container is injected, at least one pre-configured Search whether there is mapping class corresponding with the test object and mapping method in test case.
Spring is JavaSE/EE full-stack (one-stop) lightweight open source frame of a layering.It can pass through PostProcessAfterInitializaion in the BeanPostProcess class method of Spring, carries out examination Spring Whether the object of container injection, which is tested to be configured with case script, maps, namely uses at least one pre-configured test Search whether there is mapping class corresponding with the test object and mapping method in example.
Specifically, such as the test object module of all injections can be intercepted when Spring container injects test object, And start the Pmock frame for executing present embodiment method, at least one preconfigured test case is loaded, and check one by one Whether mapped with the test object of injection.
In step S504, if finding the mapping class and mapping method, the mapping method is obtained;It is tested when calling When the method for object, the mapping method is executed, and returns to corresponding result data.
In at least one preconfigured test case of load, the test object for searching whether and injecting one by one exists Mapping relations.If it is present obtaining the mapping method.For example, Java dynamic proxy can be carried out to the test object of injection, To obtain the mapping method (i.e. the Proxy Method of agent object).So that calling the test object in Spring container When method, the practical method for executing agent object, and corresponding implementing result is returned to according to input parameter, for being integrated in Spring Unit testing in frame continues to use.
The unit test method of embodiment according to the present invention can formulate class to any in the starting of Spring container Bean carry out Mock object broker, thus and the unit testing seamless combination based on integration testing, become based on Mock's Unit testing.
It will be appreciated by those skilled in the art that realizing that all or part of the steps of above embodiment is implemented as being held by CPU Capable computer program.When the computer program is executed by CPU, execute above-mentioned defined by the above method provided by the invention Function.The program can store in a kind of computer readable storage medium, which can be read-only memory, Disk or CD etc..
Further, it should be noted that above-mentioned attached drawing is only according to the present invention included by the method for illustrative embodiments Processing schematically illustrates, rather than limits purpose.It can be readily appreciated that above-mentioned processing shown in the drawings does not indicate or limits these The time sequencing of processing.In addition, being also easy to understand, these processing, which can be, for example either synchronously or asynchronously to be executed in multiple modules 's.
Following is apparatus of the present invention embodiment, can be used for executing embodiment of the present invention method.For apparatus of the present invention reality Undisclosed details in example is applied, embodiment of the present invention method is please referred to.
Fig. 6 is a kind of block diagram of unit testing device based on Mock shown according to an illustrative embodiments.Such as Fig. 6 Shown, device 60 includes: method searching module 602 and method execution module 604.
Wherein, method searching module 602 is used for when Mock object is created, at least one pre-configured test Search whether there is mapping class corresponding with the Mock object and mapping method in use-case.
Method execution module 604 is used for when method searching module 602 finds the mapping class and its mapping method, is obtained The mapping method;And when calling the method for the Mock object, the mapping method is executed, and return to corresponding Mock data, with The Mock data are continued to use for unit testing.
The unit testing device based on Mock of embodiment according to the present invention, can by configuring, without intrusively with unit Test program code combines, and previous unit testing is seamless merges, and coding cost is effectively reduced.
Fig. 7 is a kind of block diagram of unit testing device shown according to an illustrative embodiments.As shown in fig. 7, device 70 include: method searching module 702 and method execution module 704.
Wherein, method searching module 702 is used for when the test object in Spring container is injected, pre-configured At least one test case in search whether exist mapping class corresponding with test object and mapping method.
Method execution module 704 is used for when method searching module finds mapping class and mapping method, obtains mapping side Method;And when calling the method for the test object, mapping method is executed, and return to corresponding result data.
The unit testing device of embodiment according to the present invention can formulate class to any in the starting of Spring container Bean carry out Mock object broker, thus and the unit testing seamless combination based on integration testing, become based on Mock's Unit testing.
It should be noted that above-mentioned block diagram shown in the drawings is functional entity, not necessarily must with physically or logically Independent entity is corresponding.Can realize these functional entitys using software form, or in one or more hardware modules or These functional entitys are realized in integrated circuit, or are realized in heterogeneous networks and/or processor device and/or microcontroller device These functional entitys.
Fig. 8 is a kind of structural schematic diagram of computer system shown according to an illustrative embodiments.It needs to illustrate That the computer system shown in Fig. 8 is only an example, should not function to the embodiment of the present application and use scope bring and appoint What is limited.
As shown in figure 8, computer system 800 includes central processing unit (CPU) 801, it can be read-only according to being stored in Program in memory (ROM) 802 or be loaded into the program in random access storage device (RAM) 803 from storage section 808 and Execute various movements appropriate and processing.In RAM 803, also it is stored with system 800 and operates required various programs and data. CPU 801, ROM 802 and RAM 803 are connected with each other by bus 804.Input/output (I/O) interface 805 is also connected to always Line 804.
I/O interface 805 is connected to lower component: the importation 806 including keyboard, mouse etc.;It is penetrated including such as cathode The output par, c 807 of spool (CRT), liquid crystal display (LCD) etc. and loudspeaker etc.;Storage section 808 including hard disk etc.; And the communications portion 809 of the network interface card including LAN card, modem etc..Communications portion 809 via such as because The network of spy's net executes communication process.Driver 810 is also connected to I/O interface 805 as needed.Detachable media 811, such as Disk, CD, magneto-optic disk, semiconductor memory etc. are mounted on as needed on driver 810, in order to read from thereon Computer program be mounted into storage section 808 as needed.
Particularly, in accordance with an embodiment of the present disclosure, it may be implemented as computer above with reference to the process of flow chart description Software program.For example, embodiment of the disclosure includes a kind of computer program product comprising be carried on computer-readable medium On computer program, which includes the program code for method shown in execution flow chart.In such reality It applies in example, which can be downloaded and installed from network by communications portion 809, and/or from detachable media 811 are mounted.When the computer program is executed by central processing unit (CPU) 801, executes and limited in the system of the application Above-mentioned function.
It should be noted that computer-readable medium shown in the application can be computer-readable signal media or meter Calculation machine readable storage medium storing program for executing either the two any combination.Computer readable storage medium for example can be --- but not Be limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor system, device or device, or any above combination.Meter The more specific example of calculation machine readable storage medium storing program for executing can include but is not limited to: have the electrical connection, just of one or more conducting wires Taking formula computer disk, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type may be programmed read-only storage Device (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light storage device, magnetic memory device, Or above-mentioned any appropriate combination.In this application, computer readable storage medium can be it is any include or storage journey The tangible medium of sequence, the program can be commanded execution system, device or device use or in connection.And at this In application, computer-readable signal media may include in a base band or as carrier wave a part propagate data-signal, Wherein carry computer-readable program code.The data-signal of this propagation can take various forms, including but unlimited In electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be that computer can Any computer-readable medium other than storage medium is read, which can send, propagates or transmit and be used for By the use of instruction execution system, device or device or program in connection.Include on computer-readable medium Program code can transmit with any suitable medium, including but not limited to: wireless, electric wire, optical cable, RF etc. are above-mentioned Any appropriate combination.
Flow chart and block diagram in attached drawing are illustrated according to the system of the various embodiments of the application, method and computer journey The architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generation A part of one module, program segment or code of table, a part of above-mentioned module, program segment or code include one or more Executable instruction for implementing the specified logical function.It should also be noted that in some implementations as replacements, institute in box The function of mark can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are practical On can be basically executed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.Also it wants It is noted that the combination of each box in block diagram or flow chart and the box in block diagram or flow chart, can use and execute rule The dedicated hardware based systems of fixed functions or operations is realized, or can use the group of specialized hardware and computer instruction It closes to realize.
Being described in unit involved in the embodiment of the present application can be realized by way of software, can also be by hard The mode of part is realized.Described unit also can be set in the processor, for example, can be described as: a kind of processor packet Include transmission unit, acquiring unit, determination unit and first processing units.Wherein, the title of these units is under certain conditions simultaneously The restriction to the unit itself is not constituted, for example, transmission unit is also described as " sending picture to the server-side connected The unit of acquisition request ".
As on the other hand, present invention also provides a kind of computer-readable medium, which be can be Included in equipment described in above-described embodiment;It is also possible to individualism, and without in the supplying equipment.Above-mentioned calculating Machine readable medium carries one or more program.When said one or multiple programs are executed by the equipment, make Obtaining the equipment includes:
When Mock object is created, search whether to exist at least one pre-configured test case and Mock The corresponding mapping class of object and mapping method;And
If finding mapping class and mapping method:
Obtain mapping method;And
When calling the method for Mock object, mapping method is executed, and return to corresponding Mock data.
Alternatively, when said one or multiple programs are executed by the equipment, so that the equipment includes:
When the test object in Spring container is injected, searched at least one pre-configured test case With the presence or absence of mapping class corresponding with the test object and mapping method;And
If finding the mapping class and the mapping method:
Obtain the mapping method;And
When calling the method for the test object, the mapping method is executed, and return to corresponding result data.
It is particularly shown and described exemplary embodiments of the present invention above.It should be appreciated that the present invention is unlimited In detailed construction described herein, set-up mode or implementation method;On the contrary, it is intended to cover included in appended claims Spirit and scope in various modifications and equivalence setting.

Claims (14)

1. a kind of unit test method based on Mock characterized by comprising
When Mock object is created, search whether exist and the Mock at least one pre-configured test case The corresponding mapping class of object and mapping method;And
If finding the mapping class and the mapping method:
Obtain the mapping method;And
When calling the method for the Mock object, the mapping method is executed, and return to corresponding Mock data.
2. the method according to claim 1, wherein at least one described test case is carried out by scripting language Configuration.
3. method according to claim 1 or 2, which is characterized in that obtaining the mapping method includes: to be increased by bytecode By force, the mapping method is obtained.
4. method according to claim 1 or 2, which is characterized in that obtaining the mapping method includes: by Java dynamic Agency, obtains the mapping method.
5. method according to claim 1 or 2, which is characterized in that at least one pre-configured test case It searches whether in the presence of before mapping class corresponding with the Mock object and mapping method, further includes: asked from remote database Seek at least one described test case of acquisition.
6. a kind of unit test method characterized by comprising
When the test object in Spring container is injected, searched whether at least one pre-configured test case In the presence of mapping class corresponding with the test object and mapping method;And
If finding the mapping class and the mapping method:
Obtain the mapping method;And
When calling the method for the test object, the mapping method is executed, and return to corresponding result data.
7. according to the method described in claim 6, it is characterized in that, at least one described test case is carried out by scripting language Configuration.
8. method according to claim 6 or 7, which is characterized in that obtaining the mapping method includes: by Java dynamic Agency, obtains the mapping method.
9. a kind of unit testing device based on Mock characterized by comprising
Method searching module, for being searched at least one pre-configured test case when Mock object is created With the presence or absence of mapping class corresponding with the Mock object and mapping method;And
Method execution module, for obtaining when the method searching module finds the mapping class and the mapping method The mapping method;And when calling the method for the Mock object, the mapping method is executed, and return to corresponding Mock number According to.
10. a kind of unit testing device characterized by comprising
Method searching module, for when the test object in Spring container is injected, at least one pre-configured Search whether there is mapping class corresponding with the test object and mapping method in test case;And
Method execution module, for obtaining when the method searching module finds the mapping class and the mapping method The mapping method;And when calling the method for the test object, the mapping method is executed, and return to corresponding number of results According to.
11. a kind of computer equipment, comprising: memory, processor and storage are in the memory and can be in the processor The executable instruction of middle operation, which is characterized in that the processor realizes such as claim 1-5 when executing the executable instruction Described in any item methods.
12. a kind of computer equipment, comprising: memory, processor and storage are in the memory and can be in the processor The executable instruction of middle operation, which is characterized in that the processor realizes such as claim 6-8 when executing the executable instruction Described in any item methods.
13. a kind of computer readable storage medium, is stored thereon with computer executable instructions, which is characterized in that described to hold Row instruction realizes the method according to claim 1 to 5 when being executed by processor.
14. a kind of computer readable storage medium, is stored thereon with computer executable instructions, which is characterized in that described to hold Row instruction realizes such as the described in any item methods of claim 6-8 when being executed by processor.
CN201811431921.8A 2018-11-28 2018-11-28 Unit test method, device, equipment and readable storage medium storing program for executing based on Mock Pending CN109614322A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811431921.8A CN109614322A (en) 2018-11-28 2018-11-28 Unit test method, device, equipment and readable storage medium storing program for executing based on Mock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811431921.8A CN109614322A (en) 2018-11-28 2018-11-28 Unit test method, device, equipment and readable storage medium storing program for executing based on Mock

Publications (1)

Publication Number Publication Date
CN109614322A true CN109614322A (en) 2019-04-12

Family

ID=66005681

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811431921.8A Pending CN109614322A (en) 2018-11-28 2018-11-28 Unit test method, device, equipment and readable storage medium storing program for executing based on Mock

Country Status (1)

Country Link
CN (1) CN109614322A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110716919A (en) * 2019-09-23 2020-01-21 贝壳技术有限公司 Mock testing method, Mock testing device and storage medium
CN111078631A (en) * 2019-12-20 2020-04-28 广州品唯软件有限公司 File processing method, terminal device and storage medium
CN113535538A (en) * 2020-04-21 2021-10-22 网联清算有限公司 Application full-link automatic testing method and device, electronic equipment and storage medium
CN113535564A (en) * 2021-07-19 2021-10-22 中国工商银行股份有限公司 Storage process testing method and device
CN114528214A (en) * 2022-02-18 2022-05-24 马上消费金融股份有限公司 Unit testing method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10089219B1 (en) * 2017-01-20 2018-10-02 Intuit Inc. Mock server for testing
CN108647143A (en) * 2018-05-09 2018-10-12 平安普惠企业管理有限公司 MOCK interface test methods, device, computer equipment and storage medium
CN108829584A (en) * 2018-05-24 2018-11-16 携程计算机技术(上海)有限公司 service logic interface Mock test method and system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10089219B1 (en) * 2017-01-20 2018-10-02 Intuit Inc. Mock server for testing
CN108647143A (en) * 2018-05-09 2018-10-12 平安普惠企业管理有限公司 MOCK interface test methods, device, computer equipment and storage medium
CN108829584A (en) * 2018-05-24 2018-11-16 携程计算机技术(上海)有限公司 service logic interface Mock test method and system

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
DUANXZ: "JVM插码之三:javaagent介绍及javassist介绍", 《HTTPS://WWW.CNBLOGS.COM/DUANXZ/P/4957932.HTML》 *
京东数科: "各位都是怎么进行单元测试的", 《HTTPS://WWW.ZHIHU.COM/QUESTION/27313846》 *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110716919A (en) * 2019-09-23 2020-01-21 贝壳技术有限公司 Mock testing method, Mock testing device and storage medium
CN111078631A (en) * 2019-12-20 2020-04-28 广州品唯软件有限公司 File processing method, terminal device and storage medium
CN111078631B (en) * 2019-12-20 2024-01-30 广州品唯软件有限公司 File processing method, terminal equipment and storage medium
CN113535538A (en) * 2020-04-21 2021-10-22 网联清算有限公司 Application full-link automatic testing method and device, electronic equipment and storage medium
CN113535538B (en) * 2020-04-21 2023-06-16 网联清算有限公司 Method, device, electronic equipment and storage medium for automatically testing application full link
CN113535564A (en) * 2021-07-19 2021-10-22 中国工商银行股份有限公司 Storage process testing method and device
CN114528214A (en) * 2022-02-18 2022-05-24 马上消费金融股份有限公司 Unit testing method and device

Similar Documents

Publication Publication Date Title
CN109614322A (en) Unit test method, device, equipment and readable storage medium storing program for executing based on Mock
US8601434B2 (en) Method and system for information processing and test case generation
CN108347358A (en) The automatic test of cloud connection
CN108932194A (en) Automated testing method, device, system, medium and electronic equipment
CN108958992A (en) test method and device
CN109062563B (en) Method and device for generating page
CN107273297A (en) Method and apparatus for generating test case
CN112187558B (en) Data verification method and device and electronic equipment
CN110716853A (en) Test script recording method, application program testing method and related device
CN109684188B (en) Test method and device
CN112256321A (en) Static library packaging method and device, computer equipment and storage medium
CN110543297A (en) method and apparatus for generating source code
CN113238740B (en) Code generation method, code generation device, storage medium and electronic device
CN111309624B (en) Test method, test device, test equipment and storage medium
CN109739526A (en) Code update method and device
CN109992496A (en) A kind of data processing method and device for automatic test
CN109240923B (en) Interface test script generation method and computer readable storage medium
CN112988588A (en) Client software debugging method and device, storage medium and electronic equipment
CN117520190A (en) Cloud desktop client and test execution method thereof
CN112988578A (en) Automatic testing method and device
CN116795701A (en) Method and device for generating universal test case of interface program
CN111061522A (en) Method, device, equipment and storage medium for generating front-end card assembly based on back end
CN110489326A (en) HTTPAPI adjustment method device, medium and equipment based on IDS
CN115408009A (en) Code file generation method, device, equipment and storage medium
CN109145591A (en) The plug-in loading method of application program

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Room 221, 2nd floor, Block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone, 100176

Applicant after: Jingdong Digital Technology Holding Co., Ltd.

Address before: Room 221, 2nd floor, Block C, 18 Kechuang 11th Street, Daxing Economic and Technological Development Zone, Beijing, 100176

Applicant before: Beijing Jingdong Financial Technology Holding Co., Ltd.

RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20190412