Disclosure of Invention
In view of this, an object of the present application is to provide a method, an apparatus, a device, and a medium for testing an interface, which can reduce complexity of testing work, improve code reuse rate, perform a batch test of the interface, and improve testing efficiency. The specific scheme is as follows:
in a first aspect, the present application discloses an interface testing method, including:
modifying an interface automation test frame so that the interface automation test frame reads a parameter file under a preset path when the interface test is carried out;
executing an interface script to be executed based on the parameter file to obtain a return value of the interface script;
and writing the return value to the parameter file.
Optionally, the modifying interface automation test framework includes:
acquiring the preset path;
and writing the preset path into the interface automation test framework.
Optionally, before the executing the interface script to be executed based on the parameter file and obtaining the return value of the interface script, the method further includes:
acquiring the parameter file, wherein the parameter file comprises data corresponding to each interface script to be executed, the data corresponding to each interface script to be executed comprises an interface identifier, an interface URL, a request method, a parameter identifier under the same interface, a test parameter and expected test data, and the parameter identifier under the same interface represents different test parameters corresponding to the same interface;
and storing the parameter file below the preset path.
Optionally, after writing the return value to the parameter file, the method further includes:
comparing the return value with the corresponding expected test data;
and if the return value is inconsistent with the corresponding expected test data, performing failure reason analysis on the inconsistent return value and the corresponding expected test data.
Optionally, the executing the interface script to be executed based on the parameter file to obtain a return value of the interface script includes:
reading corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed;
and executing the interface script based on the read test parameters to obtain a return value of the interface script.
Optionally, the reading out the corresponding test parameter from the parameter file according to the interface identifier of the interface script to be executed includes:
and determining corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed, and reading each determined test parameter one by one according to the parameter identification under the same interface corresponding to each determined test parameter.
Optionally, the parameter file is an excel file, a csv file, or an xml file.
In a second aspect, the present application discloses an interface testing apparatus, comprising:
the frame modification module is used for modifying the interface automation test frame so as to read the parameter file under the preset path when the interface automation test frame carries out interface test;
the script execution module is used for executing the interface script to be executed based on the parameter file to obtain a return value of the interface script;
and the data writing module is used for writing the return value into the parameter file.
In a third aspect, the present application discloses an electronic device, comprising:
a memory and a processor;
wherein the memory is used for storing a computer program;
the processor is configured to execute the computer program to implement the interface testing method disclosed above.
In a fourth aspect, the present application discloses a computer readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the interface testing method disclosed above.
Therefore, according to the method and the device, an interface automatic test framework needs to be modified firstly, so that the interface automatic test framework reads the parameter file under the preset path when the interface test is carried out, then the interface script to be executed can be executed based on the parameter file, the return value of the interface script is obtained, and then the return value is written into the parameter file. Therefore, it can be seen that, this application is modified interface automation test frame earlier, makes interface automation test frame can read the parameter file under the route of predetermineeing when carrying out the interface test, then based on the interface script that the execution was waited to carry out to the parameter file execution alright can obtain the return value of interface script, will again the return value is write to in the parameter file, when modifying the parameter like this, only need modify parameter in the parameter file need not directly modify the interface code when adjusting the parameter, has improved the code rate of reusability, and has reduced the test work complexity, in addition, include the parameter of each interface script of waiting to carry out in the parameter file to carry out interface batch test, improved efficiency of software testing.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Currently, the main automated tests are the traditional testng-framed interface automated tests, or the postman and meter tools are used for interface execution tests. However, the automated test management of the interface using testng as a framework is complex, and once parameters and the like need to be adjusted, codes need to be modified, so that the test work is complex and the code reuse rate is low. And the tools such as postman and the like can not manage interface parameters in batch, so that the testing efficiency is low. In view of this, the present application provides an interface testing method, which can reduce the complexity of testing work, improve the code reuse rate, perform interface batch testing, and improve the testing efficiency.
Referring to fig. 1, an embodiment of the present application discloses an interface testing method, including:
step S11: and modifying the interface automation test frame so that the interface automation test frame can read the parameter file under the preset path when the interface test is carried out.
In a specific implementation process, the interface automation test framework needs to be modified first, so that the interface automation test framework reads a parameter file under a preset path when performing interface test. When an existing interface automatic test framework is used for testing an interface, configuration files corresponding to interface scripts to be executed need to be read, and each interface script to be executed has a configuration file of its own, so that when the interface automatic test framework is tested, the corresponding configuration files need to be read respectively. Thus, when a certain interface script to be executed runs in batch and reads parameters in the parameter file, each interface corresponds to the same interface identifier, and the parameters under the interface identifier are executed line by line.
Specifically, the modifying of the interface automation test framework may first obtain the preset path, and then write the preset path into the interface automation test framework. After the parameter file is set, the parameter file is stored under the preset path. The testng framework can be modified, so that the modified testng framework reads a parameter file under a preset path when an interface test is carried out.
Step S12: and executing the interface script to be executed based on the parameter file to obtain a return value of the interface script.
It can be understood that, after the interface automation test framework is modified, the interface script to be executed needs to be executed based on the parameter file, so as to obtain the return values corresponding to the parameter values of the interface script under the corresponding interface identifiers in the parameter file.
Accordingly, it is necessary to write an interface script to be executed first, where the written interface script needs to satisfy the following functions, including: the parameter information required to be used during testing directly reads data in a parameter file under a preset path, and parameters in a configuration file are not used any more; when all interface scripts to be executed under a specified directory are executed in batches, parameters in the parameter file are used in the execution process; and after the batch execution is finished, the return value is written in a parameter row corresponding to the parameter file in a unified way.
In a specific implementation process, before executing an interface script to be executed based on the parameter file and obtaining a return value of the interface script, the method further includes: acquiring the parameter file, wherein the parameter file includes data corresponding to each interface script to be executed, the data corresponding to each interface script to be executed includes an interface identifier, an interface URL (Uniform Resource Locator), a request method, a parameter identifier under the same interface, a test parameter, and expected test data, and the parameter identifier under the same interface represents different test parameters corresponding to the same interface; and storing the parameter file below the preset path. Wherein, the parameter file is an excel file, a csv file or an xml file.
Referring to fig. 2, a screenshot of a parameter file is shown. There are 4 parameters with interface ID (interface identification) 1, and the corresponding parameter IDs under the same interface are 1 to 4 respectively. There are 1 parameter with interface ID of 2. And writing return values corresponding to all the parameters in a return value column, comparing the return values with expected data, and then judging whether the return values are consistent with the expected data, if not, writing incorrect in the correct column, and if so, writing correct in the correct column.
Executing the interface script to be executed based on the parameter file to obtain a return value of the interface script, wherein the step of executing the interface script to be executed based on the parameter file comprises the following steps: reading corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed; and executing the interface script based on the read test parameters to obtain a return value of the interface script.
Reading out corresponding test parameters from the parameter file according to the interface identifier of the interface script to be executed, wherein the method comprises the following steps: and determining corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed, and reading each determined test parameter one by one according to the parameter identification under the same interface corresponding to each determined test parameter.
Step S13: and writing the return value to the parameter file.
It is understood that after the interface script to be executed is executed, the obtained return value needs to be written into the parameter file.
Therefore, according to the method and the device, an interface automatic test framework needs to be modified firstly, so that the interface automatic test framework reads the parameter file under the preset path when the interface test is carried out, then the interface script to be executed can be executed based on the parameter file, the return value of the interface script is obtained, and then the return value is written into the parameter file. Therefore, it can be seen that, this application is modified interface automation test frame earlier, makes interface automation test frame can read the parameter file under the route of predetermineeing when carrying out the interface test, then based on the interface script that the execution was waited to carry out to the parameter file execution alright can obtain the return value of interface script, will again the return value is write to in the parameter file, when modifying the parameter like this, only need modify parameter in the parameter file need not directly modify the interface code when adjusting the parameter, has improved the code rate of reusability, and has reduced the test work complexity, in addition, include the parameter of each interface script of waiting to carry out in the parameter file to carry out interface batch test, improved efficiency of software testing.
Referring to fig. 3, an embodiment of the present application discloses a specific interface testing method, which includes:
step S21: and modifying the interface automation test frame so that the interface automation test frame can read the parameter file under the preset path when the interface test is carried out.
Step S22: and executing the interface script to be executed based on the parameter file to obtain a return value of the interface script.
Step S23: and writing the return value to the parameter file.
The specific implementation process ofstep 21 to step S22 can refer to the content disclosed in the foregoing embodiments, and will not be described in detail herein.
Step S24: and comparing the return value with the corresponding expected test data.
Step S25: and if the return value is inconsistent with the corresponding expected test data, performing failure reason analysis on the inconsistent return value and the corresponding expected test data.
After the return value is written into the parameter file, the return value is required to be compared with the corresponding expected test data; and if the return value is inconsistent with the corresponding expected test data, performing failure reason analysis on the inconsistent return value and the corresponding expected test data.
That is, after the return value is written into the parameter file, the return value and the expected test data need to be compared, if the return value is inconsistent with the corresponding expected test data, it indicates that the corresponding test is incorrect, and the corresponding reason needs to be analyzed, so that the inconsistent return value and the corresponding expected test data need to be subjected to failure reason analysis, so as to perform improved processing on the corresponding interface script.
Referring to fig. 4, a flow chart of an interface testing method is shown. Firstly, the interface automation test framework is modified, and the interface automation is compiled, namely the interface script to be executed is compiled. And preparing test data in the excel, reading the data in the excel, executing corresponding interface scripts in batches, writing back a return value to the excel, exporting the data in the excel, and comparing and analyzing the return value and expected test data.
Referring to fig. 5, an embodiment of the present application discloses an interface testing apparatus, including:
theframe modification module 11 is configured to modify an interface automation test frame, so that the interface automation test frame reads a parameter file in a preset path when performing an interface test;
thescript execution module 12 is configured to execute the interface script to be executed based on the parameter file to obtain a return value of the interface script;
and adata writing module 13, configured to write the return value to the parameter file.
Therefore, according to the method and the device, an interface automatic test framework needs to be modified firstly, so that the interface automatic test framework reads the parameter file under the preset path when the interface test is carried out, then the interface script to be executed can be executed based on the parameter file, the return value of the interface script is obtained, and then the return value is written into the parameter file. Therefore, it can be seen that, this application is modified interface automation test frame earlier, makes interface automation test frame can read the parameter file under the route of predetermineeing when carrying out the interface test, then based on the interface script that the execution was waited to carry out to the parameter file execution alright can obtain the return value of interface script, will again the return value is write to in the parameter file, when modifying the parameter like this, only need modify parameter in the parameter file need not directly modify the interface code when adjusting the parameter, has improved the code rate of reusability, and has reduced the test work complexity, in addition, include the parameter of each interface script of waiting to carry out in the parameter file to carry out interface batch test, improved efficiency of software testing.
In some specific embodiments, theframework modification module 11 is configured to obtain the preset path; and writing the preset path into the interface automation test framework.
In some specific embodiments, the interface testing apparatus further includes:
a parameter setting module for: acquiring the parameter file, wherein the parameter file comprises data corresponding to each interface script to be executed, the data corresponding to each interface script to be executed comprises an interface identifier, an interface URL, a request method, a parameter identifier under the same interface, a test parameter and expected test data, and the parameter identifier under the same interface represents different test parameters corresponding to the same interface; and storing the parameter file below the preset path.
In some specific embodiments, the interface testing apparatus further includes:
the data analysis module is used for comparing the return value with the corresponding expected test data; and if the return value is inconsistent with the corresponding expected test data, performing failure reason analysis on the inconsistent return value and the corresponding expected test data.
In some specific embodiments, thescript execution module 12 is configured to: reading corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed; and executing the interface script based on the read test parameters to obtain a return value of the interface script.
In some specific embodiments, thescript execution module 12 is configured to: and determining corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed, and reading each determined test parameter one by one according to the parameter identification under the same interface corresponding to each determined test parameter.
In some specific embodiments, the parameter file is an excel file, a csv file, or an xml file.
Further, referring to fig. 6, an embodiment of the present application further discloses an electronic device, including: aprocessor 21 and amemory 22.
Wherein thememory 22 is used for storing a computer program; theprocessor 21 is configured to execute the computer program to implement the interface testing method disclosed in the foregoing embodiment.
For the specific process of the interface testing method, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not repeated here.
Further, an embodiment of the present application also discloses a computer readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the following steps:
modifying an interface automation test frame so that the interface automation test frame reads a parameter file under a preset path when the interface test is carried out; executing an interface script to be executed based on the parameter file to obtain a return value of the interface script; and writing the return value to the parameter file.
Therefore, according to the method and the device, an interface automatic test framework needs to be modified firstly, so that the interface automatic test framework reads the parameter file under the preset path when the interface test is carried out, then the interface script to be executed can be executed based on the parameter file, the return value of the interface script is obtained, and then the return value is written into the parameter file. Therefore, it can be seen that, this application is modified interface automation test frame earlier, makes interface automation test frame can read the parameter file under the route of predetermineeing when carrying out the interface test, then based on the interface script that the execution was waited to carry out to the parameter file execution alright can obtain the return value of interface script, will again the return value is write to in the parameter file, when modifying the parameter like this, only need modify parameter in the parameter file need not directly modify the interface code when adjusting the parameter, has improved the code rate of reusability, and has reduced the test work complexity, in addition, include the parameter of each interface script of waiting to carry out in the parameter file to carry out interface batch test, improved efficiency of software testing.
In this embodiment, when the computer subprogram stored in the computer-readable storage medium is executed by the processor, the following steps may be specifically implemented: acquiring the preset path; and writing the preset path into the interface automation test framework.
In this embodiment, when the computer subprogram stored in the computer-readable storage medium is executed by the processor, the following steps may be specifically implemented: acquiring the parameter file, wherein the parameter file comprises data corresponding to each interface script to be executed, the data corresponding to each interface script to be executed comprises an interface identifier, an interface URL, a request method, a parameter identifier under the same interface, a test parameter and expected test data, and the parameter identifier under the same interface represents different test parameters corresponding to the same interface; storing the parameter file under the preset path
In this embodiment, when the computer subprogram stored in the computer-readable storage medium is executed by the processor, the following steps may be specifically implemented: comparing the return value with the corresponding expected test data; and if the return value is inconsistent with the corresponding expected test data, performing failure reason analysis on the inconsistent return value and the corresponding expected test data.
In this embodiment, when the computer subprogram stored in the computer-readable storage medium is executed by the processor, the following steps may be specifically implemented: reading corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed; and executing the interface script based on the read test parameters to obtain a return value of the interface script.
In this embodiment, when the computer subprogram stored in the computer-readable storage medium is executed by the processor, the following steps may be specifically implemented: and determining corresponding test parameters from the parameter file according to the interface identification of the interface script to be executed, and reading each determined test parameter one by one according to the parameter identification under the same interface corresponding to each determined test parameter.
In this embodiment, when the computer subprogram stored in the computer-readable storage medium is executed by the processor, the parameter file is an excel file, a csv file, or an xml file.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in 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.
Finally, it is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of other elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The interface testing method, device, equipment and medium provided by the application are introduced in detail, specific examples are applied in the description to explain the principle and the implementation of the application, and the description of the above embodiments is only used to help understand the method and the core idea of the application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.