CN105335281A - Method and device for automatic mock of external dependency - Google Patents
Method and device for automatic mock of external dependency Download PDFInfo
- Publication number
- CN105335281A CN105335281A CN201410370258.0A CN201410370258A CN105335281A CN 105335281 A CN105335281 A CN 105335281A CN 201410370258 A CN201410370258 A CN 201410370258A CN 105335281 A CN105335281 A CN 105335281A
- Authority
- CN
- China
- Prior art keywords
- mock
- call
- outside
- eigenwert
- value
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 64
- 238000010998 test method Methods 0.000 claims description 6
- 238000009434 installation Methods 0.000 claims description 5
- 230000000903 blocking effect Effects 0.000 claims description 4
- 238000012360 testing method Methods 0.000 abstract description 56
- 230000003247 decreasing effect Effects 0.000 abstract 1
- 230000000875 corresponding effect Effects 0.000 description 45
- 238000010586 diagram Methods 0.000 description 4
- 230000000694 effects Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 2
- 230000007547 defect Effects 0.000 description 2
- 230000001419 dependent effect Effects 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 230000002596 correlated effect Effects 0.000 description 1
- 238000011835 investigation Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000012163 sequencing technique Methods 0.000 description 1
- 238000004088 simulation Methods 0.000 description 1
- 238000013522 software testing Methods 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The invention discloses a method and device for automatic mock of external dependency. The method comprises the following steps: obtaining a tested code name, an invocation parameter and an invocation frequency through using a recording mechanism so as to generate a mock characteristic value; and obtaining a returned value or a returned object of the external dependency, serializing into a returned text, and enabling the mock characteristic value to correspond to the returned text so as to obtain a mock object of the external dependency of the tested code. The obtained mock object is generated through recording in a real environment, so that the mock object is closer to the real external dependency; and the mock object is created by using the recording mechanism, not an encoding manner or a configuration manner, so that the workload of code compiling and configuration is decreased, the test efficiency can be greatly improved and the test cost is reduced.
Description
Technical field
The present invention relates to software testing technology field, particularly relate to a kind of method and device of automatic mock outside dependence.
Background technology
Program test is an important ring of program development.Unit testing is other test activity of lowermost level in program test, and described unit is tested functional block minimum in program test or code unit.In unit testing, to need to call the outside program module relied on test time, be often difficult to structure because outside relies on or obtain, unit testing can be caused to carry out, or outsidely relying on unstable, causing that test failure rate is high, investigation cost is large.For solving problems, mock (simulation) is usually adopted to test.Described mock test refers to that the virtual object of establishment one substitutes outside dependence and tests, and the virtual objects of establishment is called mock object.Present stage, mock test has two kinds of modes:
1, in test code, mock object is write, such as Jmockit (helping developer to write one group of instrument and the application programming interface of test procedure).When writing unit testing use-case in test code, statement wants the outside of mock to rely on object, and the method for object, the mock object created thus, according to the parameter imported into, returns fixing value, therefore when real execution test, do not need to call genuine outside dependence, but call the mock object of establishment, thus isolation program module and outside dependence, avoid outside to rely on de-stabilising effect test effect.
2, set up long-range mock platform, directly do not connect real outside during unit testing and rely on environment, but be connected on long-range mock platform, provide mock storehouse by platform, test man can create and editing data on platform simultaneously.Long-range mock platform can provide the centralized management of mock object, avoids because outside dependence environment changes or data change causes unit testing failure.
Inventor finds above-mentioned 1st kind of mode and the 2nd kind of mode existing defects and problems in the process realizing the application:
Above-mentioned 1st kind of mode, although directly calling outside dependence can be avoided by writing mock object in code, there is following two problems: one is that size of code is many, and too much mock test code causes workload to increase, testing efficiency is low, and probability increase code being neglected, makes mistakes; Two is adopt the mode of code to write mock object completely, and because rreturn value is defined by oneself, the not outside truth relied on of the form that may define or implication, makes mock object can not reflect outside dependence truly.
, also there are following three problems in above-mentioned 2nd kind of mode: one is that versatility is inadequate, and which can only support the program module of remote interface, can not be applicable to this locality and call, two is that configuration effort amount is large, and create a mock object, need configuration suction parameter, method of calling, rreturn value etc., when needing the parameter more complicated of configuration, structure workload will be very large, and testing efficiency can be very low, and probability of makeing mistakes increases, three is that authenticity is still lower, because mock object is still primarily of writing and configuring generation, and be difficult to realize true outside dynamically the returning of having of relying on: owing to being remote access mode, mock remote platform can not logging program unit to the call number of mock object, therefore the mock object on it can only return a fixed value to same suction parameter, the mock object needing dynamically to return different value according to call number cannot be created, such as register, true (success) is returned during a user name first time registration, expression is succeeded in registration, when reusing identical user name registration, return false (failure), represent that user name is registered, identical user name registration can not be used, but long-range mock platform cannot realize real registration.
Summary of the invention
For overcoming in correlation technique the efficiency that creates mock object and low problem, a kind of method that the application provides automatic mock outside to rely on and the device of authenticity.
According to the first aspect of the embodiment of the present application, a kind of method providing automatic mock outside to rely on, comprising:
Obtain the title of tested code, and obtain call parameters and the call number of described tested code call outside dependence;
Obtain outside dependence the described rreturn value or the returning an object value that call generation;
Mock eigenwert is generated according to the title of described tested code, call parameters and call number;
The rreturn value rely on described outside or returning an object value sequence turn to returned text;
By corresponding with described returned text for described mock eigenwert, described mock eigenwert and corresponding described returned text form mock object.
Optionally, the title of the tested code of described acquisition, and the call parameters and the call number that obtain the dependence of tested code call outside, comprising:
That tackles that described tested code relies on outside calls;
Record the title of tested code, call parameters and call number.
Optionally, describedly obtain outside dependence the described rreturn value called or returning an object value, comprising:
Outside dependence is called according to described call parameters and call number;
The rreturn value of the outside dependence of record or returning an object value.
Wherein, hash algorithm is used to generate mock eigenwert according to the title of tested code, call parameters and call number.
According to the second aspect of the embodiment of the present application, the device providing a kind of automatic mock outside to rely on, comprising:
Tested end data acquisition module, for obtaining the title of tested code, and obtains call parameters and the call number of the dependence of tested code call outside;
Outer end data acquisition module, for obtaining outside dependence the described rreturn value or the returning an object value that call generation;
Mock object generation module, mock eigenwert is generated for the title according to tested code, call parameters and call number, the rreturn value rely on described outside or returning an object value sequence turn to returned text, and by corresponding with described returned text for described mock eigenwert, described mock eigenwert and corresponding returned text form mock object;
Memory module, for storing described mock object.
Optionally, described tested end data acquisition module, comprising:
Tested end interception submodule, for calling of tackling that tested code relies on outside;
Tested end record sub module, for recording the title of tested code, call parameters and call number.
Optionally, described outer end data acquisition module, comprising:
Call submodule, for calling outside dependence according to described call parameters and call number;
Outer end record sub module, for recording rreturn value or the returning an object value of outside dependence.
Optionally, described mock object generation module, comprising:
Mock eigenwert generates submodule, generates mock eigenwert for the title according to tested code, call parameters and call number;
Serializing submodule, for turning to returned text by the rreturn value of described outside dependence or returning an object value sequence;
Build submodule, for described mock eigenwert is corresponding with the rreturn value that described outside relies on or returning an object value, the rreturn value that described mock eigenwert and corresponding described outside rely on or returning an object value form mock object.
According to the third aspect of the embodiment of the present application, a kind of mock method of testing is provided, comprises:
That tackles that tested code relies on outside calls;
Obtain the title of tested code, call parameters and call number;
Generate according to the title of described tested code, call parameters and call number and call eigenwert, and described in call the generation method of eigenwert identical with the generation method of mock eigenwert in mock object;
In mock object, corresponding returned text is searched according to described eigenwert of calling;
Returned text described in unserializing, obtains rreturn value or the returning an object value of outside dependence;
Described rreturn value or returning an object value are returned to tested code;
Verify described rreturn value or returning an object value.
According to the fourth aspect of the embodiment of the present application, a kind of mock proving installation is provided, comprises:
Call blocking module, for calling of tackling that tested code relies on outside;
Data acquisition module, obtains the title of tested code, call parameters and call number;
Call eigenwert generation module, generate for the title according to described tested code, call parameters and call number and call eigenwert, and described in call the generation method of eigenwert identical with the generation method of mock eigenwert in mock object;
Searching module, in mock object, searching corresponding returned text for calling eigenwert described in basis;
Unserializing module, for returned text described in unserializing, obtains rreturn value or the returning an object value of outside dependence;
Return module, for described rreturn value or returning an object value are returned to tested code;
Authentication module, for verifying described rreturn value or returning an object value.
The technical scheme that the embodiment of the present application provides, use the mechanism of recording, when tested code call outside relies on, tackle this to call, record the title of tested code, call parameters and call number, mock eigenwert is generated according to the title of tested code, call parameters and call number, and substitute the dependence of tested code call outside, the rreturn value of the outside dependence of interception simultaneously or returning an object value, after rreturn value or returning an object value sequence are turned to returned text, by corresponding with returned text for mock eigenwert, obtain the mock object that tested code outside relies on therefrom.This process, is equivalent to by recording the suction parameter and rreturn value or returning an object value that outside corresponding to tested code rely on, and the corresponding relation between suction parameter and rreturn value or returning an object value, recorded outside dependence.Using mock eigenwert and rreturn value to characterize mock object, make mock object form more succinct, calling eigenwert for index when testing with corresponding with mock eigenwert, corresponding rreturn value can be found more quickly, realize mock test.The technical scheme of the automatic mock external object that the embodiment of the present application provides can comprise following beneficial effect:
1, mock object authenticity is improved: because mock records generation to liking in true environment, therefore closer to real outside dependence;
2, testing efficiency is improved: use the mechanism of recording and non-coded manner creates mock object, greatly reduce the workload of writing code, and code is more simplified and is easy to grasp, mock object and related data all generate by recording simultaneously, do not rely on form regulation, parameter also can obtain mock object time complicated fast, greatly can improve testing efficiency, reduces testing cost;
3, versatility is improved: any outside can be recorded and rely on, comprise and long-rangely to rely on outside that is this locality;
4, dynamically returning based on call number can be realized: recording the related data recording call number and call at every turn in mock Object Process, containing rreturn value corresponding to each call number in the mock object obtained, therefore can obtain dynamic rreturn value according to call number when testing.
The technical scheme of the mock test that the embodiment of the present application provides, based on the technical scheme that above-mentioned automatic mock outside relies on, when testing, the allocating object of real outside dependence as tested code is substituted using mock object, according to the title of tested code, call parameters and call number generate calls eigenwert, returned text corresponding in mock object is indexed according to the eigenwert of calling corresponding and equal with mock eigenwert, after returned text being deserialized as rreturn value or returning an object value, rreturn value or returning an object value are back to tested code, verify that described rreturn value completes test.The technical scheme of the mock test that the embodiment of the present application provides, following beneficial effect can be comprised: test code is succinct, and only need generate the returned text calling eigenwert, search correspondence, returned text unserializing just can be implemented once to test, testing efficiency is high; And due to the authenticity of mock object high, test can more be tallied with the actual situation, and it is more accurate to test.
Should be understood that, it is only exemplary and explanatory that above general description and details hereinafter describe, and can not limit the application.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present application or technical scheme of the prior art, be briefly described to the accompanying drawing used required in embodiment or description of the prior art below, apparently, for those of ordinary skills, under the prerequisite not paying creative work, other accompanying drawing can also be obtained according to these accompanying drawings.
Fig. 1 is the schematic flow sheet of the method that a kind of automatic mock outside shown in the application one exemplary embodiment relies on.
Fig. 2 is the block diagram of the device that a kind of automatic mock outside shown in the application one exemplary embodiment relies on.
Fig. 3 is the schematic flow sheet of a kind of mock method of testing shown in the application one exemplary embodiment.
Fig. 4 is the block diagram of a kind of mock proving installation shown in the application one exemplary embodiment.
Embodiment
Here will be described exemplary embodiment in detail, its sample table shows in the accompanying drawings.When description below relates to accompanying drawing, unless otherwise indicated, the same numbers in different accompanying drawing represents same or analogous key element.Embodiment described in following exemplary embodiment does not represent all embodiments consistent with the application.On the contrary, they only with as in appended claims describe in detail, the example of apparatus and method that some aspects of the application are consistent.
In order to complete understanding the application, refer to numerous concrete details in the following detailed description, but it should be appreciated by those skilled in the art that the application can realize without the need to these details.In other embodiments, be not described in detail known method, process, assembly and circuit, in order to avoid unnecessarily cause embodiment fuzzy.
In first aspect, a kind of method that the application provides automatic mock outside to rely on.Fig. 1 is the schematic flow sheet of the method that a kind of automatic mock outside shown in the application one exemplary embodiment relies on.As shown in Figure 1, described method can comprise:
In step S101, obtain the title of tested code, and obtain call parameters and the call number of the dependence of tested code call outside.
Wherein, in a kind of possible embodiment, when running tested code in unit testing process, can by the mode of assignment, obtain the title of tested code, and the call parameters that relies on of tested code call outside and call number, such as, in unit testing process, before tested code call outside relies on or while calling outside dependence, give its dependent variable by the optimum configurations assignment of the title of tested code and current tested code, namely this variable obtains rreturn value or returning an object value, and described optimum configurations comprises call parameters and call number.
In a preferred embodiment, when running tested code in unit testing process, that tackles that tested code relies on outside calls, and described interception can be conventional routine call hold-up interception method, then obtains and records the title of tested code, call parameters and call number.Obtain call parameters and comprise the title, value and the type that obtain call parameters.Call number is for which time to call outside dependence, and outside rreturn value being depended on to call number relies on, the outside rreturn value that relies on or returning an object value when needing repeatedly to run tested code to obtain different number of times.The title of tested code keeps in operation afterwards after can obtaining when tested code first time is run, and call parameters and call number obtain when each run.The title of tested code is used for the mock object of generation and tested code to be mapped.
In step s 102, outside dependence the described rreturn value or the returning an object value that call generation is obtained.
Wherein, in the preferred mode of one, when using the mode of interception to obtain the title of tested code, call parameters and call number in step S101, in step s 102, first can call outside dependence according to described call parameters and call number, what replace that tested code relies on outside calls, by using record when time call parameters and call number input to outside dependence as suction parameter, what realize relying on outside calling.Using record when time call parameters and after call number to input to outside dependence as suction parameter, outside dependence can according to suction parameter output rreturn value or returning an object value.Then receive and record the outside rreturn value or the returning an object value that rely on output, that is rreturn value or returning an object value are not directly back to tested code, but be blocked and have recorded, rreturn value or returning an object value can be transmitted back to tested code after record.
In the embodiment that another kind is possible, can be obtained by the mode of assignment and outside rely on rreturn value or returning an object value that tested code call is produced, such as, when tested code receives rreturn value or the returning an object value of outside dependence, the rreturn value receive tested code or returning an object value simultaneously assignment give its dependent variable, and namely this variable obtains rreturn value or returning an object value.
The mode of interception is used to obtain the title of tested code, call parameters and call number, tested code and outside dependence can be isolated, the mode comparing assignment more stably can obtain the data of being correlated with, because when using the mode of assignment, need among tested code, to insert extra code to carry out assignment, affect the structure of tested code itself, run probability of makeing mistakes high.
In step s 103, mock eigenwert is generated according to the title of described tested code, call parameters and call number.
In step S104, the rreturn value rely on described outside or returning an object value sequence turn to returned text.
In step S105, by corresponding with described returned text for described mock eigenwert, described mock eigenwert and corresponding described returned text form mock object.
Wherein, hash algorithm can be used to generate mock eigenwert according to the title of tested code, call parameters and call number.Described mock eigenwert is unique.The returning an object value relied on due to outside needs could to be preserved and transmit by serializing, and the rreturn value therefore relied on outside or returning an object value sequence turn to returned text, and described serializing can use conventional sequencing method.Consistent for ensureing the outside form returned results relied on, therefore also serializing is carried out to rreturn value.First can generate mock eigenwert according to the title of tested code, call parameters and call number, then by rreturn value or returning an object value serializing; Also can first by rreturn value or returning an object value serializing, then generate mock eigenwert according to the title of tested code, call parameters and call number; The serializing generating mock eigenwert and rreturn value or returning an object value also can be carried out simultaneously.
Because rreturn value and returning an object value need to preserve after serializing and transmission, replacing by generating mock eigenwert the text after the title of tested code, call parameters and call number and serializing corresponding, corresponding relation can be made more succinct and accurately, not easily make mistakes.Rreturn value or returning an object value serializing are also helped the storage of rreturn value or returning an object value, maintenance and Internet Transmission.
The more important thing is, when utilizing described mock object to carry out mock test, obtain corresponding returning results according to the suction parameter being supplied to mock object, in this application, by suction parameter and the outside correspondence that returns results relied on are formed mock object, thus overcoming coded system and configuration mode, to build mock object workload large, low and the defect that authenticity is not high of efficiency, but suction parameter is usually a lot, searched by suction parameter and corresponding return results (i.e. returned text) searching work amount will be made very large, lookup algorithm also will become very complicated and be difficult to realize.And after generating unique mock eigenwert according to suction parameter (title of tested code, call parameters and call number), suction parameter is characterized with mock eigenwert, corresponding returned text is searched by mock eigenwert, lookup algorithm can be made very simply, easily to realize, and search efficiency is high.
After obtaining mock eigenwert and returned text, can using mock eigenwert as index, mock eigenwert and returned text as the value of index, thus are mapped by returned text.Each mock eigenwert and corresponding returned text are considered as a mock object.Same tested code, because the difference of call parameters and call number can corresponding multiple mock object, but contain the title of tested code in the generative process due to mock eigenwert in the application, and each mock eigenwert is unique, therefore during mock test, only need according to the title of tested code, call parameters and call number generate calls eigenwert, the mock eigenwert equal with calling eigenwert is found according to calling eigenwert, corresponding mock object can be found uniquely, therefore when carrying out mock test, do not need to go to search each mock object according to the title of tested code, the mock object corresponding with current call parameters and call number is searched again in each mock object, thus mock test process can be made more accurately succinct.
The mock object generated can be stored in local mock storehouse, also can be stored in long-range mock platform.Same tested code, after the different call parameters of use and call number generate multiple mock object, preferably described multiple mock object can as one group of mock object Coutinuous store in the mock storehouse of this locality or distant place mock platform, because the mock eigenwert of each mock object is unique, multiple mock objects corresponding to same tested code also can disperse to store, even if therefore make the order stored between different mock objects be upset owing to storing error in storing process, also mock test process and test result can not be affected.
The method that a kind of automatic mock outside that the application provides relies on, when applying, the mode of the tested code of circular flow can be used, different call parameters and call number is used during the tested code of each run, tested code loop moves to when all call parameters and call number are finished using and terminates to run, the tested code of each run is according to the title of tested code, rreturn value or the returning an object value of call parameters and call number and outside dependence generate a mock object, at the end of the circular flow of tested code, all mock objects corresponding to tested code all generate.Use the mode of circular flow can avoid the tested code of each artificial operation.Wherein, different call parameters and the selection of call number can be determined according to the object of mock test.
All generate complete when the mock object that same tested code is corresponding and after storing, just can repeatedly test according to different call parameters and call number and repeatedly test in mock test, make mock test process more simple and convenient.
By the description of above embodiment of the method, those skilled in the art can be well understood to the mode that the application can add required general hardware platform by software and realize, hardware can certainly be passed through, but in a lot of situation, the former is better embodiment.Based on such understanding, the technical scheme of the application can embody with the form of software product the part that prior art contributes in essence in other words, and be stored in a storage medium, comprise all or part of step of some instructions in order to make a smart machine perform method described in each embodiment of the application.And aforesaid storage medium comprises: the various media that can store data and program code such as ROM (read-only memory) (ROM), random access memory (RAM), magnetic disc or CDs.
Corresponding to first aspect, in second aspect, the device that the application provides a kind of automatic mock outside to rely on.Fig. 2 is the block diagram of the device that a kind of automatic mock outside shown in the application one exemplary embodiment relies on.As shown in Figure 2, described device can comprise:
Tested end data acquisition module U201, for obtaining the title of tested code, and obtains call parameters and the call number of the dependence of tested code call outside.
Described tested end data acquisition module U201 can use the mode of interception or the mode of assignment to obtain the title of tested code, call parameters and call number.
Outer end data acquisition module U202, is connected with U201, for obtaining outside dependence the described rreturn value called or returning an object value.
When described tested end data acquisition module U201 uses the mode of interception, preferably, described outer end data acquisition module U202 correspondingly uses the mode of interception, and in possible embodiment, described outer end data acquisition module U202 also can use the mode of assignment.When described tested end data acquisition module U201 uses the mode of assignment, described outer end data acquisition module U202 can use the mode of interception or the mode of assignment.
Mock object generation module U203, be connected with U202, mock eigenwert is generated for the title according to described tested code, call parameters and call number, the rreturn value rely on described outside or returning an object value sequence turn to returned text, and by corresponding with described returned text for described mock eigenwert, described mock eigenwert and corresponding returned text form mock object.
Memory module U204, is connected with U203, for storing described mock object.
Wherein, described mock object generation module U203 can use hash algorithm to generate mock eigenwert.Described serializing can use conventional serializing technology.After the returned text generating mock eigenwert and obtain serializing, can using mock eigenwert as index, mock eigenwert and returned text as index value, thus are mapped by described returned text, and form mock object.Memory module U204 can be local memory module, also can be remote storage modules, and when memory module U204 is remote storage modules, mock object generation module U203 is connected by remote interface with memory module U204.The memory module storing mock object also can be called mock storehouse.
Wherein, described tested end data acquisition module U201, in a kind of possible embodiment, can comprise:
Tested end interception submodule, for calling of tackling that tested code relies on outside.
Tested end record sub module, for recording the title of described tested code, call parameters and call number.
Wherein, record call parameters and comprise the title, value and the type that record call parameters.Call number is called outside for which time and is relied on.Record after the title of tested code can be blocked when tested code first time is run, and keep in operation afterwards, call parameters and the call number record when each run is blocked.The title of tested code is used for the mock object of generation and tested code to be mapped.
Wherein, described outer end data acquisition module U202, in a kind of possible embodiment, can comprise:
Call submodule, for calling outside dependence according to described call parameters and call number;
Outer end record sub module, for recording rreturn value or the returning an object value of outside dependence.
Wherein, call submodule and replace tested code to call outside dependence, by using record when time call parameters and call number input to outside dependence as suction parameter, what realize relying on outside calling.Using record when time call parameters and after call number to input to outside dependence as suction parameter, outside dependence can return it according to suction parameter output rreturn value or returning an object value according to suction parameter.Described outer end record sub module receives and records the outside rreturn value or the returning an object value that rely on output, rreturn value or returning an object value can be transmitted back to tested code after record.
Wherein, described mock object generation module U203, in a kind of possible embodiment, can comprise:
Mock eigenwert generates submodule, generates mock eigenwert for the title according to tested code, call parameters and call number;
Serializing submodule, for turning to returned text by the rreturn value of described outside dependence or returning an object value sequence;
Build submodule, for described mock eigenwert is corresponding with the rreturn value that described outside relies on or returning an object value, the rreturn value that described mock eigenwert and corresponding described outside rely on or returning an object value form mock object.
Wherein, described serializing submodule can be conventional serializing module.
In the third aspect, the application provides a kind of mock method of testing, tests with the mock object utilizing the application to obtain in the method that the automatic mock outside that first aspect provides relies on.Fig. 3 is the schematic flow sheet of a kind of mock method of testing shown in the application one exemplary embodiment.As shown in Figure 3, described method can comprise:
In step S301, that tackles that tested code relies on outside calls.
When performing tested code in unit testing process, that tackles that tested code relies on outside calls.
In step s 302, the title of tested code, call parameters and call number is obtained.
Wherein, obtain call parameters and comprise the title, value and the type that obtain call parameters, described call number is called outside for which time and is relied on.
In step S303, generate according to the title of described tested code, call parameters and call number and call eigenwert;
Wherein, generate the method calling eigenwert identical with the generation method of mock eigenwert in mock object, such as, the hash algorithm identical with the mock eigenwert generated in mock object can be used to generate and call eigenwert, thus the mock eigenwert called in eigenwert and mock object that the title according to identical tested code, call parameters and call number are generated is equal.
In step s 304, in mock object, corresponding returned text is searched according to calling eigenwert.
Wherein, mock object is stored among memory module (or mock storehouse).After calling eigenwert described in obtaining, equal with corresponding mock eigenwert owing to calling eigenwert, thus can to call eigenwert for index, in memory module (mock storehouse), find corresponding mock object, and find in mock object and call returned text corresponding to eigenwert with described.When memory module is remote storage modules (or long-range mock storehouse), by memory module described in remote access (mock) storehouse, finds wherein and call returned text corresponding to eigenwert.
In step S305, returned text described in unserializing, obtains rreturn value or the returning an object value of outside dependence.
Described unserializing can use conventional unserializing method.
In step S306, described rreturn value or returning an object value are returned to tested code.
In step S307, verify described rreturn value or returning an object value.
Wherein, verify that described rreturn value or returning an object value can use conventional unit testing verification method.
By the description of above embodiment of the method, those skilled in the art can be well understood to the mode that the application can add required general hardware platform by software and realize, hardware can certainly be passed through, but in a lot of situation, the former is better embodiment.Based on such understanding, the technical scheme of the application can embody with the form of software product the part that prior art contributes in essence in other words, and be stored in a storage medium, comprise all or part of step of some instructions in order to make a smart machine perform method described in each embodiment of the application.And aforesaid storage medium comprises: the various media that can store data and program code such as ROM (read-only memory) (ROM), random access memory (RAM), magnetic disc or CDs.
Corresponding to the third aspect, in fourth aspect, the application provides a kind of mock proving installation.Fig. 4 is the block diagram of a kind of mock proving installation shown in the application one exemplary embodiment.As shown in Figure 4, described device can comprise:
Call blocking module U401, for calling of tackling that tested code relies on outside.
The described module called blocking module U401 and can call for conventional hook procedure.
Data acquisition module U402, is connected with U401, obtains the title of described tested code, call parameters and call number;
Wherein, obtain call parameters and comprise the title, value and the type that obtain call parameters, call number is called outside for which time and is relied on.
Call eigenwert generation module U403, be connected with U402, generate for the title according to described tested code, call parameters and call number and call eigenwert, and described in call the generation method of eigenwert identical with the generation method of mock eigenwert in mock object.
Search module U404, be connected with U403, for searching corresponding returned text according to calling eigenwert in mock object;
Wherein, after calling eigenwert described in obtaining, can in memory module (mock storehouse), to call eigenwert for index, find corresponding mock object, and find in mock object and call returned text corresponding to eigenwert with described.When memory module is remote storage modules (long-range mock storehouse), by memory module described in remote access (mock) storehouse, finds wherein and call returned text corresponding to eigenwert.
Unserializing module U405, is connected with U404, for returned text described in unserializing, obtains rreturn value or the returning an object value of outside dependence.
Return module U406, be connected with U405, for described rreturn value or returning an object value are returned to tested code.
Authentication module U407, is connected with U406, for verifying described rreturn value or returning an object value.
Described unserializing module U405 can be conventional unserializing module.
Described authentication module U407 can be conventional unit testing authentication module.
For convenience of description, various module is divided into describe respectively with function when describing above device.Certainly, the function of each module can be realized in same or multiple software and/or hardware when implementing the application.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, between each embodiment identical similar part mutually see, what each embodiment stressed is the difference with other embodiments.Especially, for device embodiment, because it is substantially similar to embodiment of the method, so describe fairly simple, relevant part illustrates see the part of embodiment of the method.Device embodiment described above is only schematic, the wherein said module illustrated as separating component can or may not be physically separates, parts as module display can be or may not be physical module, namely can be positioned at a place, or also can be distributed on multiple mixed-media network modules mixed-media.Some or all of module wherein can be selected according to the actual needs to realize the object of the present embodiment scheme.Those of ordinary skill in the art, when not paying creative work, are namely appreciated that and implement.
It should be noted that, in this article, the such as relational terms of " first " and " second " etc. and so on is only used for an entity or operation to separate with another entity or operational zone, and not necessarily requires or imply these entities or there is relation or the backward of any this reality between operating.And, term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability, thus make to comprise the process of a series of key element, method, device or equipment and not only comprise those key elements, but also comprise other key elements clearly do not listed, or also comprise by the intrinsic key element of this process, method, article or equipment.When not more restrictions, the key element limited by statement " comprising ... ", and be not precluded within process, method, device or the equipment comprising described key element and also there is other identical element.
The above is only the embodiment of the application, those skilled in the art is understood or realizes the application.To be apparent to one skilled in the art to the multiple amendment of these embodiments, General Principle as defined herein when not departing from the spirit or scope of the application, can realize in other embodiments.Therefore, the present invention can not be restricted to these embodiments shown in this article, but will meet the widest scope consistent with principle disclosed herein and features of novelty.
Claims (10)
1. a method for automatic mock outside dependence, is characterized in that, comprising:
Obtain the title of tested code, and obtain call parameters and the call number of described tested code call outside dependence;
Obtain described outside to rely on the described rreturn value or the returning an object value that call generation;
Mock eigenwert is generated according to the title of described tested code, call parameters and call number;
The rreturn value rely on described outside or returning an object value sequence turn to returned text;
By corresponding with described returned text for described mock eigenwert, described mock eigenwert and corresponding described returned text form mock object.
2. the method for mock outside dependence automatically as claimed in claim 1, is characterized in that, the title of the tested code of described acquisition, and obtains call parameters and the call number of the dependence of tested code call outside, comprising:
That tackles that described tested code relies on outside calls;
Record the title of tested code, call parameters and call number.
3. the method that relies on of the outside of mock automatically as claimed in claim 2, is characterized in that, describedly obtains outside dependence the described rreturn value called or returning an object value, comprising:
Outside dependence is called according to described call parameters and call number;
The rreturn value of the outside dependence of record or returning an object value.
4. the method that relies on of the outside of mock automatically as claimed in claim 1, is characterized in that, uses hash algorithm to generate mock eigenwert according to the title of tested code, call parameters and call number.
5. a device for automatic mock outside dependence, is characterized in that, comprising:
Tested end data acquisition module, for obtaining the title of tested code, and obtains call parameters and the call number of the dependence of tested code call outside;
Outer end data acquisition module, for obtaining outside dependence the described rreturn value or the returning an object value that call generation;
Mock object generation module, mock eigenwert is generated for the title according to tested code, call parameters and call number, the rreturn value rely on described outside or returning an object value sequence turn to returned text, and by corresponding with described returned text for described mock eigenwert, described mock eigenwert and corresponding returned text form mock object;
Memory module, for storing described mock object.
6. the device of the outside dependence of mock automatically as claimed in claim 5, it is characterized in that, described tested end data acquisition module, comprising:
Tested end interception submodule, for calling of tackling that tested code relies on outside;
Tested end record sub module, for recording the title of tested code, call parameters and call number.
7. the device of the outside dependence of mock automatically as claimed in claim 5, it is characterized in that, described outer end data acquisition module, comprising:
Call submodule, for calling outside dependence according to described call parameters and call number;
Outer end record sub module, for recording rreturn value or the returning an object value of outside dependence.
8. the device of the outside dependence of mock automatically as claimed in claim 5, it is characterized in that, described mock object generation module, comprising:
Mock eigenwert generates submodule, generates mock eigenwert for the title according to tested code, call parameters and call number;
Serializing submodule, for turning to returned text by the rreturn value of described outside dependence or returning an object value sequence;
Build submodule, for described mock eigenwert is corresponding with the rreturn value that described outside relies on or returning an object value, the rreturn value that described mock eigenwert and corresponding described outside rely on or returning an object value form mock object.
9. a mock method of testing, is characterized in that, comprising:
That tackles that tested code relies on outside calls;
Obtain the title of tested code, call parameters and call number;
Generate according to the title of described tested code, call parameters and call number and call eigenwert, and described in call the generation method of eigenwert identical with the generation method of mock eigenwert in mock object;
In mock object, corresponding returned text is searched according to described eigenwert of calling;
Returned text described in unserializing, obtains rreturn value or the returning an object value of outside dependence;
Described rreturn value or returning an object value are returned to tested code;
Verify described rreturn value or returning an object value.
10. a mock proving installation, is characterized in that, comprising:
Call blocking module, for calling of tackling that tested code relies on outside;
Data acquisition module, obtains the title of tested code, call parameters and call number;
Call eigenwert generation module, generate for the title according to described tested code, call parameters and call number and call eigenwert, and described in call the generation method of eigenwert identical with the generation method of mock eigenwert in mock object;
Searching module, in mock object, searching corresponding returned text for calling eigenwert described in basis;
Unserializing module, for returned text described in unserializing, obtains rreturn value or the returning an object value of outside dependence;
Return module, for described rreturn value or returning an object value are returned to tested code;
Authentication module, for verifying described rreturn value or returning an object value.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410370258.0A CN105335281B (en) | 2014-07-30 | 2014-07-30 | A kind of method and device relied on outside automatic mock |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410370258.0A CN105335281B (en) | 2014-07-30 | 2014-07-30 | A kind of method and device relied on outside automatic mock |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105335281A true CN105335281A (en) | 2016-02-17 |
CN105335281B CN105335281B (en) | 2018-03-20 |
Family
ID=55285835
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410370258.0A Expired - Fee Related CN105335281B (en) | 2014-07-30 | 2014-07-30 | A kind of method and device relied on outside automatic mock |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105335281B (en) |
Cited By (20)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106970873A (en) * | 2017-01-10 | 2017-07-21 | 阿里巴巴集团控股有限公司 | Mock method of testings, apparatus and system on line |
CN107402854A (en) * | 2016-05-19 | 2017-11-28 | 中兴通讯股份有限公司 | Test information management method, apparatus, test case execution system and equipment |
CN107659455A (en) * | 2017-10-16 | 2018-02-02 | 武汉斗鱼网络科技有限公司 | A kind of method, storage medium, equipment and the system of iOS ends Mock data |
CN107992425A (en) * | 2017-12-25 | 2018-05-04 | 携程旅游网络技术(上海)有限公司 | The automatic generation method and system of unit testing Mock codes |
CN108563575A (en) * | 2018-04-16 | 2018-09-21 | 百度在线网络技术(北京)有限公司 | Applied program testing method, device, terminal and computer readable storage medium |
CN109739526A (en) * | 2017-10-30 | 2019-05-10 | 北京京东尚科信息技术有限公司 | Code update method and device |
CN109901983A (en) * | 2017-12-07 | 2019-06-18 | 北京京东尚科信息技术有限公司 | Automated testing method and device, storage medium, electronic equipment |
CN110119354A (en) * | 2019-04-19 | 2019-08-13 | 平安普惠企业管理有限公司 | Method for testing software, device and electronic equipment based on Test cases technology |
CN110489334A (en) * | 2019-07-24 | 2019-11-22 | 贝壳技术有限公司 | A kind of system integration and test test processing method and device |
CN111221721A (en) * | 2018-11-27 | 2020-06-02 | 中国移动通信集团上海有限公司 | Automatic recording and executing method and device for unit test cases |
CN111752841A (en) * | 2020-06-28 | 2020-10-09 | 深圳前海微众银行股份有限公司 | Single test simulation method, device, equipment and computer readable storage medium |
CN112019558A (en) * | 2020-09-03 | 2020-12-01 | 深圳壹账通智能科技有限公司 | Universal baffle testing method, device, equipment and computer storage medium |
US10949334B2 (en) | 2018-11-26 | 2021-03-16 | Cognizant Technology Solutions India Pvt. Ltd. | System and a method for automated unit test generation |
CN112559344A (en) * | 2020-12-10 | 2021-03-26 | 平安养老保险股份有限公司 | Remote mock testing method and system |
CN112579440A (en) * | 2020-12-02 | 2021-03-30 | 深圳前海微众银行股份有限公司 | Method and device for determining virtual test dependent object |
CN112579467A (en) * | 2020-12-28 | 2021-03-30 | 北京百家科技集团有限公司 | Test method, test device, computer equipment and storage medium |
CN112732567A (en) * | 2020-12-31 | 2021-04-30 | 平安银行股份有限公司 | Mock data testing method and device based on ip, electronic equipment and storage medium |
CN113656290A (en) * | 2021-08-04 | 2021-11-16 | 支付宝(杭州)信息技术有限公司 | Mock point automatic identification method, device and equipment |
US11334471B1 (en) | 2020-12-02 | 2022-05-17 | UiPath Inc. | Mocking robotic process automation (RPA) activities for workflow testing |
US11989122B2 (en) | 2022-06-29 | 2024-05-21 | International Busi Corporation ess Machines | Handling mock objects that are written in the form of multiple assignment instructions |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080256517A1 (en) * | 2006-10-18 | 2008-10-16 | International Business Machines Corporation | Method and System for Automatically Generating Unit Test Cases Which Can Reproduce Runtime Problems |
CN102855178A (en) * | 2011-06-30 | 2013-01-02 | 阿里巴巴集团控股有限公司 | Method and device for generating Mock base during unit test |
CN102855177A (en) * | 2011-06-30 | 2013-01-02 | 阿里巴巴集团控股有限公司 | Unit test method and device |
CN102981947A (en) * | 2011-09-07 | 2013-03-20 | 阿里巴巴集团控股有限公司 | Data preparation method in test and system provided with the same |
CN103593172A (en) * | 2012-10-29 | 2014-02-19 | 百度在线网络技术(北京)有限公司 | System, method and device for developing unified structured data oriented applications |
CN103593173A (en) * | 2012-10-29 | 2014-02-19 | 百度在线网络技术(北京)有限公司 | Integration development system, integration development method and integration development device for application programs |
-
2014
- 2014-07-30 CN CN201410370258.0A patent/CN105335281B/en not_active Expired - Fee Related
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080256517A1 (en) * | 2006-10-18 | 2008-10-16 | International Business Machines Corporation | Method and System for Automatically Generating Unit Test Cases Which Can Reproduce Runtime Problems |
CN102855178A (en) * | 2011-06-30 | 2013-01-02 | 阿里巴巴集团控股有限公司 | Method and device for generating Mock base during unit test |
CN102855177A (en) * | 2011-06-30 | 2013-01-02 | 阿里巴巴集团控股有限公司 | Unit test method and device |
CN102981947A (en) * | 2011-09-07 | 2013-03-20 | 阿里巴巴集团控股有限公司 | Data preparation method in test and system provided with the same |
CN103593172A (en) * | 2012-10-29 | 2014-02-19 | 百度在线网络技术(北京)有限公司 | System, method and device for developing unified structured data oriented applications |
CN103593173A (en) * | 2012-10-29 | 2014-02-19 | 百度在线网络技术(北京)有限公司 | Integration development system, integration development method and integration development device for application programs |
Cited By (27)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107402854A (en) * | 2016-05-19 | 2017-11-28 | 中兴通讯股份有限公司 | Test information management method, apparatus, test case execution system and equipment |
CN106970873B (en) * | 2017-01-10 | 2021-07-09 | 创新先进技术有限公司 | On-line mock testing method, device and system |
CN106970873A (en) * | 2017-01-10 | 2017-07-21 | 阿里巴巴集团控股有限公司 | Mock method of testings, apparatus and system on line |
CN107659455A (en) * | 2017-10-16 | 2018-02-02 | 武汉斗鱼网络科技有限公司 | A kind of method, storage medium, equipment and the system of iOS ends Mock data |
CN107659455B (en) * | 2017-10-16 | 2020-01-03 | 武汉斗鱼网络科技有限公司 | Method, storage medium, device and system for Mock data of iOS (internet operating system) end |
CN109739526A (en) * | 2017-10-30 | 2019-05-10 | 北京京东尚科信息技术有限公司 | Code update method and device |
CN109901983A (en) * | 2017-12-07 | 2019-06-18 | 北京京东尚科信息技术有限公司 | Automated testing method and device, storage medium, electronic equipment |
CN107992425B (en) * | 2017-12-25 | 2020-09-22 | 携程旅游网络技术(上海)有限公司 | Automatic generation method and system for unit test Mock code |
CN107992425A (en) * | 2017-12-25 | 2018-05-04 | 携程旅游网络技术(上海)有限公司 | The automatic generation method and system of unit testing Mock codes |
CN108563575A (en) * | 2018-04-16 | 2018-09-21 | 百度在线网络技术(北京)有限公司 | Applied program testing method, device, terminal and computer readable storage medium |
US10949334B2 (en) | 2018-11-26 | 2021-03-16 | Cognizant Technology Solutions India Pvt. Ltd. | System and a method for automated unit test generation |
CN111221721A (en) * | 2018-11-27 | 2020-06-02 | 中国移动通信集团上海有限公司 | Automatic recording and executing method and device for unit test cases |
CN111221721B (en) * | 2018-11-27 | 2023-09-05 | 中国移动通信集团上海有限公司 | Automatic recording and executing method and device for unit test cases |
CN110119354A (en) * | 2019-04-19 | 2019-08-13 | 平安普惠企业管理有限公司 | Method for testing software, device and electronic equipment based on Test cases technology |
CN110489334A (en) * | 2019-07-24 | 2019-11-22 | 贝壳技术有限公司 | A kind of system integration and test test processing method and device |
CN111752841A (en) * | 2020-06-28 | 2020-10-09 | 深圳前海微众银行股份有限公司 | Single test simulation method, device, equipment and computer readable storage medium |
CN112019558A (en) * | 2020-09-03 | 2020-12-01 | 深圳壹账通智能科技有限公司 | Universal baffle testing method, device, equipment and computer storage medium |
CN112579440A (en) * | 2020-12-02 | 2021-03-30 | 深圳前海微众银行股份有限公司 | Method and device for determining virtual test dependent object |
US11334471B1 (en) | 2020-12-02 | 2022-05-17 | UiPath Inc. | Mocking robotic process automation (RPA) activities for workflow testing |
WO2022117038A1 (en) * | 2020-12-02 | 2022-06-09 | 深圳前海微众银行股份有限公司 | Method and apparatus for determining virtual test dependency object |
CN112579440B (en) * | 2020-12-02 | 2024-08-02 | 深圳前海微众银行股份有限公司 | Determination method and device for virtual test dependent object |
CN112559344A (en) * | 2020-12-10 | 2021-03-26 | 平安养老保险股份有限公司 | Remote mock testing method and system |
CN112579467A (en) * | 2020-12-28 | 2021-03-30 | 北京百家科技集团有限公司 | Test method, test device, computer equipment and storage medium |
CN112732567A (en) * | 2020-12-31 | 2021-04-30 | 平安银行股份有限公司 | Mock data testing method and device based on ip, electronic equipment and storage medium |
CN112732567B (en) * | 2020-12-31 | 2023-06-27 | 平安银行股份有限公司 | Mock data testing method and device based on ip, electronic equipment and storage medium |
CN113656290A (en) * | 2021-08-04 | 2021-11-16 | 支付宝(杭州)信息技术有限公司 | Mock point automatic identification method, device and equipment |
US11989122B2 (en) | 2022-06-29 | 2024-05-21 | International Busi Corporation ess Machines | Handling mock objects that are written in the form of multiple assignment instructions |
Also Published As
Publication number | Publication date |
---|---|
CN105335281B (en) | 2018-03-20 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105335281A (en) | Method and device for automatic mock of external dependency | |
CN107273286B (en) | Scene automatic test platform and method for task application | |
CN103838672B (en) | The automated testing method of a kind of all-purpose financial statements and device | |
CN102999320A (en) | Automatic test case generation method and system | |
CN103853652B (en) | A kind of test cases generation method and device | |
CN102855177B (en) | A kind of method and apparatus of unit testing | |
CN104657140A (en) | Code generating method and device | |
US7882121B2 (en) | Generating queries using cardinality constraints | |
CN107665171A (en) | Automatic regression test method and device | |
CN106293664A (en) | Code generating method and device | |
CN103092751B (en) | Web application performance test system based on customer behavior model in cloud environment | |
CN102118281B (en) | Method, device and network equipment for automatic testing | |
CN103309904A (en) | Method and device for generating data warehouse ETL (Extraction, Transformation and Loading) codes | |
CN109558525A (en) | A kind of generation method of test data set, device, equipment and storage medium | |
CN110022315A (en) | Weight management method, device and equipment in a kind of piece of chain type account book | |
CN105447030A (en) | Index processing method and equipment | |
CN106547870A (en) | Point table method and device of data base | |
CN110209584A (en) | A kind of automatic generation of test data and relevant apparatus | |
CN105630667A (en) | Test method and terminal equipment | |
CN106326776A (en) | Data object verification method, device and system based on rules, and electric device | |
Voigt et al. | Metamodel matching based on planar graph edit distance | |
CN114117977B (en) | Method suitable for automatically verifying processor system scene | |
CN116450107A (en) | Method and device for secondary development of software by low-code platform and electronic equipment | |
CN105786525A (en) | Method and device for transplanting code from process model to thread model | |
CN109165102B (en) | Constraint solver distributed scheduling method based on intelligent contracts |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20180320 |