Summary of the invention
Privately owned analogue data can not be configured in order at least solve API in the prior art, the data of simulation can not customize,
And the problem of mock data are not configured deeply.
In a first aspect, the embodiment of the present invention provides a kind of analogue data generation method for web front-end, comprising:
The digital simulation that server is initiated in response to web front-end is requested, inquire in the digital simulation request whether include
Mock field;
When including mock field in digital simulation request, determine that the digital simulation is asked according to the mock field
The request type asked, wherein the request type includes: local resource simulation, non-local resources simulation;
When the request type is that local resource is simulated, the mock configuration of web front-end is obtained;
Parse the mock configuration of the web front-end, wherein the mock configuration includes that default mock is configured, is non-default
Mock configuration;
When the mock is configured to non-default mock configuration, generated according to the non-default mock configuration privately owned configurable
Analogue data.
Second aspect, the embodiment of the present invention provide a kind of analogue data generation system for web front-end, comprising:
Field Inquiry program module, the digital simulation initiated for server in response to web front-end are requested, and the number is inquired
It whether include mock field according in simulation request;
Request type determines program module, is used for when including mock field in digital simulation request, according to described
Mock field determines the request type of the digital simulation request, wherein the request type includes: that local resource simulates, is non-
Local resource simulation;
Configuration obtains program module, for obtaining the mock of web front-end when the request type is that local resource is simulated
Configuration;
Command Line Parsing program module, the mock for parsing the web front-end are configured, wherein the mock, which is configured, includes
Default mock configuration, non-default mock configuration;
Privately owned configurable analogue data generates program module, for when the mock is configured to non-default mock configuration,
Privately owned configurable analogue data is generated according to the non-default mock configuration.
The third aspect provides a kind of electronic equipment comprising: at least one processor, and with described at least one
Manage the memory of device communication connection, wherein the memory is stored with the instruction that can be executed by least one described processor, institute
It states instruction to be executed by least one described processor, so that at least one described processor is able to carry out any embodiment of the present invention
The analogue data generation method for web front-end the step of.
Fourth aspect, the embodiment of the present invention provide a kind of storage medium, are stored thereon with computer program, and feature exists
In the analogue data generation method for web front-end of realization any embodiment of the present invention when the program is executed by processor
Step.
The beneficial effect of the embodiment of the present invention is: determining corresponding digital simulation by inquiry mock field, meets
Public digital simulation, private data simulation, the demand of privately owned configurable data simulation.It is directed to common data simulation, life
In to public remote interface digital simulation service on;It is directed to private data simulation, local data analog configuration file is arrived in hit
In;It is directed to privately owned configurable digital simulation, simulation is realized according to the interpolation expression in configuration file, meanwhile, also protect
The channel using truthful data is stayed.
Specific embodiment
In order to make the object, technical scheme and advantages of the embodiment of the invention clearer, below in conjunction with the embodiment of the present invention
In attached drawing, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is
A part of the embodiment of the present invention, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art
Every other embodiment obtained without creative efforts, shall fall within the protection scope of the present invention.
A kind of stream of the analogue data generation method for web front-end provided as shown in Figure 1 for one embodiment of the invention
Cheng Tu includes the following steps:
S11: the digital simulation that server is initiated in response to web front-end is requested, inquire in the digital simulation request whether
Include mock field;
S12: when including mock field in digital simulation request, the data mould is determined according to the mock field
Plan to invite the request type asked, wherein the request type includes: local resource simulation, non-local resources simulation;
S13: when the request type is that local resource is simulated, the mock configuration of web front-end is obtained;
S14: the mock configuration of the web front-end is parsed, wherein the mock configuration includes that default mock is configured, is non-silent
Recognize mock configuration;
S15: when the mock is configured to non-default mock configuration, according to the non-default mock configuration generate it is privately owned can
Configure analogue data.
In the present embodiment, mock is substitute of the truthful data during debugging.For it is certain be not easy construction or
Person is not easy the object obtained, creates the method so as to test with a virtual object.
Since real object has not confirmable behavior, uncertain effect is generated, (for example, stock market, weather
Forecast etc.) these real objects are difficult to be created, and certain behaviors of real object are difficult to be triggered.
In digital simulation, this object is described usually using an interface.This interface is realized in product code,
Carry out reference object simply by interface in test code, when quoting analogue data, program can not identify pair of this reference
Like real object or mock object, it is possible to freely adjust and which kind of object to carry out analogue data using.
It is all that mock is carried out to the returned data of interface in general scene.It is simplest by taking http agreement as an example
Mock can save portion mock data on mock server, and generate corresponding url to this mock data.It will access
Third party url, with mock url replacement.Most basic mock demand can be met in this way.
For step S11, developer issues digital simulation request to server in web front-end, and server is in response to opening
The digital simulation request that hair personnel initiate in web front-end, to inquire in the digital simulation request header file, if include mock
Field determines that object cited in developer is real object or mock object.
For step S12, when in the header file of digital simulation request including mock field, according to the mock word
Section determines the request type of digital simulation request.Wherein, request type includes local resource simulation and non-local money
Source simulation.
The mock configuration of web front-end is obtained when the type of the request is that local resource is simulated for step S13.Example
Such as, the mock configuration got is as follows:
For step S14, the mock configuration obtained according to step S13 is parsed, for example, passing through interpolation expression solution
Analysis.
Such as according in above-mentioned mock configuration:
For step S15, configures when the mock is configured to non-default mock, configured according to the non-default mock, it is non-
Default namely parses expression formula whether is added in this file, executes Mock generator, generates specific privately owned configurable
Analogue data, for example, on June 1st, 2018 at the beginning of activity, 2018 end times September 1st ....The life of other data
At details are not described herein.
It can be seen that the request type that the digital simulation request is determined by inquiring mock field by the embodiment
For local resource simulation when, by developer configuration file generated by interpolation expression corresponding developer exclusively enjoy it is privately owned
Configurable analogue data.To complete the simulation of privately owned configurable data.
As an implementation, in the present embodiment, after the mock configuration of the parsing web front-end, institute
State method further include:
When the mock is configured to default mock configuration, privately owned analogue data is generated according to default mock configuration.
In the present embodiment, it when the mock is configured to default mock configuration, is configured according to the mock of the default,
Generate corresponding privately owned analogue data, in implementation, such as mock:@mock/xxx/xxx.json is this without the judgement of protocol header
Ground mock, while being also local default mock configuration, (value of@mock/xxx/xxx.json here be directed toward be the machine mock
Configure resource address), to generate corresponding privately owned analogue data.
It can be seen that determine that the project of developer needs to exclusively enjoy by query expression privately owned by the embodiment
Analogue data when, but do not require specifically to configure, to generate the simulation of private data.
As an implementation, in the present embodiment, the digital simulation is determined according to the mock field described
After the request type of request, the method also includes:
When the request type is that non-local resources is simulated, digital simulation request is forwarded to public simulation program
Interface generates public analogue data.
In the present embodiment, when the request type is that non-local resources is simulated, illustrate developer, use is public
Analogue data.Digital simulation request is forwarded to public simulation program interface, generates public analogue data.For example,
It can be forwarded to common API platform: Apiary, YApi etc., generate public analogue data, specific implementation method such as mock:
Http:// xxx.xx/xxx is then judged as long-range public mock with the protocol headers such as http, simulates for non-local resources, if
It is long-range mock configuration, obtains this mock and configure corresponding value, directly initiate request, obtains returned data and be transmitted to client again
End.
It can be seen that by the embodiment by determining request type, inquiry developer is intended to what kind of
Analogue data, when it is only necessary to when simple public analogue data, the digital simulation is requested for the project of developer needs
It is forwarded in common API platform, to complete the simulation for being directed to common data.
As an implementation, in the present embodiment, in inquiry digital simulation request whether include
After mock field, the method also includes:
When not including mock field in digital simulation request, digital simulation request is forwarded to including true
The application programming interfaces of data obtain truthful data.
In the present embodiment, when not protecting mock field in digital simulation request, illustrate that the project of developer needs
True data are wanted, so the request of data to be forwarded to the application programming interfaces of truthful data, and then obtain true number
According to.
It can be seen that the channel by retaining truthful data by the embodiment, meet the various data of developer
Demand.
As an implementation, in the present embodiment, the digital simulation is determined according to the mock field described
After the request type of request, the method also includes:
When the request type is that non-local resources is simulated, is configured according to the mock of the server, generate privately owned mould
Quasi- data.
In the present embodiment, when request type be non-local resources simulate when, illustrate developer only hope using
Privately owned data are exclusively enjoyed to be tested, and are specifically which type of data, not special requirement, thus, directly pass through clothes
The mock configuration of business device, generates privately owned analogue data.
It can be seen that the request type that the digital simulation request is determined by inquiring mock field by the embodiment
It is specific without requiring when showing that the project of developer needs to exclusively enjoy privately owned analogue data when being simulated for non-local resources
Configuration configures according to the mock of server, privately owned analogue data is generated, to complete the simulation of private data.
As an implementation, in the present embodiment, the mock configuration of server generates private after described according to modification
After having configurable analogue data, the method also includes: store the mock field.
The storage mock field includes:
The initiation address of the digital simulation request of the mock field is stored in the interface statement of the server.
In the present embodiment, " mock " is added in the interface statement of the server, needed in the statement of interface
Match mock field.Such as:
It can be seen that by the implementation method by the way that mock field and interface statement configuration to be consistent, convenient for exploitation
Lookup and maintenance of the personnel in the later period.
As an implementation, the storage mock field further include:
Inquiry whether there is mock.json file;
When there are the mock.json file, the initiation address that the digital simulation of the mock field is requested is stored
To in the mock.json file;
When the mock.json file is not present, mock.json file is created, by the data mould of the mock field
The initiation address asked is planned to invite to store into the mock.json file.
In the present embodiment, inquiry whether there is mock.json file.Wherein, json (JavaScript Object
Notation, JS object numbered musical notation) be a kind of lightweight data interchange format, using the text lattice for being totally independent of programming language
Formula stores and indicates data.Succinctly and clearly hierarchical structure is easy to people and reads and write, at the same be also easy to machine parsing and
It generates, effectively promotes network transmission efficiency.For simple, storing data is acted on.When there are the mock file,
The initiation address that the digital simulation of the mock field is requested is stored into the mock.json file.When there is no described
When mock.json file, mock.json file is just created in the server, then again by the data of the mock field
The initiation address of simulation request is stored into the mock.json.Such as: mock.json
It can be seen that by the implementation method by arriving the initiation address storage of the digital simulation request of each mock field
In mock.json, redundant data will not be generated, promotes the stability of server.
A kind of analogue data for web front-end for being illustrated in figure 2 one embodiment of the invention offer generates the knot of system
Structure schematic diagram, which can be performed the analogue data generation method that web front-end is used for described in above-mentioned any embodiment, and configure
In the terminal.
It includes: Field Inquiry program module that a kind of analogue data for web front-end provided in this embodiment, which generates system,
11, request type determines program module 12, and configuration obtains program module 13, Command Line Parsing program module 14 and privately owned configurable mould
Quasi- data generator module 15.
Wherein, the digital simulation that Field Inquiry program module 11 is initiated for server in response to web front-end is requested, inquiry
It whether include mock field in the digital simulation request;Request type determines program module 12 for asking when the digital simulation
When in asking including mock field, the request type of the digital simulation request is determined according to the mock field, wherein described to ask
Seeking type includes: local resource simulation, non-local resources simulation;Configuration obtains program module 13 for when the request type is
When local resource is simulated, the mock configuration of web front-end is obtained;Command Line Parsing program module 14 is for parsing the web front-end
Mock configuration, wherein the mock configuration includes default mock configuration, non-default mock configuration;Privately owned configurable analogue data
It generates program module 15 to be used for when the mock is configured to non-default mock configuration, be generated according to the non-default mock configuration
Privately owned configurable analogue data.
Further, the system also includes: privately owned analogue data generates program module,
For generating privately owned simulation number according to default mock configuration when the mock is configured to default mock configuration
According to.
Further, the system also includes: public analogue data generates program module,
For when the request type is that non-local resources is simulated, digital simulation request to be forwarded to public simulation
Routine interface generates public analogue data.
Further, the method also includes: truthful datas to obtain program module,
For when the digital simulation request in do not include mock field when, by the digital simulation request be forwarded to including
The application programming interfaces of truthful data obtain truthful data.
Further, after the privately owned configurable analogue data generates program module, the system also includes: field
Program module is stored, for storing the mock field.
The embodiment of the invention also provides a kind of nonvolatile computer storage media, computer storage medium is stored with meter
The mould for web front-end in above-mentioned any means embodiment can be performed in calculation machine executable instruction, the computer executable instructions
Quasi- data creation method;
As an implementation, nonvolatile computer storage media of the invention is stored with the executable finger of computer
It enables, computer executable instructions setting are as follows:
The digital simulation that server is initiated in response to web front-end is requested, inquire in the digital simulation request whether include
Mock field;
When including mock field in digital simulation request, determine that the digital simulation is asked according to the mock field
The request type asked, wherein the request type includes: local resource simulation, non-local resources simulation;
When the request type is that local resource is simulated, the mock configuration of web front-end is obtained;
Parse the mock configuration of the web front-end, wherein the mock configuration includes that default mock is configured, is non-default
Mock configuration;
When the mock is configured to non-default mock configuration, generated according to the non-default mock configuration privately owned configurable
Analogue data.
As a kind of non-volatile computer readable storage medium storing program for executing, it can be used for storing non-volatile software program, non-volatile
Property computer executable program and module, such as the corresponding program instruction/mould of the method for the test software in the embodiment of the present invention
Block.One or more program instruction is stored in non-volatile computer readable storage medium storing program for executing, when being executed by a processor, is held
The analogue data generation method for web front-end in the above-mentioned any means embodiment of row.
Non-volatile computer readable storage medium storing program for executing may include storing program area and storage data area, wherein storage journey
It sequence area can application program required for storage program area, at least one function;Storage data area can be stored according to test software
Device use created data etc..In addition, non-volatile computer readable storage medium storing program for executing may include that high speed is deposited at random
Access to memory, can also include nonvolatile memory, a for example, at least disk memory, flush memory device or other are non-
Volatile solid-state part.In some embodiments, it includes relative to place that non-volatile computer readable storage medium storing program for executing is optional
The remotely located memory of device is managed, these remote memories can be by being connected to the network to the device of test software.Above-mentioned network
Example include but is not limited to internet, intranet, local area network, mobile radio communication and combinations thereof.
The embodiment of the present invention also provides a kind of electronic equipment comprising: at least one processor, and with described at least one
The memory of a processor communication connection, wherein the memory is stored with the finger that can be executed by least one described processor
Enable, described instruction executed by least one described processor so that at least one described processor be able to carry out it is of the invention any
The step of analogue data generation method for web front-end of embodiment.
The client of the embodiment of the present application exists in a variety of forms, including but not limited to:
(1) mobile communication equipment: the characteristics of this kind of equipment is that have mobile communication function, and to provide speech, data
Communication is main target.This Terminal Type includes: smart phone (such as iPhone), multimedia handset, functional mobile phone and low
Hold mobile phone etc..
(2) super mobile personal computer equipment: this kind of equipment belongs to the scope of personal computer, there is calculating and processing function
Can, generally also have mobile Internet access characteristic.This Terminal Type includes: PDA, MID and UMPC equipment etc., such as iPad.
(3) portable entertainment device: this kind of equipment can show and play multimedia content.Such equipment include: audio,
Video player (such as iPod), handheld device, e-book and intelligent toy and portable car-mounted navigation equipment.
(4) other electronic devices having data processing function.
Herein, relational terms such as first and second and the like be used merely to by an entity or operation with it is another
One entity or operation distinguish, and without necessarily requiring or implying between these entities or operation, there are any this reality
Relationship or sequence.Moreover, the terms "include", "comprise", include not only those elements, but also including being not explicitly listed
Other element, or further include for elements inherent to such a process, method, article, or device.Do not limiting more
In the case where system, the element that is limited by sentence " including ... ", it is not excluded that including process, method, the article of the element
Or there is also other identical elements in equipment.
The apparatus embodiments described above are merely exemplary, wherein described, unit can as illustrated by the separation member
It is physically separated with being or may not be, component shown as a unit may or may not be physics list
Member, it can it is in one place, or may be distributed over multiple network units.It can be selected according to the actual needs
In some or all of the modules achieve the purpose of the solution of this embodiment.Those of ordinary skill in the art are not paying creativeness
Labour in the case where, it can understand and implement.
Through the above description of the embodiments, those skilled in the art can be understood that each embodiment can
It realizes by means of software and necessary general hardware platform, naturally it is also possible to pass through hardware.Based on this understanding, on
Stating technical solution, substantially the part that contributes to existing technology can be embodied in the form of software products in other words, should
Computer software product may be stored in a computer readable storage medium, such as ROM/RAM, magnetic disk, CD, including several fingers
It enables and using so that a computer equipment (can be personal computer, server or the network equipment etc.) executes each implementation
Method described in certain parts of example or embodiment.
Finally, it should be noted that the above embodiments are merely illustrative of the technical solutions of the present invention, rather than its limitations;Although
Present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that: it still may be used
To modify the technical solutions described in the foregoing embodiments or equivalent replacement of some of the technical features;
And these are modified or replaceed, technical solution of various embodiments of the present invention that it does not separate the essence of the corresponding technical solution spirit and
Range.