Embodiment
Below with reference to accompanying drawings exemplary embodiment of the present disclosure is described in more detail.Although show exemplary embodiment of the present disclosure in accompanying drawing, however should be appreciated that can realize the disclosure in a variety of manners and not should limit by the embodiment set forth here.On the contrary, provide these embodiments to be in order to more thoroughly the disclosure can be understood, and complete for the scope of the present disclosure can be conveyed to those skilled in the art.
It is current when network application is tested, mainly JavaScript script (hereinafter referred to as JS script) is tested, for this reason, first the test webpage 14 that structure one is corresponding with the Web page 12 that will test, JS script 142(except comprising needs test in test webpage 14 is equivalent to performance element) except, the JS test script 144(that also embedded in the JS script 142 that will test is tested is equivalent to test cell), test webpage 14 can run JS script 142 automatically, and show test results on test webpage 14, this is as shown in Figure 1.
But, because test webpage 14 and Web page 12 to be tested are separated, and the JS script 142 of needs test often relates to the HTML(HypertextMarkupLanguage in Web page 12, HTML (Hypertext Markup Language)) element, this causes to test the part relating to Web page 12 in JS script 142.In addition, JS script 142 and JS test script 144 separate, and the closure part in the JS script 142 that this causes needs to be tested cannot be tested.Because JS script allows at a function nested inside function, namely function can be defined in inside another one function, is called intrinsic function and external function.Wherein, intrinsic function can access the action scope member of external function, comprises the local variable of external function, parameter and other intrinsic function.Like this, the definition of intrinsic function and its action scope just define a closure, when when other local this intrinsic function of access, also can access the action scope member of external function simultaneously.
For this reason, the present invention proposes a kind of method of testing of testing network application and test macro, and wherein network application comprises one or more webpage to be tested, and each webpage to be tested comprises the page and one or more script be associated.Illustrate according to an embodiment of the invention, be suitable for the process flow diagram of the network application method of testing 200 solved the problem below in conjunction with Fig. 2.
As shown in Figure 2, method of testing 200 of the present invention starts from step S210.In step S210, Embedded test unit in each performance element to be tested of webpage to be tested, wherein test cell is suitable for testing the function of corresponding performance element.
Alternatively, the n-back test of above-mentioned performance element and the test function of above-mentioned test cell is realized by JS script.Only introduce method of testing embodiment of the present invention for JS script below, it is appreciated of course that, do not limit the script of the function realizing this performance element and test cell in an embodiment of the present invention.
Particularly, when writing the JS script (being equivalent to performance element) to be tested in Web page to be tested, can the JS script of any local Embedded test unit in each JS script to be tested, wherein test cell is suitable for testing the function of corresponding JS script to be tested.The JS script of every section of test cell can adopt and start with certain special marking, then terminates with certain special marking.Such as, the character string of the beginning label of test cell can be " // #iftest ", and alternatively, this character string can new line in above-mentioned code; Correspondingly, the character string of the end mark of test cell can be " // #endiftest ", and alternatively, this character string can new line in above-mentioned code.It is appreciated of course that, do not limit the representation of beginning label in special marking and end mark in an embodiment of the present invention.
Code below gives the situation of the JS script of Embedded test unit in the part JS script to be tested in Web page to be tested, and wherein the JS script of test cell starts with " // #iftest ", terminates with " // #endiftest ":
In above-mentioned code, function init is the performance element that will carry out testing, and test_logo_init is test cell.The JS script of test cell can follow certain rule, and such as it is a trial function, and its trial function name adopts with " test " beginning, and is an attribute of object window.Apo.It is appreciated of course that, do not limit the form of expression of the trial function in the JS script of this test cell in an embodiment of the present invention.
Subsequently, in step S220, Embedded test engine in this webpage to be tested, test cell is registered in this testing engine.Wherein, testing engine can be encapsulated as a JS script, and is embedded in webpage to be tested by the mode of include.In addition, can comprise test cell list in testing engine, test cell list comprises the test cell to testing engine registration.
Subsequently, in step S230, in testing engine, for each test cell of registering to it, perform the test function of described test cell, thus the performance element being embedded with test cell is tested.Particularly, this testing engine automatically can detect each performance element to be tested (JS script namely to be tested) before this Homepage Publishing to be tested, from the performance element that each is to be tested, extract corresponding test cell (i.e. JS test script) respectively and automatically run, to test performance element to be tested accordingly respectively.
According to one embodiment of present invention, in step S230, when test starts, testing engine can detect all properties of a global object window.Apo automatically, extracts the trial function that all test start, then runs.In test function, at least need to call an Apo.assert method, if do not called, testing engine will think that test is not passed through.
Provide a specific code example below:
Should be noted that, when processing JS script, need to consider that JS script belongs to the synchronous process performing and can obtain result immediately, need after still belonging to execution to wait for a period of time (such as with server mutual) could obtain the asynchronous process of result.If JS script belongs to asynchronous process, then when testing, needing waits for a period of time determines that whether test result is correct again.
After step S230, can direct process ends.Alternatively, can also step S240 be performed after step S230, in step S240, be presented to the test result of each performance element to be tested in Web page, and then the flow process of method ends.
According to one embodiment of present invention, step S240 can realize by code as follows:
Alternatively, in order to obtain the webpage to be tested of " totally ", after step S240, can also step S250 be performed, test cell and testing engine are removed from webpage to be tested, and then the flow process of method ends.Due in the above example, the JS script of every section of test cell can adopt and start with certain special marking, terminate with certain special marking again, therefore can remove test cell conveniently by location special marking from webpage to be tested, and obtain the Web page that can formally issue.
It should be noted that, the method shown in Fig. 2 does not limit is undertaken by the order of shown each step, and can adjust the sequencing of each step as required, such as step S220 also can perform before step S210.In addition, the step in the method shown in Fig. 2 is also not limited to the division of above-mentioned steps, and above-mentioned steps can split into more multi-step further also can be merged into less step.
See Fig. 3, the Web page 32 do not issued comprises: one or more JS script 322 of being associated and testing engine 324, wherein Embedded test unit 3222 in JS script 322, this test cell 3222 is suitable for testing the function of corresponding JS script 322, and is registered in testing engine 324 by test cell 3222.
During test, testing engine 324 automatically can detect JS script 322 in the Web page 32 do not issued, and extracts corresponding test cell 3222 and automatically run, to test the function of JS script 322 from JS script 322.
After being completed, 326 are shown test results in the Web page 32 do not issued, then by distributor 34, the Web page 32 do not issued is processed, wherein relevant to test code (is specifically comprised testing engine 324, test result 326, and be embedded into the test cell 3222 in JS script 322) remove.That is, before formal issue Web page, all associated documents are checked by distributor 34, character string in Study document, test special marking (i.e. mentioned above // #iftest and // #endiftest) and between code get rid of, thus obtain " totally ", the Web page that can issue and JS script 322, then issued by distributor 34, obtain the Web page 36 after issuing.
Illustrate according to an embodiment of the invention below in conjunction with Fig. 4, be suitable for a kind of network application test macro 400 of solving the problem, wherein network application comprises one or more webpage to be tested, and each webpage to be tested comprises the page and one or more script be associated.
As shown in Figure 4, test macro 400 comprises: testing engine 410 and test cell 420, and wherein testing engine 410 is added in webpage to be tested; Test cell 420 to be embedded in the performance element of the script be associated of webpage to be tested and to be registered in testing engine, is suitable for testing the function of corresponding performance element.Test macro 400 of the present invention performs the test function of the test cell 420 to its registration by testing engine 410, thus tests the performance element being embedded with this test cell 420.
Alternatively, the function of the n-back test of performance element and the test of test cell 420 is realized by JS script.Only be introduced method of testing embodiment of the present invention for JS script below, it is appreciated of course that, do not limit the script of the function realizing this performance element and test cell in an embodiment of the present invention.
Alternatively, test macro 400 also comprises display unit 430.Display unit 430 shows the test result that test cell 420 is tested corresponding performance element.
Alternatively, testing engine 410 can comprise test cell list, and this test cell list comprises the test cell 420 of registering to testing engine 410.
Alternatively, test cell 420 comprises the special string being separately positioned on its head and the tail.Wherein, the special marking of stem can be set to " // #iftest "; The character string of the distinctive mark of afterbody is " // #endiftest ".It is appreciated of course that, do not limit the representation of special marking in an embodiment of the present invention.
Alternatively, test macro 400 also comprises removal unit 440.Test cell 420 and testing engine 410, after the test of test cell 420 pairs of performance elements completes, are removed by this removal unit 440 from webpage to be tested.The relevant code of test can be got rid of flexibly by removal unit 440, this guarantees any position that test cell 420 can be embedded into webpage to be tested neatly.
Want special instruction, intrinsic not relevant to any certain computer, virtual system or miscellaneous equipment with display at this algorithm provided.Various general-purpose system also can with use based on together with this teaching.According to description above, the structure constructed required by this type systematic is apparent.In addition, the present invention is not also for any certain programmed language.It should be understood that and various programming language can be utilized to realize content of the present invention described here, and the description done language-specific is above to disclose preferred forms of the present invention.
In instructions provided herein, describe a large amount of detail.But can understand, embodiments of the invention can be put into practice when not having these details.In some instances, be not shown specifically known method, structure and technology, so that not fuzzy understanding of this description.
Similarly, be to be understood that, in order to simplify the disclosure and to help to understand in each inventive aspect one or more, in the description above to exemplary embodiment of the present invention, each feature of the present invention is grouped together in single embodiment, figure or the description to it sometimes.But, the method for the disclosure should be construed to the following intention of reflection: namely the present invention for required protection requires feature more more than the feature clearly recorded in each claim.Or rather, as claims below reflect, all features of disclosed single embodiment before inventive aspect is to be less than.Therefore, the claims following embodiment are incorporated to this embodiment thus clearly, and wherein each claim itself is as independent embodiment of the present invention.
Those skilled in the art are appreciated that and adaptively can change the module in the system in embodiment and they are arranged in one or more systems different from this embodiment.Module in embodiment or unit or assembly can be combined into a module or unit or assembly, and multiple submodule or subelement or sub-component can be put them in addition.Except at least some in such feature and/or process or unit be mutually repel except, any combination can be adopted to combine all processes of all features disclosed in this instructions (comprising adjoint claim, summary and accompanying drawing) and so disclosed any method or system or unit.Unless expressly stated otherwise, each feature disclosed in this instructions (comprising adjoint claim, summary and accompanying drawing) can by providing identical, alternative features that is equivalent or similar object replaces.
In addition, those skilled in the art can understand, although embodiments more described herein to comprise in other embodiment some included feature instead of further feature, the combination of the feature of different embodiment means and to be within scope of the present invention and to form different embodiments.Such as, in the following claims, the one of any of embodiment required for protection can use with arbitrary array mode.
All parts embodiment of the present invention with hardware implementing, or can realize with the software module run on one or more processor, or realizes with their combination.It will be understood by those of skill in the art that the some or all functions that microprocessor or digital signal processor (DSP) can be used in practice to realize according to the some or all parts in the embodiment of the present invention.The present invention can also be embodied as part or all equipment for performing method as described herein or device program (such as, computer program and computer program).Realizing program of the present invention and can store on a computer-readable medium like this, or the form of one or more signal can be had.Such signal can be downloaded from internet website and obtain, or provides on carrier signal, or provides with any other form.
The present invention will be described instead of limit the invention to it should be noted above-described embodiment, and those skilled in the art can design alternative embodiment when not departing from the scope of claims.In the claims, any reference symbol between bracket should be configured to limitations on claims.Word " comprises " not to be got rid of existence and does not arrange element in the claims or step.Word "a" or "an" before being positioned at element is not got rid of and be there is multiple such element.The present invention can by means of including the hardware of some different elements and realizing by means of the computing machine of suitably programming.In the unit claim listing some devices, several in these devices can be carry out imbody by same hardware branch.Word first, second and third-class use do not represent any order.Can be title by these word explanations.