Summary of the invention
In view of the above problems, the object of the present invention is to provide a kind of test processing method and devices, are able to achieve virtual difference
Network environment for testing, be more convenient to use.
Test processing method provided by the invention, comprising:
The type information of network to be tested and the type information of test program present access network are obtained respectively;Wherein, lead to
It crosses and is inserted into file corresponding with the type of network to be tested in the network type file inside test program, obtain to be tested
The type information of network;Wherein,
The type information of network to be tested includes the first of the type of network to be tested and the type of expression network to be tested
Network type return value;The type information of test program present access network include test program present access network type and
Indicate the second network type return value of the type of test program present access network;
Test program present access network type and network to be tested type difference when, by by the second network class
Type return value replaces with first network type return value, and the network type for being currently accessed test program becomes accessing net to be tested
The type of network.
Test processes device provided by the invention, comprising:
File pitching pile unit, for being inserted into the type with network to be tested in the network type file inside test program
Corresponding file;
Network type information acquisition unit to be tested, for the text corresponding with the type of network to be tested by insertion
Part obtains the type information of network to be tested;Wherein, the type information of network to be tested includes the type and table of network to be tested
Show the first network type return value of the type of network to be tested;
Current network type information acquisition unit, for obtaining the type information of test program present access network;Wherein,
The type information of test program present access network includes the type of test program present access network and indicates that test program is worked as
Second network type return value of the type of preceding access network;
Return value replacement unit, it is different from the type of network to be tested for the type in test program present access network
When, the second network type return value is replaced with into first network type return value, makes the type of test program present access network
Become accessing the type of network to be tested.
Device end provided by the invention, including for storing network type information memory and test processes above-mentioned
Device.
Using the above-mentioned test processing method and device provided according to the present invention, pass through the network class inside test program
It is inserted into file (being inserted into corresponding document by way of pitching pile) corresponding with the type of network to be tested in type file, obtains
It indicates the first network type return value of the type of network to be tested, while obtaining the class for indicating test program present access network
Second network type return value of type, in the type and the type difference of network to be tested of test program current network, so that it may
To replace the second network type return value with first network type return value, thus the network type that test program is currently accessed
The type of network to be tested is invented, realizes virtual different network environment for testing.
To the accomplishment of the foregoing and related purposes, one or more aspects of the present invention include be particularly described below and
The feature particularly pointed out in claim.Certain illustrative aspects of the invention is described in detail in the following description and the annexed drawings.
However, these aspects indicate only usable some of the various ways in the principles of the present invention.In addition, of the invention
It is intended to include all such aspects and their equivalent.
Specific embodiment
In the following description, for purposes of illustration, it in order to provide the comprehensive understanding to one or more embodiments, explains
Many details are stated.It may be evident, however, that these embodiments can also be realized without these specific details.
In other examples, one or more embodiments for ease of description, well known structure and equipment are shown in block form an.
In existing testing scheme, it is desirable to which kind of network tested, it is necessary to use mobile phone card corresponding with the network, such as
Fruit does not have mobile phone card that can not then be tested, and therefore, the present invention proposes a kind of test processes scheme, can be worked as according to test program
The network type of preceding access, which invents, thinks network type to be tested, such as what test program was currently accessed is 3G network, and needs
2G network is tested, in the case where not using 2G card, 3G network is invented into 2G network and is tested.
Hereinafter, specific embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Fig. 1 shows the process of test processing method according to an embodiment of the present invention.
As shown in Figure 1, test processing method provided in an embodiment of the present invention, firstly, obtaining the class of network to be tested respectively
The type information of type information and test program present access network;Wherein, pass through the network type file inside test program
It is middle to be inserted into file corresponding with the type of network to be tested, obtain the type information of network to be tested;Wherein, network to be tested
Type information include the type of network to be tested and indicate network to be tested type first network type return value;Test
The type information of program present access network includes the type of test program present access network and indicates that test program currently connects
Enter the second network type return value (step S110) of the type of network;
Test program present access network type and network to be tested type difference when, by by the second network class
Type return value replaces with first network type return value, and the network type for being currently accessed test program becomes accessing net to be tested
The type (step S120) of network.
It should be noted that obtain the type for indicating network to be tested first network type return value can with obtain to
The type of test network carries out simultaneously, can also carry out after the type for obtaining network to be tested, and similarly, obtaining indicates test
Second network type return value of the type of program present access network can be in the class for obtaining test program present access network
Type carries out simultaneously, can also carry out after the type for obtaining test program present access network.
It should be noted the type phase of insertion and network to be tested in the network type file inside test program
The process of corresponding file is known as program pitching pile, and program pitching pile is by the insertion operation into tested program, to realize test mesh
Method.The basic principle of program pitching pile is under the premise of not destroying tested program original logic integrality, in program
Corresponding position on be inserted into some probes, these probes are exactly substantially the code segment for carrying out information collection, can be asignment statement
The function call of sentence or acquisition coverage information, by the operation characteristic data for executing simultaneously output program of probe, based on to these
The analysis of characteristic discloses the internal act and feature of program.
For more detailed description test processing method provided in an embodiment of the present invention, Fig. 2 shows real according to the present invention
Apply the detailed process of the test processing method of example.As shown in Fig. 2, the detailed stream of test processing method provided in an embodiment of the present invention
Journey, comprising:
Step S210: modification build script carries out pitching pile to class file.
Modification build script is in order to which pitching pile does homework, and modification build script makes code become application file,
Build script can tell build tool that the code of pitching pile is included.By taking a specific embodiment as an example,
It is that aspectj is individually placed on build_aspectj.xml that antcall a target, target are inserted into build.xml.
Fig. 3 a and Fig. 3 b respectively illustrate the scene of modification build script according to an embodiment of the present invention.
As shown in Figure 3a, antcall a target, antcall are inserted into build.xml for calling this script
Target in file.
As shown in Figure 3b, target is that aspectj is individually placed on build_aspectj.xml, and aspectj is used to generate
Class file.
Class file is the network type file inside test program, carries out pitching pile to network type file, that is,
Pitching pile is carried out to class file, insertion is file corresponding with the type of network to be tested.
Step S220: the class file after compiling pitching pile forms test program.
If it is Android system, what is formed after compiling is the test program of apk format, if it is ios system, shape after compiling
At be ipa format test program.
Step S230: starting test program obtains the type information and network to be tested of application program present access network
Type information.
The type information of application program present access network includes that the type of application program present access network and representative are worked as
Second network type return value of the network type of preceding access.
The mode that system offer API can be used in the mode of the type information of acquisition present access network obtains, and provides
API includes:
android.net.NetworkInfo.getType()、
android.net.NetworkInfo.getSubType()、
android.telephony.TelephonyManager.getNetworkType()。
The network type and indicate the network type that test program is currently accessed can be obtained by above-mentioned api interface
Second network type return value.
The type information of network to be tested be by the network type file inside test program be inserted into it is to be tested
The corresponding file acquisition of the type of network, and file corresponding with the type of network to be tested is by configuration file side
What formula or socket communication mode generated.
File corresponding with the type of network to be tested is preset network profile, that is, user setting
Network profile, network profile include the two aspect content of type and first network type return value of network to be tested,
Preset network type is exactly the type of network to be tested, that is, needs the network type of user setting, first network type
Return value represents the type of network to be tested, and passes through user setting.
Therefore, corresponding with the type of network to be tested by being inserted into the network type file inside test program
The type information of the network to be tested of file acquisition includes network type to be tested and the first network for indicating the network type
Type return value is obtained by the network profile of user setting.
The type information of above-mentioned acquisition present access network and the type information of network to be tested are sequences in no particular order,
Both the type information that can have first obtained network to be tested, can also first obtain the type information of present access network.
Fig. 4 shows the comparative diagram of network type according to an embodiment of the present invention Yu network type return value, wherein wifi
The corresponding network type return value of network type is 0*99999999, and the corresponding network type return value of GPRS network type is 0*
000000001, the network type return value of other network types corresponding thereto refers to Fig. 4.
Step S240: whether the type for judging test program present access network is identical as the type of network to be tested;Such as
Fruit is identical, executes step S260;If it is not the same, executing step S250.
Step S250: the second network type return value is replaced with into first network type return value.
After the second network type return value is replaced with first network type return value, test program present access network
Type can invent the type of network to be tested, at this point, the work of virtual network type to be tested is completed, test program can
To be tested according to virtual network to be tested.
Step S260: it is handled according to default behavior.
Default behavior refers to the replacement without first network type return value and the second network type return value, due to
The type of network to be tested is identical as the network type that test program is currently accessed, and having no need to change network type can test,
It is therefore not necessary to carry out the replacement of first network type return value and the second network type return value.
In order to further embody invention effect, by the effect of effect and the conventional test methodologies acquirement obtained using the present invention
It is compared, has carried out two groups of tests below:
It first group, tests " when network is switched to mobile network from wifi, browser can automatically switch to very fast mode "
According to conventional test methodologies, the scene for needing to cover is very more, such as wifi, GPRS, WCDMA mobile network,
Switch mutually between wifi network and those described above network, also, after handover network different surely correct switch to pole
Fast mode.And external network, other than needing specific mobile phone card, and special cell phone apparatus is needed, actually tested
Come very troublesome.
And use test processing method provided by the invention, it is only necessary to which the pitching pile in program code passes through modification and network
The corresponding network type return value of type, can disguise oneself as corresponding network, do not need truly using special mobile phone card and
Cell phone apparatus can be tested, and test effect is identical as conventional test methodologies.
Second group, test " certain photo class app, it is automatic to download cloud data when user is under wifi environment, and it is pre- on
Pass user local photo;And when under mobile network, automatic downloading is not done and pre- is uploaded " correctness of logic.
Conventional test methodologies, using specific mobile network card+corresponding cell phone apparatus, then under this network environment
The correctness of verifying logic.Then it is uploaded under mobile network and speed of download ratio wifi is slow very much, and the verifying of logic
Itself and network speed are not related.
It is to simulate mobile using the method for pitching pile during the test using test processing method provided by the invention
Network, it is not really necessary that specific mobile network card+corresponding cell phone apparatus, what whole process used is wifi network entirely,
This testing scheme easily realizes, low cost, low consumption when, and do not cause any interference to result.
Corresponding with above-mentioned test processing method, the present invention provides a kind of test processes device.Fig. 5 is shown according to this hair
The logical construction of the test processes device of bright embodiment.
As shown in figure 5, test processes device 500 provided in an embodiment of the present invention, including it is file pitching pile unit 510, to be measured
Try network type information acquisition unit 520, current network type information acquisition unit 530 and return value replacement unit 540.
Wherein, file pitching pile unit 510 is for insertion in the network type file inside test program and net to be tested
The corresponding file of the type of network.
Network type information acquisition unit 520 to be tested, for passing through the corresponding with the type of network to be tested of insertion
File, obtain the type information of network to be tested;Wherein, the type information of network to be tested includes the type of network to be tested
With the first network type return value for the type for indicating network to be tested;
Current network type information acquisition unit 530, for obtaining the type information of test program present access network;Its
In, the type information of test program present access network includes the type and expression test program of test program present access network
Second network type return value of the type of present access network;
Return value replacement unit 540, the type for type and network to be tested in test program present access network
When different, the second network type return value is replaced with into first network type return value, makes test program present access network
Type becomes accessing the type of network to be tested.
Fig. 6 shows the logical construction of a specific embodiment of test processes device according to an embodiment of the present invention.
As shown in fig. 6, test processes device 500 further includes network type judging unit 550, for obtaining net to be tested
After the type information of network and the type information of test program present access network, the type of test program present access network is judged
It is whether identical as the type of network to be tested;If identical, returned without the second network type return value with first network type
Return the replacement of value;If it is not the same, the second network type return value is replaced with first network type by return value replacement unit 540
Return value makes the type of test program present access network become accessing the type of network to be tested.
Wherein, the further file generating unit 560 of test processes device 500, for by configuration file mode or
Socket communication mode generates file corresponding with the type of network to be tested.
In addition, obtaining the type information of test program present access network in current network type information acquisition unit 530
During, the type information of test program present access network is obtained in such a way that test program provides API;Wherein, it surveys
Trying the API that program provides includes:
android.net.NetworkInfo.getType();
android.net.NetworkInfo.getSubType();
android.telephony.TelephonyManager.getNetworkType()。
The present invention correspondingly provides a kind of device end, and referring to Fig. 7, which includes for storing network class
The memory 710 and test processes device 500 of type information, wherein test device includes:
File pitching pile unit, for being inserted into the type with network to be tested in the network type file inside test program
Corresponding file.
Network type information acquisition unit to be tested, for the text corresponding with the type of network to be tested by insertion
Part obtains the type information of network to be tested;Wherein, the type information of network to be tested includes the type and table of network to be tested
Show the first network type return value of the type of network to be tested;
Current network type information acquisition unit, for obtaining the type information of test program present access network;Wherein,
The type information of test program present access network includes the type of test program present access network and indicates that test program is worked as
Second network type return value of the type of preceding access network;
Return value replacement unit, it is different from the type of network to be tested for the type in test program present access network
When, the second network type return value is replaced with into first network type return value, makes the type of test program present access network
Become accessing the type of network to be tested.
Test processes device has structure described in Fig. 5, and referring specifically to previously mentioned, details are not described herein again.
Test processing method and device provided by the invention is described in detail in the above content, will be indicated by the method for pitching pile
The first network type return value of the type of network to be tested is inserted into inside test program, is replaced with first network type return value
The second network type return value corresponding with the type of test program present access network is changed, so that test program currently be connect
The network type entered invents the type of network to be tested, realizes virtual different network environment for testing.
The above description is merely a specific embodiment, but scope of protection of the present invention is not limited thereto, any
Those familiar with the art in the technical scope disclosed by the present invention, can easily think of the change or the replacement, and should all contain
Lid is within protection scope of the present invention.Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.