Embodiment
Below in conjunction with accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried out clear, completeGround is described, it is clear that described embodiment is only a part of embodiment of the invention, rather than whole embodiments.Generally existThe component of the embodiment of the present invention described and illustrated in accompanying drawing can be arranged and designed with a variety of configurations herein.CauseThis, the detailed description of the embodiments of the invention to providing in the accompanying drawings is not intended to limit claimed invention belowScope, but it is merely representative of the selected embodiment of the present invention.Based on embodiments of the invention, those skilled in the art are not doingThe every other embodiment obtained on the premise of going out creative work, belongs to the scope of protection of the invention.
The test case code automatically generating device that present pre-ferred embodiments are provided can be applied to such as Fig. 1 institutes with methodIn the application environment shown.As shown in figure 1, client 100, server 200 and proxy server 400 are located at wireless network or hadIn gauze network, by the wireless network or cable network, server 200 is carried out with client 100, proxy server 400 respectivelyData interaction.In the embodiment of the present invention, at least one application program (Application, APP) is installed in client 100,It is corresponding with server 200, provide the user service.In the embodiment of the present invention, client 100 is preferably that mobile terminal is setIt is standby, it can for example include smart mobile phone, tablet personal computer, pocket computer on knee, Wearable mobile terminal etc..
Fig. 2 shows the structured flowchart of the server 200 in the embodiment of the present invention.As shown in Fig. 2 server 200 includesTest case code automatically generating device 300, memory 101, storage control 102, it is one or more (one only to be shown in figureIt is individual) processor 103, Peripheral Interface 104 etc..These components are mutually communicated by one or more communication bus/signal wire.It is describedTest case code automatically generating device 300, which includes at least one, to be stored in institute in the form of software or firmware (firmware)State in memory 101 or be solidificated in the software function in the operating system (operating system, OS) of the server 200Module.
Picture processing device that memory 101 can be used in storage software program and module, such as embodiment of the present invention andProgrammed instruction/module corresponding to method, processor 103 is stored in software program and mould in memory 101 by operationBlock, so that various function application and data processing are performed, such as test case Code automatic build provided in an embodiment of the present inventionMethod.Memory 101 can also include high speed random access memory, may also include nonvolatile memory, such as one or moreMagnetic storage device, flash memory or other non-volatile solid state memories.Processor 103 and other possible components are to depositingThe access of reservoir 101 can be carried out under the control of storage control 102.
Various input/output devices are coupled to processor 103 and memory 101 by Peripheral Interface 104.In some implementationsIn example, Peripheral Interface 104, processor 103 and storage control 102 can be realized in one single chip.In some other realityIn example, they can be realized by independent chip respectively.
It is appreciated that the structure shown in Fig. 2 is only signal, server 200 may also include more more than shown in Fig. 2 or moreFew component, or with the configuration different from shown in Fig. 2.Each component shown in Fig. 2 can use hardware, software or its groupClose and realize.
Referring to Fig. 3, the embodiments of the invention provide a kind of test case code automatically generating device 300, applied to clothesBusiness device 200, the server 200 is set up with client 100 and communicated to connect, and the test case code automatically generating device 300 is wrappedInclude data-reading unit 301, parameter extraction unit 302, searching unit 303, code generating unit 304, information receiving unit305th, judging unit 306 and information transmitting unit 307.
Described information receiving unit 305 is used for the name information for receiving the trial function to be measured that a client 100 is sent.
For example, user selects in the application program that client 100 (mobile phone or computer) is installed and clicks on trial function to be measuredName information, now client 100 name information of trial function to be measured is sent to server 200.
The judging unit 306 is used to judge whether to be cached with the code associated with the name information of the trial function to be measuredPacket.
In the present embodiment, code data bag can use but be not limited to java language codes packet or C Plus Plus code numberAccording to bag or C language code data bag, the embodiment of the present invention is with using the illustration of java language codes packet.
If the data-reading unit 301 is used to be cached with the code number associated with the name information of the trial function to be measuredDuring according to bag, the code data bag of trial function to be measured is read in pre-stored object code catalogue.
If described information transmitting element 307 has the code that the name information with the trial function to be measured is associated for uncachedDuring packet, request of data is sent to a proxy server 400.
Described information receiving unit 305 be used to receiving the proxy server 400 feeds back according to the request of data withThe code data bag of the name information association of the trial function to be measured.
When in server 200 it is uncached have code data bag when, can to proxy server 400 send request of data, if generationReason server 400 be stored with the code data bag associated with the name information of the trial function to be measured when, will directly be treated with describedThe code data bag of the name information association of test function is sent to server 200, so as to need tester to find and uploadCode data bag, it is convenient and swift.The present embodiment, code server 400 is interacted with multiple servers 200, and receives multiple servicesDevice 200 is in the different code data bags uploaded during test mode and stored.
Parameter extraction unit 302 is used to extract the multiple input type parametric variables included in trial function to be measured and returnValue.
In Java language, data type is essentially divided into two kinds:Fundamental type and reference data type.Basic classType:Simple data type is data type can not simplify, built-in, defined in itself by programming language that it is illustrated reallyNumeral, character and integer.Reference data type:Java language does not support structure (struct) or joint in C++ in itself(union) data type, its composite data type is typically all to be constructed by class or interface, and class provides binding dataWith the mode of method, Information hiding is carried out while can be directed to outside program.Return value, can be with for test case codeAccuracy for verifying tested trial function.
The searching unit 303 is used to search and each input parameter categorical variable pair from default rule fileThe variable-value scope answered.
In the present embodiment, fundamental type and reference data type include polytype variable respectively, for example, input type is joinedNumber variable includes integer variable, floating type variable, logical type variable and character type variable etc., and every kind of variable has oneselfSpan, for example, the span of integer variable be -2^31 to 2^31-1 between arbitrary integer.
Code generating unit 304 is used for pair according to multiple input type parametric variables, each input type parametric variableSpan, return value and the code data bag generation test case code answered.
In the present embodiment, using java reflex mechanisms by input type parametric variable, each input type parametric variableCorresponding span, return value and the code data bag are in the way of presetting rule is spliced using text, woundBuild out the test case code of tested trial function.
Wherein, java reflex mechanisms refer to, java reflex mechanisms be in running status, can for any one classEnough know all properties and method of this class;For any one object, its any means and attribute can be called;ThisKind dynamic access information and the function of dynamic call object method are referred to as the reflex mechanism of java language.
Test case code refers to one group of test input, execution condition and the expected knot worked out for some special objectiveReally, to test some Program path or examine whether meet the software code of some particular demands.
It is preferred that in view of being generated using each value of the corresponding span to each input type parametric variableTest case code tested trial function is tested, coverage rate is higher, but it is long to expend the time, process complexity, if to everyOne of value test case code of the corresponding span of individual input type parametric variable is carried out to tested trial functionTest, time-consuming short, process is simple, but coverage rate is low.
It is thus preferable to, the code generating unit 304 is used for according to multiple input type parametric variables, each inputThe maximum positive value of the corresponding span of type parameter variable, null value and minimum negative value, return value and the generationCode packet generation test case code.
Utilize the maximum positive value of the corresponding span of each input type parametric variable, null value and minimum negativeIt is time-consuming relatively short and brief when value, return value and code data bag generation test case code are to tested trial function,And coverage rate is of a relatively high.
Referring to Fig. 4, the embodiment of the present invention additionally provide a kind of test case code automatic generation method, it is necessary to explanationBe, the test case code automatic generation method that the embodiment of the present invention is provided, the technique effect of its general principle and generation andAbove-described embodiment is identical, to briefly describe, and the present embodiment part does not refer to part, refers in corresponding in the above embodimentsHold.The test case code automatic generation method includes:
Step S401:Receive the name information of the trial function to be measured of a client 100 transmission.
It is to be appreciated that step S401 can be performed by information receiving unit 305.
Step S402:Judge whether to be cached with the code data bag associated with the name information of the trial function to be measured, such asIt is really no, then step S403 is performed, if it is, performing step S405.
It is to be appreciated that step S402 can be performed by judging unit 306.
Step S403:Request of data is sent to a proxy server 400.
It is to be appreciated that step S403 can be performed by information transmitting unit 307.
Step S404:Receive the proxy server 400 being fed back according to the request of data with the trial function to be measuredName information association code data bag.
It is to be appreciated that step S404 can be performed by information receiving unit 305.
Step S405:The code data bag of trial function to be measured is read in pre-stored object code catalogue.
It is to be appreciated that step S405 can be performed by data-reading unit 301.
In the present embodiment, code data bag can use java language codes packet or C Plus Plus code data bag or C languagesSay code data bag.
Step S406:Extract the multiple input type parametric variables included in trial function to be measured and return value.
It is to be appreciated that step S406 can be performed by parameter extraction unit 302.
Step S407:Become corresponding with each input parameter categorical variable is searched from default rule file to measureIt is worth scope.
It is to be appreciated that step S407 can be performed by searching unit 303.
Step S408:According to multiple input type parametric variables, the corresponding value model of each input type parametric variableEnclose, return value and the code data bag generate test case code.
It is to be appreciated that step S408 can be performed by code generating unit 304.
Specifically step S408 can be included according to multiple input type parametric variables, each input type parametric variableThe maximum positive value of corresponding span, null value and minimum negative value, return value and code data bag generation are surveyedExample code on probation.
In summary, the present invention is provided test case code automatically generating device and method, first by pre-storedObject code catalogue in read the code data bag of trial function to be measured;Then included in trial function to be measured multiple defeated is extracted againEnter type parameter variable and return value;Then searched and each input parameter categorical variable pair from default rule fileThe variable-value scope answered;Finally taken according to multiple input type parametric variables, each the corresponding of input type parametric variableIt is worth scope, return value and code data bag generation test case code.The test case code automatically generating device withMethod programs substantial amounts of test code without tester oneself, greatlyd save by automatically generating test case codeHuman cost, and it is high to generate test case code coverage.
In several embodiments provided herein, it should be understood that disclosed apparatus and method, it can also pass throughOther modes are realized.Device embodiment described above is only schematical, for example, flow chart and block diagram in accompanying drawingShow according to the device of multiple embodiments of the present invention, the architectural framework in the cards of method and computer program product,Function and operation.At this point, each square frame in flow chart or block diagram can represent the one of a module, program segment or codePart a, part for the module, program segment or code is used to realize holding for defined logic function comprising one or moreRow instruction.It should also be noted that in some implementations as replacement, the function of being marked in square frame can also with different fromThe order marked in accompanying drawing occurs.For example, two continuous square frames can essentially be performed substantially in parallel, they are sometimesIt can perform in the opposite order, this is depending on involved function.It is also noted that every in block diagram and/or flow chartThe combination of individual square frame and block diagram and/or the square frame in flow chart, can use the special base for performing defined function or actionRealize, or can be realized with the combination of specialized hardware and computer instruction in the system of hardware.
In addition, each functional module in each embodiment of the invention can integrate to form an independent portionPoint or modules individualism, can also two or more modules be integrated to form an independent part.
If the function is realized using in the form of software function module and is used as independent production marketing or in use, can be withIt is stored in a computer read/write memory medium.Understood based on such, technical scheme is substantially in other wordsThe part contributed to prior art or the part of the technical scheme can be embodied in the form of software product, the meterCalculation machine software product is stored in a storage medium, including some instructions are to cause a computer equipment (can be individualPeople's computer, server, or network equipment etc.) perform all or part of step of each of the invention embodiment methods described.And foregoing storage medium includes:USB flash disk, mobile hard disk, read-only storage (ROM, Read-Only Memory), arbitrary access are depositedReservoir (RAM, Random Access Memory), magnetic disc or CD etc. are various can be with the medium of store program codes.NeedIllustrate, herein, such as first and second or the like relational terms be used merely to by an entity or operation withAnother entity or operation make a distinction, and not necessarily require or imply between these entities or operation there is any this realityThe relation or order on border.Moreover, term " comprising ", "comprising" or its any other variant are intended to the bag of nonexcludabilityContain, so that process, method, article or equipment including a series of key elements are not only including those key elements, but also includingOther key elements being not expressly set out, or also include for this process, method, article or the intrinsic key element of equipment.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that including the key elementProcess, method, article or equipment in also there is other identical element.
The preferred embodiments of the present invention are the foregoing is only, are not intended to limit the invention, for the skill of this areaFor art personnel, the present invention can have various modifications and variations.Within the spirit and principles of the invention, that is made any repaiiesChange, equivalent substitution, improvement etc., should be included in the scope of the protection.It should be noted that:Similar label and letter existsSimilar terms is represented in following accompanying drawing, therefore, once being defined in a certain Xiang Yi accompanying drawing, is then not required in subsequent accompanying drawingIt is further defined and explained.
The foregoing is only a specific embodiment of the invention, but protection scope of the present invention is not limited thereto, anyThose familiar with the art the invention discloses technical scope in, change or replacement can be readily occurred in, should all be containedCover within protection scope of the present invention.Therefore, protection scope of the present invention described should be defined by scope of the claims.
It should be noted that herein, such as first and second or the like relational terms are used merely to a realityBody or operation make a distinction with another entity or operation, and not necessarily require or imply these entities or deposited between operatingIn any this actual relation or order.Moreover, term " comprising ", "comprising" or its any other variant are intended toNonexcludability is included, so that process, method, article or equipment including a series of key elements not only will including thoseElement, but also other key elements including being not expressly set out, or also include being this process, method, article or equipmentIntrinsic key element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded thatAlso there is other identical element in process, method, article or equipment including the key element.