Invention content
In view of this, the embodiment of the present invention provides a kind of method and apparatus of automatic Data Generation Test, number can be solvedAccording to the problem that element splicing difficulty is big, splicing error rate is high.
To achieve the above object, one side according to the ... of the embodiment of the present invention provides a kind of automatic Data Generation TestMethod, including:
Read test template with test data, the test data includes parameter name and parameter in the test templateValue;
Target data is obtained, the target data is converted to by desired value by format conversion;
The position that parameter value to be replaced is searched in the test template is replaced described to be replaced with the desired valueParameter value, to automatically generate target detection data.
Optionally, target data is obtained, the target data is converted to by desired value by format conversion, including:
The target data for obtaining picture format, is converted to the target data of the picture format by format conversionBASE64 values or binary value.
Optionally, the position that parameter value to be replaced is searched in the test template, described in desired value replacementParameter value to be replaced, including:
Read parameter name input by user;
Parameter name input by user is matched in the test template using regular expression, is found and the parameter nameThe position of corresponding parameter value to be replaced;
The parameter value in the position range is obtained, the parameter value in the position range is replaced with the desired value.
Optionally, the parameter value in the position range is replaced with the desired value, including:
The character string replacement method provided by JAVA, automatically replaces with the mesh by the character string in the position rangeThe character string of scale value.
Optionally, the test template is the text file that test data is written with JSON formats;
After automatically generating target detection data, the method further includes:By replaced JSON formats test dataIt is illustrated in web page text frame.
In addition, other side according to the ... of the embodiment of the present invention, provides a kind of device of automatic Data Generation Test, packetIt includes:
Read module is used for read test template, includes with test data, the test data in the test templateParameter name and parameter value;
The target data is converted to desired value by conversion module for obtaining target data by format conversion;
Replacement module, the position for searching parameter value to be replaced in the test template are replaced with the desired valueThe parameter value to be replaced is changed, to automatically generate target detection data.
Optionally, the conversion module is used for:
The target data for obtaining picture format, is converted to the target data of the picture format by format conversionBASE64 values or binary value.
Optionally, the replacement module is used for:
Read parameter name input by user;
Parameter name input by user is matched in the test template using regular expression, is found and the parameter nameThe position of corresponding parameter value to be replaced;
The parameter value in the position range is obtained, the parameter value in the position range is replaced with the desired value.
Optionally, the parameter value in the position range is replaced with the desired value, including:
The character string replacement method provided by JAVA, automatically replaces with the mesh by the character string in the position rangeThe character string of scale value.
Optionally, the test template is the text file that test data is written with JSON formats;
The replacement module is additionally operable to:After automatically generating target detection data, replaced JSON formats are testedData are illustrated in web page text frame.
Other side according to the ... of the embodiment of the present invention additionally provides a kind of electronic equipment, including:
One or more processors;
Storage device, for storing one or more programs,
When one or more of programs are executed by one or more of processors so that one or more of processingDevice realizes the method described in any of the above-described embodiment.
Other side according to the ... of the embodiment of the present invention additionally provides a kind of computer-readable medium, is stored thereon with meterCalculation machine program, realizes the method described in any of the above-described embodiment when described program is executed by processor.
One embodiment in foregoing invention has the following advantages that or advantageous effect:Because using using in test templateThe position for searching parameter value to be replaced replaces parameter value to be replaced with desired value, to the skill of automatic Data Generation TestArt means, so overcoming the technical problem that data element splicing difficulty is big, splicing error rate is high;The present invention is by target dataIt is automatically converted to desired value, is matched in test template using regular expression and replaces position, and target is replaced in correct positionValue is conducive to improve interface testing working efficiency, letter to avoid artificial repeatability splicing from replacing complicated interminable data formatChange workflow.
Further effect possessed by above-mentioned non-usual optional mode adds hereinafter in conjunction with specific implementation modeWith explanation.
Specific implementation mode
It explains to the exemplary embodiment of the present invention below in conjunction with attached drawing, including the various of the embodiment of the present inventionDetails should think them only exemplary to help understanding.Therefore, those of ordinary skill in the art should recognizeIt arrives, various changes and modifications can be made to the embodiments described herein, without departing from scope and spirit of the present invention.TogetherThe description to known function and structure is omitted for clarity and conciseness in sample in following description.
Fig. 1 is the schematic diagram of the main flow of the method for automatic Data Generation Test according to the ... of the embodiment of the present invention.Such as Fig. 1Shown, as an embodiment of the present invention, the method for the automatic Data Generation Test may include:
Step 101, read test template with test data, the test data includes parameter in the test templateName and parameter value.
Since the data of each interface transmission are different, to realize that function versatility, the embodiment of the present invention take reading mouldThe form of plate, to ensure that method provided in an embodiment of the present invention can be used to realize automatic Data Generation Test.
Currently, the format of test data can be generally divided into:JSON formats, XML format, binary format etc., due toJSON is a kind of data interchange format of lightweight, is easy to read and write, while being also easy to machine parsing and generating, and transmits numberThe complicated data element of JSON formats splicing is mostly used according to extremely complex interface, therefore the embodiment of the present invention is with JSON formatsIt is described in detail for test data.
Before step 101, the method can also include:Test data is written in text file with JSON formats(such as TXT files etc.) is selected in this, as test template for user.Enter to join different, need due to each interfaceIt to be directed to different interfaces, different test datas is write, to produce different test templates.
For example, the content in test template can be as follows:
{
"appName":"LEE_LOCAL_TEST",
"appAuthorityKey":" UqhrKxsCykLN/29npDP1kQ==",
"verifyBusinessType":"MESHED_PHOTO_VERIFY",
"businessId":"JRAPP-BT_AUTH",
"faceSDK":"jdin",
"faceSDKVersion":"1.0",
"ip":"49.118.242.36",
"shieldInfo":null,
"pin":"",
"name":" Yang Lili ",
"idCard":"370123199203160528",
"faceData":null,
"extra":null
}
It should be pointed out that the test data in above-mentioned test template is merely exemplary ground, test data is according to eachThe ginseng that enters of interface based on JSON transmission datas determines, interface enters ginseng and (including enters to join and name and enter ginseng value, i.e. parameter name and parameterValue) it is converted to after JSON formats in write-in .txt files, it is used as test template, guarantee to be mostly based on JSON and pass .txt filesThe interface of transmission of data enters ginseng and method provided in an embodiment of the present invention can be used to realize automatic Data Generation Test.
Test template can store local, and user selects local test template to carry out by click " uploading Template button "It uploads.
Step 102, target data is obtained, the target data is converted to by desired value by format conversion.
In this step, the type for the format conversion that can be inputted or select according to user, automatically by target dataBe converted to required desired value.
In some embodiments of the invention, for the target data of picture format, BASE64 lattice can be converted intoFormula, binary format etc..Specifically, step 102 may include:The target data for obtaining picture format, will by format conversionThe target data of the picture format is converted to BASE64 values or binary value.If user's selection is BASE64 formats,Target data is then converted into BASE64 values.If user selection be binary format, by target data be converted to two intoValue processed.
Step 103, the position that parameter value to be replaced is searched in the test template, described in desired value replacementParameter value to be replaced, to automatically generate target detection data.
In this step, it needs first to read parameter name input by user, then be searched in the test template to be replacedParameter value position, the parameter value to be replaced in test template is replaced with into the desired value obtained in step 102.Therefore,The embodiment of the present invention can be with Dynamic Recognition parameter name input by user, to replace corresponding parameter value, to complete data elementSplicing.
As an alternative embodiment of the invention, step 103 can specifically include:First, parameter input by user is readName;Then, parameter name input by user is matched in the test template using regular expression, found and the parameter nameThe position of corresponding parameter value to be replaced;Finally, the parameter value in the position range is obtained, which is replaced with the desired valueSet the parameter value in range.
By taking the test template in step 102 as an example:
First, parameter name input by user is read;User can input the parameter name to be replaced in web page text frame, thanSuch as, the entitled image of the parameter of the target data of picture format, entitled faceData of parameter of the target data of pictures etc.;
Then, parameter name input by user is matched in the test template using regular expression, such as image,FaceData etc., to find the position of parameter value to be replaced corresponding with the parameter name in the test template;
Finally, the character string (as needing the character string replaced) in the position range is obtained, in the position rangeCharacter string replaces with the character string of the desired value obtained in step 102, such as BASE64 values or binary value etc..
For example, tester needs to replace the BASE64 values of picture, then matched in test template by regular expressionBASE64 values after to image parameters name, replaced test data are as follows:
As it can be seen that the embodiment of the present invention be directed to the interface based on JSON transmission datas, automatic conversion complex data format (such asPicture format), a key generates complete JSON strings, and it includes BASE64 picture formats that the transmission of the interfaces such as manual identified, which may be implemented,When JSON test datas, automatic conversion, splicing picture format, and generate the functions such as JSON test datas.
Optionally, the parameter value in the position range is replaced with the desired value, including:The character string provided by JAVACharacter string in the position range is automatically replaced with the character string of the desired value by replacement method.
Optionally, after step 103, the method further includes:Replaced JSON formats test data is illustrated inIn web page text frame, in order to which tester replicates.
According to various embodiments recited above, it can be seen that the present invention uses and searches ginseng to be replaced in test templateThe position of numerical value replaces parameter value to be replaced with desired value, to the technical solution of automatic Data Generation Test, solves numberAccording to the problem that element splicing difficulty is big, splicing error rate is high.That is, in the prior art, generally requiring tester peopleFor the data element for searching complicated, and manual switch format, splicing, replacement etc. are carried out to it, leads to that working efficiency is low, dataProblem of poor quality, error rate is high.And the present invention is that target data is automatically converted to desired value, is being surveyed using regular expressionPosition is replaced in matching in die trial plate, and replaces desired value in correct position, complicated superfluous to avoid artificial repeatability splicing from replacingLong data format is conducive to improve interface testing working efficiency, simplifies workflow.
Fig. 2 is showing according to the main flow of the method for an automatic Data Generation Test that can refer to embodiment of the inventionIt is intended to, the method for the automatic Data Generation Test may include:
Step 201, the test template that user uploads is read;
Step 202, the target data of user's selection, such as picture are obtained;
Step 203, the type of the format conversion selected by user, desired value is converted to by target data;
Step 204, the parameter name that user inputs in web page text frame is read;
Step 205, when automatically generating button when the user clicks, it is defeated that user is matched in test template using regular expressionThe parameter name entered finds the position of parameter value to be replaced corresponding with parameter name;
Step 206, the parameter value in the position range is obtained, the parameter value in the position range is replaced with desired value;
Step 207, the automatic Data Generation Test in web page text frame.
If be pointed out that target data (such as:Abc format conversion) need not be carried out, then need not execute stepRapid 203, but step 204 is directly executed, with the parameter value in target data replacement test template, the test data of generation is such asUnder:
{
"appName":"LEE_LOCAL_TEST",
"appAuthorityKey":" UqhrKxsCykLN/29npDP1kQ==",
"verifyBusinessType":"MESHED_PHOTO_VERIFY",
"businessId":"JRAPP-BT_AUTH",
"faceSDK":"jdin",
"faceSDKVersion":"1.0",
"ip":"49.118.242.36",
"shieldInfo":null,
"pin":"",
"name":" Yang Lili ",
"idCard":"370123199203160528",
"faceData":"abc",
"extra":null
}
If target data is changing value, random digit generation method or data rule changing method may be selected;If meshMark data are increment value, then selecting data increases method certainly;If target data is data common-used formula calculated value, may be selectedCommon-used formula computational methods etc..These target datas need not convert format, can directly read target data, and complete to spellIt connects.
By from for increasing ID, the content of test template is as follows:
{
"ID":"000000001",
"appName":"LEE_LOCAL_TEST",
"appAuthorityKey":" UqhrKxsCykLN/29npDP1kQ==",
"verifyBusinessType":"MESHED_PHOTO_VERIFY",
"businessId":"JRAPP-BT_AUTH",
"faceSDK":"jdin",
"faceSDKVersion":"1.0",
"ip":"49.118.242.36",
"shieldInfo":null,
"pin":"",
"name":" Yang Lili ",
"idCard":"370123199203160528",
"faceData":null,
"extra":null
}
Automatically increase ID certainly and spliced test data is as follows:
{
"ID":"000000002",
"appName":"LEE_LOCAL_TEST",
"appAuthorityKey":" UqhrKxsCykLN/29npDP1kQ==",
"verifyBusinessType":"MESHED_PHOTO_VERIFY",
"businessId":"JRAPP-BT_AUTH",
"faceSDK":"jdin",
"faceSDKVersion":"1.0",
"ip":"49.118.242.36",
"shieldInfo":null,
"pin":"",
"name":" Yang Lili ",
"idCard":"370123199203160528",
"faceData":null,
"extra":null
}
{
"ID":"000000003",
"appName":"LEE_LOCAL_TEST",
"appAuthorityKey":" UqhrKxsCykLN/29npDP1kQ==",
"verifyBusinessType":"MESHED_PHOTO_VERIFY",
"businessId":"JRAPP-BT_AUTH",
"faceSDK":"jdin",
"faceSDKVersion":"1.0",
"ip":"49.118.242.36",
"shieldInfo":null,
"pin":"",
"name":" Yang Lili ",
"idCard":"370123199203160528",
"faceData":null,
"extra":null
}
In addition, in the specific implementation content of a method that can refer to automatic Data Generation Test in embodiment of the invention,It has been described in detail in the method for automatic Data Generation Test described above, therefore has no longer illustrated in this duplicate contents.
Fig. 3 is the schematic diagram of the main modular of the device of automatic Data Generation Test according to the ... of the embodiment of the present invention.Such as Fig. 3Shown, the device 300 of the automatic Data Generation Test includes read module 301, conversion module 302 and replacement module.Wherein,301 read test template of the read module with test data, the test data includes parameter name in the test templateAnd parameter value;The conversion module 302 obtains target data, and the target data is converted to desired value by format conversion;The replacement module 303 searches the position of parameter value to be replaced in the test template, described in desired value replacementParameter value to be replaced, to automatically generate target detection data.
Optionally, the conversion module 302 obtains the target data of picture format, by format conversion by the picture latticeThe target data of formula is converted to BASE64 values or binary value.
Optionally, the replacement module 303 reads parameter name input by user;Using regular expression in the test mouldParameter name input by user is matched in plate, finds the position of parameter value to be replaced corresponding with the parameter name;Obtaining shouldParameter value in position range replaces the parameter value in the position range with the desired value.
Optionally, the parameter value in the position range is replaced with the desired value, including:
The character string replacement method provided by JAVA, automatically replaces with the mesh by the character string in the position rangeThe character string of scale value.
Optionally, the test template is the text file that test data is written with JSON formats;
After automatically generating target detection data, replaced JSON formats are also tested number by the replacement module 303According to being illustrated in web page text frame.
According to various embodiments recited above, it can be seen that the present invention uses and searches ginseng to be replaced in test templateThe position of numerical value replaces parameter value to be replaced with desired value, to the technical solution of automatic Data Generation Test, solves numberAccording to the problem that element splicing difficulty is big, splicing error rate is high.That is, in the prior art, generally requiring tester peopleFor the data element for searching complicated, and manual switch format, splicing, replacement etc. are carried out to it, leads to that working efficiency is low, dataProblem of poor quality, error rate is high.And the present invention is that target data is automatically converted to desired value, is being surveyed using regular expressionPosition is replaced in matching in die trial plate, and replaces desired value in correct position, complicated superfluous to avoid artificial repeatability splicing from replacingLong data format is conducive to improve interface testing working efficiency, simplifies workflow.
It should be noted that the specific implementation content of the device in automatic Data Generation Test of the present invention, aboveIt has been described in detail in the method for the automatic Data Generation Test, therefore has no longer illustrated in this duplicate contents.
Fig. 4 shows the method for the automatic Data Generation Test that can apply the embodiment of the present invention or automatically generates test numberAccording to method exemplary system architecture 400.
As shown in figure 4, system architecture 400 may include terminal device 401,402,403, network 404 and server 405.Network 404 between terminal device 401,402,403 and server 405 provide communication link medium.Network 404 can be withIncluding various connection types, such as wired, wireless communication link or fiber optic cables etc..
User can be interacted by network 404 with server 405 with using terminal equipment 401,402,403, to receive or send outSend message etc..Various telecommunication customer end applications, such as the application of shopping class, net can be installed on terminal device 401,402,403(merely illustrative) such as the application of page browsing device, searching class application, instant messaging tools, mailbox client, social platform softwares.
Terminal device 401,402,403 can be the various electronic equipments with display screen and supported web page browsing, packetInclude but be not limited to smart mobile phone, tablet computer, pocket computer on knee and desktop computer etc..
Server 405 can be to provide the server of various services, such as utilize terminal device 401,402,403 to userThe shopping class website browsed provides the back-stage management server (merely illustrative) supported.Back-stage management server can be to receivingTo the data such as information query request analyze etc. processing, and (such as target push information, product are believed by handling resultBreath --- merely illustrative) feed back to terminal device.
It should be noted that the method for the automatic Data Generation Test that the embodiment of the present invention is provided is generally in server405 execute, and correspondingly, the device of the automatic Data Generation Test is generally located in server 405.Institute of the embodiment of the present inventionThe method of the automatic Data Generation Test of offer can also be executed in terminal device 401,402,403, correspondingly, the automatic lifeIt is generally located on terminal device 401,402,403 at the device of test data.
It should be understood that the number of the terminal device, network and server in Fig. 4 is only schematical.According to realization needIt wants, can have any number of terminal device, network and server.
Below with reference to Fig. 5, it illustrates the computer systems 500 suitable for the terminal device for realizing the embodiment of the present inventionStructural schematic diagram.Terminal device shown in Fig. 5 is only an example, to the function of the embodiment of the present invention and should not use modelShroud carrys out any restrictions.
As shown in figure 5, computer system 500 includes central processing unit (CPU) 501, it can be read-only according to being stored inProgram in memory (ROM) 502 or be loaded into the program in random access storage device (RAM) 503 from storage section 508 andExecute various actions appropriate and processing.In RAM 503, also it is stored with system 500 and operates required various programs and data.CPU 501, ROM 502 and RAM 503 are connected with each other by bus 504.Input/output (I/O) interface 505 is also connected to alwaysLine 504.
It is connected to I/O interfaces 505 with lower component:Importation 506 including keyboard, mouse etc.;It is penetrated including such as cathodeThe output par, c 507 of spool (CRT), liquid crystal display (LCD) etc. and loud speaker etc.;Storage section 508 including hard disk etc.;And the communications portion 509 of the network interface card including LAN card, modem etc..Communications portion 509 via such as becauseThe network of spy's net executes communication process.Driver 510 is also according to needing to be connected to I/O interfaces 505.Detachable media 511, such asDisk, CD, magneto-optic disk, semiconductor memory etc. are mounted on driver 510, as needed in order to be read from thereonComputer program be mounted into storage section 508 as needed.
Particularly, it according to embodiment disclosed by the invention, may be implemented as counting above with reference to the process of flow chart descriptionCalculation machine software program.For example, embodiment disclosed by the invention includes a kind of computer program product comprising be carried on computerComputer program on readable medium, the computer program include the program code for method shown in execution flow chart.?In such embodiment, which can be downloaded and installed by communications portion 509 from network, and/or from canMedium 511 is dismantled to be mounted.When the computer program is executed by central processing unit (CPU) 501, system of the invention is executedThe above-mentioned function of middle restriction.
It should be noted that computer-readable medium shown in the present invention can be computer-readable signal media or meterCalculation machine readable storage medium storing program for executing either the two arbitrarily combines.Computer readable storage medium for example can be --- but notBe limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor system, device or device, or arbitrary above combination.MeterThe more specific example of calculation machine readable storage medium storing program for executing can include but is not limited to:Electrical connection with one or more conducting wires, justIt takes formula computer disk, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type and may be programmed read-only storageDevice (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 the present invention, can be any include computer readable storage medium or storage journeyThe tangible medium of sequence, the program can be commanded the either device use or in connection of execution system, device.And at thisIn invention, computer-readable signal media may include in a base band or as the data-signal that a carrier wave part is propagated,Wherein carry computer-readable program code.Diversified forms may be used in the data-signal of this propagation, including but unlimitedIn electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be that computer canAny computer-readable medium other than storage medium is read, which can send, propagates or transmit and be used forBy instruction execution system, device either device use or program in connection.Include on computer-readable mediumProgram code can transmit with any suitable medium, including but not limited to:Wirelessly, electric wire, optical cable, RF etc. or above-mentionedAny appropriate combination.
Flow chart in attached drawing and block diagram, it is illustrated that according to the system of various embodiments of the invention, method and computer journeyThe architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generationA part for a part for one module, program segment, or code of table, above-mentioned module, program segment, or code includes one or moreExecutable instruction for implementing the specified logical function.It should also be noted that in some implementations as replacements, institute in boxThe function of mark can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are practicalOn can be basically executed in parallel, they can also be executed in the opposite order sometimes, this is depended on the functions involved.Also it wantsIt 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 ruleThe dedicated hardware based systems of fixed functions or operations is realized, or can use the group of specialized hardware and computer instructionIt closes to realize.
Being described in module involved in the embodiment of the present invention can be realized by way of software, can also be by hardThe mode of part is realized.Described module can also be arranged in the processor, for example, can be described as:A kind of processor packetInclude read module, conversion module and replacement module, wherein the title of these modules is not constituted under certain conditions to the moduleThe restriction of itself.
As on the other hand, the present invention also provides a kind of computer-readable medium, which can beIncluded in equipment described in above-described embodiment;Can also be individualism, and without be incorporated the equipment in.Above-mentioned calculatingMachine readable medium carries one or more program, when said one or multiple programs are executed by the equipment, makesObtaining the equipment includes:Read test template, with test data in the test template, the test data include parameter name andParameter value;Target data is obtained, the target data is converted to by desired value by format conversion;It is looked into the test templateThe parameter value to be replaced is replaced in the position for looking for parameter value to be replaced with the desired value, is surveyed to automatically generate targetTry data.
Technical solution according to the ... of the embodiment of the present invention, because searching parameter value to be replaced in test template using usingPosition, parameter value to be replaced is replaced with desired value, to automatic Data Generation Test technological means, so overcoming numberAccording to the technical problem that element splicing difficulty is big, splicing error rate is high;The present invention is that target data is automatically converted to desired value, is adoptedIt is matched in test template with regular expression and replaces position, and desired value is replaced in correct position, to avoid manually repeatingProperty splicing replace complicated interminable data format, be conducive to improve interface testing working efficiency, simplify workflow.
Above-mentioned specific implementation mode, does not constitute limiting the scope of the invention.Those skilled in the art should be brightIt is white, design requirement and other factors are depended on, various modifications, combination, sub-portfolio and replacement can occur.It is anyModifications, equivalent substitutions and improvements made by within the spirit and principles in the present invention etc., should be included in the scope of the present inventionWithin.