Disclosure of Invention
In view of the above, the present invention is proposed to provide a method and apparatus for dynamic configuration of test case parameters that overcomes or at least partially solves the above problems.
According to an aspect of the present invention, a method for dynamically configuring test case parameters is provided, including:
acquiring test case parameters from a plurality of XML files which are described with the test case parameters in advance;
parameter sets are constructed based on the obtained test case parameters, and the constructed parameter sets are stored in the preset parameter set list, wherein one parameter set is constructed by the test case parameters corresponding to one test case;
receiving a target test case selected by a user, and searching a parameter set corresponding to the target test case from the preset parameter set list;
dynamically generating a corresponding parameter configuration interface according to the searched parameters in the parameter set, and receiving reconfiguration of the parameters of the target test case through the parameter configuration interface;
and updating the content in the XML file corresponding to the target test case based on the reconfigured parameters.
Optionally, each parameter set identifier in the preset parameter set list has a unique identifier of a corresponding test case, and the receiving a target test case selected by a user and searching a parameter set corresponding to the target test case from the preset parameter set list includes:
receiving a target test case selected by a user, and acquiring a unique identifier of the target test case;
and searching a parameter set corresponding to the unique identifier of the target test case from a preset parameter set list.
Optionally, before obtaining the test case parameters from the plurality of XML files in which the test case parameters are described in advance, the method further includes: and loading a plurality of XML files which are described with test case parameters in advance.
Optionally, loading a plurality of XML files in which test case parameters are described in advance includes:
searching a TestScript folder under a test program directory, and traversing different test scene folders from a next-level directory of the TestScript folder, wherein the test scene folders store the XML files in advance;
and loading XML files corresponding to different test cases from each test scene folder.
Optionally, the parameters in the parameter set include a display sequence, and the dynamically generating a corresponding parameter configuration interface according to the found parameters in the parameter set includes:
and according to the display sequence, displaying the parameter configuration control corresponding to each test case parameter in the searched parameter set in the display control, and dynamically generating a corresponding parameter configuration interface based on the displayed parameter configuration control.
Optionally, updating the content in the XML file corresponding to the target test case based on the reconfigured parameter includes:
updating the parameter set corresponding to the target test case in the preset parameter set list by using the reconfigured parameters;
and updating the content in the corresponding XML file according to the updated parameter set corresponding to the target test case.
Optionally, the method further comprises: and testing the program to be tested by the target test case with the reconfigured parameters through the test case execution tool.
Optionally, the testing the program to be tested by the target test case with the reconfigured parameters through the test case execution tool includes:
matching a predefined test case encoder corresponding to the target test case with the reconfigured parameters through a test case execution tool;
reading the test case parameters in the updated XML file corresponding to the target test case, and encoding the read test case parameters by using a successfully matched test case encoder according to a preset protocol to generate protocol data;
and sending the protocol data to a program to be tested, and testing the program to be tested.
Optionally, matching, by the target test case with the reconfigured parameters, a predefined test case encoder corresponding to the target test case through the test case execution tool includes:
calling a corresponding test function by the target test case with the reconfigured parameters through the test case execution tool, wherein a test template is defined in the form parameters of the test function;
and acquiring a corresponding test template based on the called test function, and matching a predefined test case encoder according to the type of the test template.
According to another aspect of the present invention, there is also provided a test case parameter dynamic configuration apparatus, including:
the acquisition module is suitable for acquiring the test case parameters from a plurality of XML files which are described with the test case parameters in advance;
the construction module is suitable for constructing parameter sets based on the acquired test case parameters and storing the constructed parameter sets into the preset parameter set list, wherein one parameter set is constructed by the test case parameters corresponding to one test case;
the receiving module is suitable for receiving a target test case selected by a user and searching a parameter set corresponding to the target test case from the preset parameter set list;
the generating module is suitable for dynamically generating a corresponding parameter configuration interface according to the searched parameters in the parameter set, and receiving the reconfiguration of the parameters of the target test case through the parameter configuration interface;
and the updating module is suitable for updating the content in the XML file corresponding to the target test case based on the reconfigured parameters.
In the embodiment of the invention, the parameter set is constructed based on the obtained test case parameters by obtaining the test case parameters from a plurality of XML files which are described with the test case parameters in advance, and the constructed parameter set is stored in the preset parameter set list, so that the parameter set corresponding to the target test case can be directly searched from the preset parameter set list after the target test case selected by a user is received. And then, dynamically generating a corresponding parameter configuration interface according to the searched parameters in the parameter set corresponding to the target test case. The user can reconfigure the parameters of the target test case through the parameter configuration interface, and further update the content in the XML file corresponding to the target test case based on the reconfigured parameters. Therefore, the embodiment of the invention describes the parameters of the test case based on the XML file and generates the corresponding parameter configuration interface according to the parameters of the test case, so that the parameters of the test case can be directly adjusted through the parameter configuration interface, and the contents in the XML file, such as the addition, modification, deletion and the like of the parameters, are modified based on the adjusted parameters of the test case.
Furthermore, the parameter set is stored in the preset parameter set list, and when the test case parameters or the parameter set are used subsequently, the parameter set can be directly obtained from the preset parameter set list without traversing the content in each XML file, so that the obtaining efficiency of the test case parameters can be improved.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments thereof, taken in conjunction with the accompanying drawings.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
In order to solve the above technical problem, an embodiment of the present invention provides a method for dynamically configuring test case parameters, where the method may be applied to a test case based on TTCN3 language to perform a dynamic configuration process of test case parameters. FIG. 1 is a flowchart illustrating a method for dynamically configuring test case parameters according to an embodiment of the present invention. Referring to fig. 1, the method includes at least steps S102 to S110.
Step S102, obtaining the test case parameters from a plurality of XML files described with the test case parameters in advance.
The step describes the test parameters based on the XML file, and the adjustment of the parameters of the test case can be conveniently realized by modifying the nodes in the XML file in the subsequent process.
And step S104, constructing parameter sets based on the acquired test case parameters, and storing the constructed parameter sets into a preset parameter set list, wherein one parameter set is constructed by the test case parameters corresponding to one test case.
And step S106, receiving the target test case selected by the user, and searching a parameter set corresponding to the target test case from the preset parameter set list.
In this step, each parameter set identifier in the preset parameter set list has a unique identifier of a corresponding test case, and when a parameter set corresponding to a target test case is searched from the preset parameter set list, the unique identifier of the target test case may be obtained first, and then the parameter set corresponding to the unique identifier of the target test case is searched from the preset parameter set list.
Step S108, dynamically generating a corresponding parameter configuration interface according to the searched parameters in the parameter set, and receiving the reconfiguration of the parameters of the target test case through the parameter configuration interface.
In this step, the reconfiguration of the target test case parameters may include configuration operations such as addition, deletion, modification, and the like of the parameters.
Step S110, updating the content in the XML file corresponding to the target test case based on the reconfigured parameters.
In this step, when the content in the XML file corresponding to the target test case is updated based on the reconfigured parameters, the parameter set corresponding to the target test case in the preset parameter set list may be updated first by using the reconfigured parameters, and then the content in the corresponding XML file is updated according to the updated parameter set corresponding to the target test case.
The embodiment of the invention describes the parameters of the test case based on the XML file and generates the corresponding parameter configuration interface according to the parameters of the test case, so that the parameters of the test case can be directly adjusted through the parameter configuration interface, the contents in the XML file are modified based on the adjusted parameters of the test case, such as the addition, modification, deletion and the like of the parameters, the process does not need to modify the codes in the test program at all, the parameter adjustment process is simple and convenient, the adjustment speed of the parameters of the test case is improved, the multiplexing of the parameters of the test case can be supported, and the invention has extremely high flexibility and expansibility. Furthermore, the parameter set is stored in the preset parameter set list, and when the test case parameters or the parameter set are used subsequently, the parameter set can be directly obtained from the preset parameter set list without traversing the content in each XML file, so that the obtaining efficiency of the test case parameters can be improved.
Referring to step S102, in an embodiment of the present invention, when obtaining the test case parameters from the multiple XML files in which the test case parameters are described in advance, the multiple XML files in which the test case parameters are described in advance need to be loaded first, and then the test case parameters are obtained from the loaded XML files. Referring to fig. 2, the following describes a process of loading a plurality of XML files with test case parameters described in advance and obtaining the test case parameters.
And S202, searching a TestScript folder in the test program directory. The test program is the currently executing program.
And step S204, traversing different test scene folders from the next-level directory of the TestScript folder, wherein XML files with test case parameters described in advance are stored in the test scene folders.
And S206, sequentially reading XML files corresponding to different test cases in the test scene folder.
The scheme can read XML configuration files in different test scenes, so that a test program in test software developed based on the scheme can support the test of a multi-scene test mode.
And S208, verifying the format of the read XML file, and judging whether the verification is successful, if so, executing the step S210, and if not, executing the step S206.
In this step, the verification information content for verifying the format of the XML file is set in advance in the XML file. The verification information may include verification information regarding the type, scope, etc. of the test case parameters in the XML file.
And step S210, obtaining the parameters of the test case from the read XML file.
Step S212, determining whether reading of all XML files in different test scene folders is completed, if yes, ending, and if not, executing step S206.
In conjunction with step S104, it has been described above that the test case parameters corresponding to one test case construct one parameter set. In this embodiment, the process of obtaining the test case parameters from the read XML file, constructing the parameter set based on the obtained test case parameters, and storing the parameter set in the preset parameter set list may be as follows: and sequentially and circularly traversing all nodes in the XML file, storing the attribute in each line of nodes in the XML file into a corresponding parameter set structure, and then inserting the parameter set structure into a predefined parameter set list.
The XML file of the embodiment of the invention can adopt a tree-shaped layered structure form, and the beginning of the file is provided with a file description statement for describing the version number and the coding mode of the file. The following is a root node params parameter set, the root node is followed by a param parameter child node, the param has 14 attributes, including id unique identifier, order display order, name parameter name, title parameter display title, value parameter value, select value selection value, defaultValue default value, unit, type control type, enable is operable or not, visible is not displayed, min minimum value, max maximum value, hit prompt information. The type control type comprises an input box, a select pull-down list box and a table pop-up table, and is used for providing different types of display modes. The XML file is adopted to construct the configuration parameters of the test case, the separation of the parameters and the program can be effectively realized, and only the content in the XML file needs to be modified when the parameters of the test case are modified, and the program code does not need to be modified.
An embodiment of the present invention provides a partial content of an XML file, as follows:
referring to step S106 above, in an embodiment of the present invention, when the corresponding parameter configuration interface is dynamically generated according to the searched parameters in the parameter set, the parameter configuration control corresponding to each test case parameter may be displayed in a display control (e.g., a Grid control) according to an order display sequence in the parameter set, where the parameter configuration control is used to configure the corresponding test case parameter, so as to dynamically generate the corresponding parameter configuration interface based on the displayed parameter configuration control. The dynamic generation of the parameter configuration interface by using the parameters in the parameter set is also an initialization process for the display control, such as initializing the contents of the title, the display sequence, the type, the default value and the like of the display control according to the parameters of the test case.
In this embodiment, the preset parameter set list may also include some default parameters that the user cannot modify. Therefore, it is also necessary to determine whether the default parameter contains a visible that displays "true" or does not display "false" by traversing each parameter set in the preset parameter set list.
If the visual is "false", it is skipped directly and the visual of the next parameter set is looked up until the last parameter set in the parameter set list is preset. If the visual is "true", a line is dynamically inserted into the GRID (display control), wherein the first column is a hidden id value, the second column is a title of title, the third column is a value field of the parameter, and the fourth column is a unit value. The value field control is initialized according to the type value, tpye is an input box with an "input" control as a default, tpye is a "select" control for dynamically creating a drop-down list box, tpye is a "table" control for an insert button, and for example, if tpye is a "select", a drop-down list option can be filled with a value of select value.
Furthermore, it is also possible to read "value" to fill the value field of the parameter, "enable" is read, and if "enable" is read as "false", the value field after filling the parameter will be set as not modifiable.
In an embodiment of the present invention, after the content in the XML file corresponding to the target test case is updated based on the reconfigured parameters, the target test case with the reconfigured parameters may be used to test the program to be tested through the test case execution tool. The specific test process is as follows:
first, the target test case with the reconfigured parameters is matched with the corresponding predetermined test case encoder through the test case execution tool.
And then, reading the test case parameters in the updated XML file corresponding to the target test case, and encoding the read test case parameters by using a successfully matched test case encoder according to a preset protocol to generate protocol data.
And finally, sending the protocol data to the program to be tested, and testing the program to be tested.
In this embodiment, when the target test case with the reconfigured parameters is matched with the predefined test case encoder corresponding to the target test case through the test case execution tool, the corresponding test function may be called by the target test case with the reconfigured parameters through the test case execution tool, where the form parameters of the test function define the test template. And then acquiring a corresponding test template based on the called test function, and matching a predefined test case encoder according to the type of the test template.
In order to more clearly embody the process of testing the program under test by using the test case after reconfiguring the parameters, an embodiment of the invention is described in detail below. For example, the target test case is a test case designed based on TTCN, and the TTCN test case mentioned herein refers to a test case after the parameters are reconfigured.
Firstly, a user clicks to start executing a test program, and a TTCN test case is started.
And step two, the TTCN test case calls a corresponding test function, a template is defined in the form parameter of the function, and a predefined coder is matched according to the template type.
And thirdly, acquiring the ID of the test case, and searching the corresponding updated XML file from different scene folders according to the ID of the test case. The XML file not only describes the parameters of the test case, but also includes ID identifiers for identifying which parameters of the test case are.
And fourthly, traversing the parameters of each node in the XML file, and putting the parameter name and the parameter value into the dictionary.
And fifthly, reading the content in the dictionary, and encoding the read content by an encoder according to the requirement of a preset protocol format to generate protocol data.
And sixthly, the encoder sends the coded protocol data to the program to be tested so as to test the program to be tested.
And seventhly, receiving the feedback information of the program to be tested, calling the corresponding test function, and matching a predefined decoder according to the template type in the function so as to decode the feedback information.
For example, the feedback information returned includes identification information of test failure, test success, need for retesting, and the like.
The embodiment of the invention can also uniformly convert the reconfigured parameters into dictionary keys/values, such as names/values, can realize the uniformity of interfaces and improve the expansibility and flexibility of software. According to the scheme, the rapid development of the parameter configuration of the test case can be realized without modifying a software program, and the expansibility and the universality of software in the instrument device are improved on the basis of the specialty of the instrument device measured by using a TTCN3 language development protocol. In addition, different XML files are only needed to be configured in different test scenes, the software only has one version, and the unified software version greatly improves the research and development efficiency and the maintenance efficiency of the software in the measuring instrument device.
In addition, if the embodiment of the invention develops the test case based on the TTCN3 language, the test in the aspects of protocol consistency, parallelism, time delay and the like can be supported, and the test process can be supported to be displayed graphically, and the information receiving and sending of each protocol interaction and the judgment in the process can be displayed visually.
Based on the same inventive concept, an embodiment of the present invention further provides a device for dynamically configuring test case parameters, and fig. 3 illustrates a schematic structural diagram of the device for dynamically configuring test case parameters according to an embodiment of the present invention. Referring to fig. 3, the apparatus 400 for dynamically configuring test case parameters at least includes an obtaining module 410, a constructing module 420, a receiving module 430, a generating module 440, and an updating module 450.
The functions of the components or devices of the device 400 and the connection relationships between the components will be described in the embodiment of the present invention based on the test case parameters:
an obtaining module 410, adapted to obtain test case parameters from a plurality of XML files in which the test case parameters are described in advance;
a constructing module 420, coupled to the obtaining module 410, adapted to construct a parameter set based on the obtained test case parameters, and store the constructed parameter set in a preset parameter set list, where a parameter set is constructed for a test case parameter corresponding to one test case;
a receiving module 430, coupled to the constructing module 420, adapted to receive the target test case selected by the user, and search a parameter set corresponding to the target test case from a preset parameter set list;
the generating module 440 is coupled to the receiving module 430, and is adapted to dynamically generate a corresponding parameter configuration interface according to the searched parameters in the parameter set, and receive reconfiguration of the parameters of the target test case through the parameter configuration interface;
the updating module 450, coupled to the generating module 440, is adapted to update the content in the XML file corresponding to the target test case based on the reconfigured parameters.
In an embodiment of the present invention, if each parameter set identifier in the preset parameter set list has a unique identifier of a corresponding test case, the receiving module 430 is further adapted to receive a target test case selected by a user, obtain the unique identifier of the target test case, and search for a parameter set corresponding to the unique identifier of the target test case from the preset parameter set list.
In an embodiment of the present invention, if the parameters in the parameter set include a display sequence, the generating module 440 is further adapted to display the parameter configuration control corresponding to each test case parameter in the display control according to the display sequence of the parameter identifier in the parameter set, and dynamically generate a corresponding parameter configuration interface based on the displayed parameter configuration control.
In an embodiment of the present invention, the updating module 450 is further adapted to update the parameter set corresponding to the target test case in the preset parameter set list by using the reconfigured parameter, and update the content in the corresponding XML file according to the updated parameter set corresponding to the target test case.
In an embodiment of the present invention, referring to fig. 4, the dynamic configuration apparatus 400 for test case parameters may further include a loading module 460 and a testing module 470 in addition to the above modules.
The loading module 460, coupled to the obtaining module 410, is adapted to load the XML files with the test case parameters described in advance before the obtaining module 410 obtains the test case parameters from the XML files with the test case parameters described in advance.
The test module 470, coupled to the update module 450, is adapted to test the program to be tested by the target test case with reconfigured parameters through the test case execution tool.
In an embodiment of the present invention, the loading module 460 is further adapted to search the TestScript folder in the test program directory, traverse different test scenario folders from the next-level directory of the TestScript folder, where XML files are stored in the test scenario folders in advance, and load XML files corresponding to different test cases from each test scenario folder.
In an embodiment of the present invention, the test module 470 is further adapted to match, by the target test case with the reconfigured parameters through the test case execution tool, the predefined test case encoder corresponding to the target test case, read the test case parameters in the updated XML file corresponding to the target test case, encode the read test case parameters according to the preset protocol by using the test case encoder successfully matched, generate protocol data, send the protocol data to the program to be tested, and test the program to be tested.
In an embodiment of the present invention, the test module 470 is further adapted to call a corresponding test function through a test case execution tool by the target test case with reconfigured parameters, where a form parameter of the test function defines a test template, obtain the corresponding test template based on the called test function, and match a predefined test case encoder according to a type of the test template.
According to any one or a combination of the above preferred embodiments, the following advantages can be achieved by the embodiments of the present invention:
in the embodiment of the invention, the parameter set is constructed based on the obtained test case parameters by obtaining the test case parameters from a plurality of XML files which are described with the test case parameters in advance, and the constructed parameter set is stored in the preset parameter set list, so that the parameter set corresponding to the target test case can be directly searched from the preset parameter set list after the target test case selected by a user is received. And then, dynamically generating a corresponding parameter configuration interface according to the searched parameters in the parameter set corresponding to the target test case. The user can reconfigure the parameters of the target test case through the parameter configuration interface, and further update the content in the XML file corresponding to the target test case based on the reconfigured parameters. Therefore, the embodiment of the invention describes the parameters of the test case based on the XML file and generates the corresponding parameter configuration interface according to the parameters of the test case, so that the parameters of the test case can be directly adjusted through the parameter configuration interface, and the contents in the XML file, such as the addition, modification, deletion and the like of the parameters, are modified based on the adjusted parameters of the test case. Furthermore, the parameter set is stored in the preset parameter set list, and when the test case parameters or the parameter set are used subsequently, the parameter set can be directly obtained from the preset parameter set list without traversing the content in each XML file, so that the obtaining efficiency of the test case parameters can be improved.
It is clear to those skilled in the art that the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and for the sake of brevity, further description is omitted here.
In addition, the functional units in the embodiments of the present invention may be physically independent of each other, two or more functional units may be integrated together, or all the functional units may be integrated in one processing unit. The integrated functional units may be implemented in the form of hardware, or in the form of software or firmware.
Those of ordinary skill in the art will understand that: the integrated functional units, if implemented in software and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computing device (e.g., a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention when the instructions are executed. And the aforementioned storage medium includes: u disk, removable hard disk, Read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disk, and other various media capable of storing program code.
Alternatively, all or part of the steps of implementing the foregoing method embodiments may be implemented by hardware (such as a computing device, e.g., a personal computer, a server, or a network device) associated with program instructions, which may be stored in a computer-readable storage medium, and when the program instructions are executed by a processor of the computing device, the computing device executes all or part of the steps of the method according to the embodiments of the present invention.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments can be modified or some or all of the technical features can be equivalently replaced within the spirit and principle of the present invention; such modifications or substitutions do not depart from the scope of the present invention.