Detailed Description
Embodiments of the present invention will be described below with reference to the accompanying drawings.
The method and the device for updating the test script are suitable for a scene of updating the test script of the test application program when the application program is updated in the process of automatically testing the application program (also called a system). The method is particularly suitable for a scene that the normal operation of the test script is influenced after the application program is updated, and the test script of the test application program is updated. The application program may be an application program of a third party, and may also be an application program of the terminal device, which may include at least one code segment. The test script is compiled, operated and debugged in a test platform (also called a test frame), and when the test script operates in the test frame, the test on the corresponding application program can be realized; a test script is also made up of lines of code (called test code), where one or more lines of test code are used to perform a test operation on an application program, and the one or more lines of test code used to perform a test operation on an application program are called a test step, and the execution of the test step may cause the execution of one or more code segments in the application program, and thus each test step may be said to test one or more code segments in at least one code segment.
In practical applications, the running of multiple test scripts may enable the testing of one application, while one test script uniquely tests one application. Therefore, it can be said that one application corresponds to a plurality of test scripts, and one test script corresponds to one application.
In the automated testing of applications, test scripts are typically written based on the application. Therefore, when an application is updated, especially when the application is updated to affect the running of the test script, the test script needs to be updated. However, since the maintenance cost of the test script is increased by manually updating the test script, the following method for updating the test script is proposed in the present application.
Fig. 1 is a flowchart of a method for updating a test script according to an embodiment of the present application. The execution subject of the method may be a device with processing capabilities: as shown in fig. 1, a server, a system, or an apparatus, such as a test platform, the method specifically includes:
all or part of the at least one code section is monitored, step 110.
Optionally, before performing step 110, all of the at least one code segment of the updated application program may be loaded into a management interface of the testing platform, and in the management interface, a user may select a part of the at least one code segment for monitoring. Specifically, if a selection instruction input by a user is received, selecting a part of code segments from at least one code segment according to the selection instruction; storing the partial code segments in a background database of the test platform, namely monitoring only the partial code segments when monitoring the code segments of the application program subsequently; otherwise, all the code segments in at least one code segment are stored in a background database of the test platform, namely all the code segments are monitored when the code segments of the application program are monitored subsequently.
Of course, the above description is only given by taking the process of storing part of code segments once as an example; when a plurality of partial code sections need to be monitored, repeatedly executing the operation of storing the partial code sections for many times; in addition, it should be noted that a part of the code segment may include one code segment, or may include a plurality of code segments.
It is understood that at least one original code segment of the application program before updating is stored in a background database of the test platform in advance, wherein each original code segment may correspond to one code segment of the application program after updating. The process of monitoring all code sections in at least one code section is as follows: reading each code segment in at least one code segment from a background database of the test platform, reading an original code segment corresponding to the code segment, comparing the code segment with the original code segment, and if the first code segment is inconsistent with the corresponding original code segment, determining that the first code segment is changed. The first code segment here may be any of at least one code segment. Similarly, the process of monitoring a part of code sections in at least one code section is: reading each code segment in a part of code segments from a background database of the test platform, reading an original code segment corresponding to each code segment, comparing the two code segments, and if the first code segment in the part of code segments is inconsistent with the corresponding original code segment, determining that the first code segment is changed.
In fact, in at least one code segment of the application program, part of the code segments are important, so that the updating frequency is high, and other code segments are not updated basically, or even if the code segments are updated, the running of the test script is not influenced, so that the code segments with low updating frequency are not monitored, and only the important part of the code segments are monitored, thereby improving the monitoring efficiency of the code segments.
And 120, when it is monitored that the first code segment in all or part of the code segments changes, reading one or more corresponding test steps from a preset storage unit, wherein the preset storage unit is used for storing the corresponding relation between the code segments of the application program and the test steps in the test script.
It is stated that one or more test steps corresponding to each of the at least one code section are predetermined. Specifically, the correspondence relationship may be stored in a preset storage unit. In one example, the predetermined memory location may be as shown in table 1.
TABLE 1
In table 1, the application includes four code segments, which are: a code segment A, a code segment B, a code segment C and a code segment D; in addition, the application program corresponds to two test scripts, which are respectively: test script X and test script Y. Taking the first code segment as "code segment a" as an example, it can be read from table 1 that the corresponding test script is "test script X", and the corresponding test steps are "test step 1" and "test step 2" in "test script X".
Of course, in practical applications, the test steps corresponding to the code segments may be determined in other manners.
Step 130, identifying the changed codes in the first code segment to determine the change type of the changed codes.
It should be noted that when it is monitored that the first code segment changes, that is, when it is monitored that the first code segment is inconsistent with the corresponding original code segment in comparison, the code with inconsistent comparison in the first code segment and the corresponding original code segment, that is, the changed code may be identified, so as to determine the change type of the changed code. In one example, when it is recognized that a name of a User Interface (UI) element in the first code segment is changed, for example, the name of the UI element in the first code segment is "button a", and the name of the UI element in the corresponding original code segment is "button B", where the name of the UI element is a changed code, so that a change type of the changed code may be determined as "change of UI element"; in another example, when it is recognized that the number of the interface parameters in the first code segment changes, for example, the interface parameters of the service interface provided by the application program in the first code segment include "parameter a", "parameter B", and "parameter C", and the interface parameters of the service interface in the corresponding original code segment include "parameter a" and "parameter B". Here, the interface parameter of the service interface is the changed code, and therefore, the change type of the changed code may be determined as "change of the interface parameter"; by analogy, the change type of all changed codes can be determined.
And step 140, when the change type of the code belongs to a preset change type, updating the one or more test steps according to the changed code.
Here, the preset variation types include, but are not limited to, one or more of the following types: changes in UI elements of the user interface, changes in parameters of the interface, changes in results returned by the interface, changes in paths, and the like. Here, the change of the UI element and the change of the interface parameter may be referred to as an example in step 130. And the change of the interface return result may mean that the first code segment is inconsistent with the type of the return result in the corresponding original code segment, for example, the change is from a return boolean type value to a return numerical value, etc. The change of the path may refer to a new field in the database table or a change in the field name, etc.
It should be noted that, in practical applications, the preset change types may not be limited to the above-mentioned ones, and those skilled in the art may preset according to experience and needs, for example, all the change types of the code that can affect the running of the test script may be set as the preset change types, which is not limited in this application.
In step 140, updating the one or more test steps according to the changed code, specifically:
replacing the UI element before change in the one or more testing steps with the changed UI element in the first code segment when the change type of the code belongs to the change of the UI element; alternatively, the first and second electrodes may be,
when the change type of the code belongs to the change of the interface parameters, replacing the interface parameters before the change in the one or more test steps with the changed interface parameters in the first code segment; alternatively, the first and second electrodes may be,
when the change type of the code belongs to the change of the interface return result, replacing the interface return result before the change in the one or more test steps with the changed interface return result in the first code segment;
when the change type of the code belongs to the change of the path, replacing the path before the change in the one or more test steps with the changed path in the first code segment.
It should be noted that the test script of the present application is used for testing the application program before updating, and therefore, information such as the name of the UI element, the interface parameter, the interface return result, and the path in the test script is the same as information in the application program before updating; in order to correctly test the updated application program, the information in one or more steps corresponding to the first code segment may be modified to update the test script. As in the previous example, the name of the UI element in one or more test steps corresponding to the first code segment "button B" may be modified to "button a"; the interface parameters "parameter a" and "parameter B" in one or more test steps corresponding to the first code segment may be modified to "parameter a", "parameter B", and "parameter C", etc.
Based on the above two updating methods of the test script, those skilled in the art can perform corresponding updating on the test steps corresponding to the code segments of other variation types, which is not described herein again. It should be noted that, when the test platform executes the above update process on the test script, the update part in each test step may be recorded accordingly.
It is understood that the above-mentioned determination of whether the change type of the code belongs to the preset change type is to determine whether the change of the code affects the operation of the test script. Of course, in practical applications, it may also be determined whether the change of the code will affect the operation of the test script in other ways, as long as the code affecting the change of the test script operation can be correctly and safely identified. For example, the corresponding test steps of the changed code segment may be combined to determine whether the changed code may affect the execution of the test script.
It should be noted that when it is determined by some judgment method that the change of the code does not affect the running of the test script, the change can be ignored. It is understood that after updating one or more test steps according to the changed code or ignoring the change of the code, the monitoring process of the test platform on at least one code segment of the updated application program is finished; after the monitoring process is finished, testing the updated application program according to the updated or non-updated test script; after the testing process is finished, the testing platform may send the updated part in each testing step and the running result of the updated or non-updated testing script to the tester by way of mail, so that the tester may summarize the testing result of the updated application program.
Of course, in practical applications, there may be a case where the test platform fails to analyze the change type of the code, and in this case, the test platform may also notify the tester by sending an email, so that the tester may perform further analysis.
The updating method of the test script provided by the application monitors all or part of at least one code segment; when the change of a first code segment in all or part of the code segments is monitored, reading one or more corresponding test steps from a preset storage unit; identifying the changed codes in the first code section to determine the change types of the changed codes; and when the change type of the code belongs to the preset change type, updating one or more test steps according to the changed code. In the application, when the code segment is monitored to change, the corresponding test step can be directly updated according to the changed code, so that the automatic updating and maintenance of the test script are realized, the workload of testers is reduced, and the test efficiency of the application program is improved.
Correspondingly to the above method for updating a test script, an embodiment of the present application further provides an apparatus for updating a test script, where the test script is used to test a corresponding application program, where the application program includes at least one code segment, and the test script includes at least one test step, where each test step is used to test one or more code segments in the at least one code segment, as shown in fig. 2, the apparatus includes: a monitoring unit 201, a reading unit 202, an identification unit 203 and an update unit 204.
A monitoring unit 201, configured to monitor all or part of the at least one code segment.
The monitoring unit 201 is specifically configured to:
acquiring at least one original code segment of the application program before updating, wherein each original code segment corresponds to one code segment in the at least one code segment;
and comparing each code segment in all or part of the code segments with the corresponding original code segment, and if the comparison of the first code segment with the corresponding original code segment is inconsistent, determining that the first code segment in all or part of the code segments is changed.
A reading unit 202, configured to read one or more corresponding test steps from a preset storage unit when the monitoring unit 201 monitors that a first code segment in all or part of the code segments changes, where the preset storage unit is used to store a corresponding relationship between a code segment of the application and a test step in the test script.
An identifying unit 203, configured to identify a code that changes in the first code segment to determine a change type of the changed code.
An updating unit 204, configured to update the one or more testing steps according to the changed code when the identifying unit 203 identifies that the change type of the code belongs to a preset change type.
Wherein the preset variation types include, but are not limited to, one or more of the following types:
changes in user interface UI elements, changes in interface parameters, changes in interface return results, and changes in paths.
The updating unit 204 is specifically configured to:
replacing the UI element before change in the one or more testing steps with the changed UI element in the first code segment when the change type of the code belongs to the change of the UI element; alternatively, the first and second electrodes may be,
when the change type of the code belongs to the change of the interface parameters, replacing the interface parameters before the change in the one or more test steps with the changed interface parameters in the first code segment; alternatively, the first and second electrodes may be,
when the change type of the code belongs to the change of the interface return result, replacing the interface return result before the change in the one or more test steps with the changed interface return result in the first code segment;
when the change type of the code belongs to the change of the path, replacing the path before the change in the one or more test steps with the changed path in the first code segment.
Optionally, the apparatus further comprises: a selecting unit 205 and a storing unit 206.
A selecting unit 205, configured to select a part of code segments from the at least one code segment according to a selection instruction input by a user.
A storage unit 206, configured to store the part of code segments selected by the selecting unit 205 in a background database.
The functions of the functional modules of the device in the embodiment of the present application may be implemented through the steps in the method embodiment described above, and therefore, the specific working process of the device provided in the present application is not repeated herein.
In the updating apparatus for a test script provided by the present application, the monitoring unit 201 monitors all or part of the at least one code segment; when the first code segment in all or part of the code segments changes, the reading unit 202 reads the corresponding one or more test steps from a preset storage unit; the identifying unit 203 identifies the changed codes in the first code segment to determine the change type of the changed codes; when the change type of the code belongs to a preset change type, the updating unit 204 updates the one or more test steps according to the changed code. Therefore, automatic updating and maintenance of the test script are achieved, workload of testers is reduced, and test efficiency of the application program is improved.
The updating device of the test script can be embedded into the existing test platform in a plug-in mode, and monitors all or part of the code segments of at least one code segment of the application program on the basis of the existing test platform.
Those of skill would further appreciate that the various illustrative objects and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied in hardware, a software module executed by a processor, or a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above-mentioned embodiments, objects, technical solutions and advantages of the present application are described in further detail, it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present application, and are not intended to limit the scope of the present application, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present application should be included in the scope of the present application.