Test method and device
Technical Field
The embodiment of the invention belongs to the field of software testing, and particularly relates to a testing method and a testing device.
Background
At present, data extraction interfaces are needed for testing of a plurality of terminal products, the interfaces involved in different projects are different, and the calling modes of different interfaces are also different. In the prior art, a project group developer compiles an interface to call a test tool, runs the test tool, and stores data returned by the interface in a file for the analysis of the tester. The tester analyzes and compares the received data in the file with an expected result, and judges whether the data are in accordance with the expectation.
In the prior art, on one hand, a test tool does not have a unified design specification and a unified framework, and the test tool is developed by different project groups, so that the reliability problem exists in the tool, and the test cost is additionally increased. On the other hand, automatic testing is not realized, and a manual testing method is adopted, so that the period is long, the coverage rate of testing data is low, and the testing efficiency and the accuracy rate of testing results are low.
Therefore, a new technical solution is needed to solve the above technical problems.
Disclosure of Invention
In view of this, the embodiments of the present invention provide a testing method and apparatus, which aim to solve the problem that the existing testing tools are not unified and do not implement automated testing, so that the testing efficiency and the accuracy of the testing result are low.
The embodiment of the invention is realized in such a way that a test method comprises the following steps:
starting an interface calling tool to obtain the serial number and the parameters of the interface to be tested;
calling a pre-established test case library based on the serial number of the interface to be tested to obtain a corresponding test case configuration file, wherein the test case library comprises the test case configuration file and expected result data;
calling an interface corresponding to the interface number to be tested to run the test case configuration file based on the interface parameter to be tested, and acquiring return result data;
and outputting and displaying a test result based on the expected result data and the return result data.
Another object of an embodiment of the present invention is to provide a testing apparatus, including:
the device comprises a to-be-tested interface information acquisition unit, a to-be-tested interface calling tool and a to-be-tested interface calling module, wherein the to-be-tested interface information acquisition unit is used for starting the interface calling tool and acquiring the serial number and the parameters of the to-be-tested interface of the to-be-;
a test case configuration file obtaining unit, configured to call a pre-established test case library based on the serial number of the interface to be tested, and obtain a corresponding test case configuration file, where the test case library includes the test case configuration file and expected result data;
a returned result data obtaining unit, configured to call, based on the parameter of the interface to be tested, an interface corresponding to the serial number of the interface to be tested to run the test case configuration file, and obtain returned result data;
and the result display unit is used for outputting and displaying the test result based on the expected result data and the return result data.
In the embodiment of the invention, the interface test integration and automatic test are realized by acquiring the interface number and the interface parameter of the interface to be tested, calling the pre-established test case library based on the interface number to be tested to acquire the corresponding test case configuration file, wherein the test case library comprises the test case configuration file and the expected result data, starting an interface calling tool, calling the interface corresponding to the interface number to be tested to operate the test case configuration file based on the interface parameter to be tested, acquiring the return result data, and outputting and displaying the test result based on the expected result data and the return result data, thereby improving the test efficiency and accuracy.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
FIG. 1 is a flow chart of a testing method according to a first embodiment of the present invention;
fig. 2 is a structural diagram of a testing apparatus according to a second embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to a determination" or "in response to a detection". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
In order to explain the technical means of the present invention, the following description will be given by way of specific examples.
The first embodiment is as follows:
fig. 1 shows a flowchart of a testing method provided in a first embodiment of the present invention, which is detailed as follows:
and step S11, acquiring the serial number and the parameters of the interface to be tested.
The interface to be tested is an interface to be tested.
Optionally, before the step S11, to improve the test efficiency and the test accuracy, the method includes:
a1, obtaining the interface type of the appointed interface, wherein the appointed interface comprises the interface to be tested. Wherein the interface types include, but are not limited to, c/c + + dynamic libraries and webAPIs.
A2, numbering the appointed interface based on the interface type, and generating the interface number. And the interface number comprises the number of the interface to be tested.
And A3, acquiring the interface parameters of the specified interface. And the interface parameters comprise the interface parameters to be tested.
And A4, acquiring the test environment information of the specified interface. And the test environment information comprises the test environment information of the interface to be tested.
And A5, acquiring an expected test result rule of the specified interface. Wherein the expected test result rule comprises an expected test result rule of the interface to be tested.
A6, setting a test case configuration file based on the interface number, the interface parameters and the test environment information.
And A7, generating expected test result data based on the expected test result rule and the test case configuration file.
And A8, establishing a test case library based on the test case configuration file and the expected test result data.
Specifically, the interface type of the designated interface is obtained, where the designated interface may include all interfaces, may only include the interface to be tested, and may also include the interface to be tested and some interfaces in all interfaces. And numbering the designated interface according to the interface type to generate an interface number, wherein the interface number comprises the serial number of the interface to be tested. And setting a test case configuration file based on the interface number, the interface parameters and the test environment information. That is, test case configuration files of different types of interfaces are preset, and the interface numbers correspond to the test case configuration files one to one. And generating and storing expected test result data based on the expected test result rule and the test case configuration file, wherein the expected test result data also corresponds to the interface numbers one by one. And finally, establishing a test case library based on the test case configuration file and the expected test result data. Therefore, the corresponding test case configuration file can be searched and called through the interface number, and the test efficiency is improved.
The test case configuration file is set based on the interface number, the interface parameters and the test environment information, expected test result data are generated based on the expected test result rule and the test case configuration file, and finally a test case library is established based on the test case configuration file and the expected test result data, so that a tester can call the test case configuration file according to the interface number and obtain the expected test result data conveniently, and the test efficiency is improved.
Optionally, before the step S11, to improve the testing efficiency, the method includes:
and B1, acquiring the calling mode of the interface to be tested.
And B2, modifying an interface calling tool based on the calling mode, the serial number of the interface to be tested and the parameters of the interface to be tested.
Specifically, before a calling tool is started, the serial number of the interface to be tested and the parameters of the interface to be tested are input into the calling tool. Meanwhile, the calling modes of different types of interfaces are different, so that the calling mode is added into the interface calling tool by acquiring the calling mode of the interface to be tested. Optionally, the calling mode of the interface to be tested may use the serial number of the interface to be tested as an identifier.
And step S12, calling a pre-established test case library based on the serial number of the interface to be tested to obtain a corresponding test case configuration file, wherein the test case library comprises the test case configuration file and expected result data.
Specifically, based on the serial number of the interface to be tested, a pre-established test case library is called, and a test case configuration file corresponding to the serial number of the interface to be tested is obtained, so that the operation is simple, and the test efficiency is high.
Step S13, starting an interface calling tool, calling an interface corresponding to the interface number to be tested to run the test case configuration file based on the interface parameter to be tested, and acquiring return result data.
Optionally, in order to refine the test result, after the step S13, the method further includes:
c1, acquiring a format setting command;
c2, generating a test report based on the expected result data, the return result data and the format setting command.
Specifically, after a format setting command is obtained, the format of a test report is set according to the format setting command, and a test report is generated and output for a tester to refer to based on the expected result number and the returned result data.
And step S14, outputting and displaying the test result based on the expected result data and the return result data.
Optionally, the step S14 specifically includes:
d1, comparing the expected result data with the return result data.
D2, if the expected result data is consistent with the return result data, outputting a pass.
D3, if the expected result data is not consistent with the return result data, the output is failed.
Optionally, in order to make the testing personnel more clearly understand the testing result, if the expected result data is inconsistent with the returned result data, the step S14 further includes:
d4, marking the part of the expected result data inconsistent with the returned result data. The marking method includes common marking methods such as color marking and underline marking, which are not limited herein.
Optionally, in order to record the test process for the reference of the tester, in the embodiment of the present invention, the test operation process may be recorded by a log.
In the first embodiment of the present invention, an interface number is generated by obtaining an interface type of a designated interface, numbering the designated interface based on the interface type, wherein the interface number includes an interface number to be tested, obtaining an interface parameter, test environment information, and an expected test result rule of the designated interface, setting a test case configuration file based on the interface number, the interface parameter, and the test environment information, generating expected test result data based on the expected test result rule and the test case configuration file, pre-establishing a test case library based on the test case configuration file and the expected test result data, and calling the pre-established test case library to obtain a corresponding test case configuration file based on the interface number to be tested by obtaining the interface number and the interface parameter of the interface to be tested, the test case library comprises a test case configuration file and expected result data, an interface calling tool is started, an interface corresponding to the serial number of the interface to be tested is called to operate the test case configuration file based on the parameters of the interface to be tested, return result data is obtained, and finally a test result is output and displayed based on the expected result data and the return result data, so that the integration and automatic test of interface test are realized, and the test efficiency and accuracy are improved.
It should be understood that, in the embodiment of the present invention, the sequence numbers of the above-mentioned processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiment of the present invention.
Example two:
fig. 2 is a block diagram of a test apparatus according to a second embodiment of the present invention, in which only the parts related to the embodiment of the present invention are shown for convenience of explanation.
The test device includes: the device comprises an interface information acquisition unit to be tested 21, a test case configuration file acquisition unit 22, a return result data acquisition unit 23 and a result display unit 24, wherein:
the interface information acquiring unit to be tested 21 is configured to start an interface calling tool, and acquire the serial number of the interface to be tested and the parameters of the interface to be tested.
Optionally, in order to improve the testing efficiency and the testing accuracy, the testing apparatus further includes:
and the appointed interface type acquisition unit is used for acquiring the interface type of the appointed interface, and the appointed interface comprises the interface to be tested. Wherein the interface types include, but are not limited to, c/c + + dynamic libraries and webAPIs.
And the specified interface number acquisition unit is used for generating an interface number for the specified interface number based on the interface type. And the interface number comprises the number of the interface to be tested.
And the appointed interface parameter acquisition unit is used for acquiring the interface parameters of the appointed interface. And the interface parameters comprise the interface parameters to be tested.
And the appointed interface environment information acquisition unit is used for acquiring the test environment information of the appointed interface, wherein the test environment information comprises the test environment information of the interface to be tested.
And the specified interface rule obtaining unit is used for obtaining the expected test result rule of the specified interface. Wherein the expected test result rule comprises an expected test result rule of the interface to be tested.
And the setting unit is used for setting a test case configuration file based on the interface number, the interface parameters and the test environment information.
And the result generating unit is used for generating expected test result data based on the expected test result rule and the test case configuration file.
And the case base establishing unit is used for establishing a test case base based on the test case configuration file and the expected test result data.
Specifically, the interface type of the designated interface is obtained, where the designated interface may include all interfaces, may only include the interface to be tested, and may also include the interface to be tested and some interfaces in all interfaces. And numbering the designated interface according to the interface type to generate an interface number, wherein the interface number comprises the serial number of the interface to be tested. And setting a test case configuration file based on the interface number, the interface parameters and the test environment information. That is, test case configuration files of different types of interfaces are preset, and the interface numbers correspond to the test case configuration files one to one. And generating and storing expected test result data based on the expected test result rule and the test case configuration file, wherein the expected test result data also corresponds to the interface numbers one by one. And finally, establishing a test case library based on the test case configuration file and the expected test result data. Therefore, the corresponding test case configuration file can be searched and called through the interface number, and the test efficiency is improved.
The test case configuration file is set based on the interface number, the interface parameters and the test environment information, expected test result data are generated based on the expected test result rule and the test case configuration file, and finally a test case library is established based on the test case configuration file and the expected test result data, so that a tester can call the test case configuration file according to the interface number and obtain the expected test result data conveniently, and the test efficiency is improved.
Optionally, in order to improve the testing efficiency, the testing apparatus further includes:
and the calling mode acquiring unit is used for acquiring the calling mode of the interface to be tested.
And the modifying unit is used for modifying the interface calling tool based on the calling mode, the serial number of the interface to be tested and the parameter of the interface to be tested.
Specifically, before a calling tool is started, the serial number of the interface to be tested and the parameters of the interface to be tested are input into the calling tool. Meanwhile, the calling modes of different types of interfaces are different, so that the calling mode is added into the interface calling tool by acquiring the calling mode of the interface to be tested. Optionally, the calling mode of the interface to be tested may use the serial number of the interface to be tested as an identifier.
The test case configuration file obtaining unit 22 is configured to call a pre-established test case library based on the serial number of the interface to be tested, and obtain a corresponding test case configuration file, where the test case library includes the test case configuration file and expected result data.
Specifically, based on the serial number of the interface to be tested, a pre-established test case library is called, and a test case configuration file corresponding to the serial number of the interface to be tested is obtained, so that the operation is simple, and the test efficiency is high.
And the return result data obtaining unit 23 is configured to call an interface corresponding to the interface number to be tested to run the test case configuration file based on the interface parameter to be tested, and obtain return result data.
And a result display unit 24 for outputting and displaying the test result based on the expected result data and the return result data.
Optionally, the result display unit 24 specifically includes:
a comparison module for comparing the expected result data with the returned result data.
And the pass output module is used for outputting pass if the expected result data is consistent with the returned result data.
And the failure output module is used for outputting failure if the expected result data is inconsistent with the returned result data.
Optionally, in order to make the testing personnel more clearly understand the testing result, if the expected result data is inconsistent with the returned result data, the result displaying unit 24 further includes:
and the marking unit is used for marking the part of the expected result data inconsistent with the returned result data. The marking method includes common marking methods such as color marking and underline marking, which are not limited herein.
Optionally, in order to refine the test result, the apparatus further comprises:
and the format acquisition unit is used for acquiring the format setting command.
And the report generating unit is used for generating a test report based on the expected result data, the return result data and the format setting command.
Specifically, after a format setting command is obtained, the format of a test report is set according to the format setting command, and a test report is generated and output for a tester to refer to based on the expected result number and the returned result data.
Optionally, in order to record the testing process for the reference of the tester, the testing apparatus further includes:
and the recording unit is used for recording the test operation process through the log.
In the second embodiment of the present invention, an interface number is generated by obtaining an interface type of a designated interface, numbering the designated interface based on the interface type, wherein the interface number includes a serial number of an interface to be tested, obtaining interface parameters, test environment information, and expected test result rules of the designated interface, setting a test case configuration file based on the interface number, the interface parameters, and the test environment information, generating expected test result data based on the expected test result rules and the test case configuration file, pre-establishing a test case library based on the test case configuration file and the expected test result data, and calling the pre-established test case library to obtain a corresponding test case configuration file based on the serial number of the interface to be tested by obtaining the interface number and the interface parameters of the interface to be tested, the test case library comprises a test case configuration file and expected result data, an interface calling tool is started, an interface corresponding to the serial number of the interface to be tested is called to operate the test case configuration file based on the parameters of the interface to be tested, return result data is obtained, and finally a test result is output and displayed based on the expected result data and the return result data, so that the integration and automatic test of interface test are realized, and the test efficiency and accuracy are improved.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. 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 invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units 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 computer device (which may be 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. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.