CN112416802A - Python language-based interface test method and device and storage medium - Google Patents

Python language-based interface test method and device and storage medium Download PDF

Info

Publication number
CN112416802A
CN112416802A CN202011424580.9A CN202011424580A CN112416802A CN 112416802 A CN112416802 A CN 112416802A CN 202011424580 A CN202011424580 A CN 202011424580A CN 112416802 A CN112416802 A CN 112416802A
Authority
CN
China
Prior art keywords
file
json
test
interface
python language
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011424580.9A
Other languages
Chinese (zh)
Inventor
尹杰
万振华
王颉
李华
董燕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Kaiyuan Internet Security Technology Co Ltd
Original Assignee
Shenzhen Kaiyuan Internet Security Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Kaiyuan Internet Security Technology Co Ltd filed Critical Shenzhen Kaiyuan Internet Security Technology Co Ltd
Priority to CN202011424580.9A priority Critical patent/CN112416802A/en
Publication of CN112416802A publication Critical patent/CN112416802A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Abstract

The invention provides an interface test method, an interface test device and a storage medium based on a Python language, wherein the interface test method based on the Python language comprises the following steps: acquiring Json files which are test case files, wherein each Json file corresponds to a certain interface or a test scene; compiling an execution file based on a Python language and a Json file, wherein the format of data in the execution file is a Json format; and executing the Json file according to the execution file to obtain a test report. The execution file is compiled based on Python language and Json format, the compiling difficulty is low, and the execution file is extremely friendly to common testers and can be quickly mastered only by simple training. And by "type" in the test case file (i.e., Json file): the scene field can easily distinguish whether the current Json file corresponds to a single-interface test or a certain scene test, and if the current Json file corresponds to the certain scene test, a tester can conveniently organize the scene test according to the scene corresponding to the current Json file.

Description

Python language-based interface test method and device and storage medium
Technical Field
The present invention relates to the field of interface testing technologies, and in particular, to a method and an apparatus for testing an interface based on Python language, and a storage medium.
Background
The interface test is a test for testing interfaces between components of the system, and is mainly used for testing interfaces between the system and other external systems and interfaces between submodules in the system. The test focuses on checking the correctness of the interface parameter transmission, the correctness of the interface function realization, the correctness of the output result and the integrity and the reasonableness of the fault-tolerant processing of various abnormal conditions. The interface test can detect the defects of the system earlier, thereby improving the quality of the product.
At present, interface testing methods are divided into two types, one is an interface testing method based on a testing tool, for example, testing is performed by a testing tool such as postman and Jmeter; the other is an interface testing method based on code writing, such as code writing testing through a requests class library in a language library. For the interface test method based on the test tool, the self-defining capability is poor, the test scenarios and other case tests cannot be conveniently organized, namely the convenience of the scenario test is low; the testing method based on code writing has low efficiency, and is not friendly to common testers in the aspect of code writing, namely the code writing difficulty is higher.
Therefore, there is a need for an improved method of testing the interface.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: the interface testing method, the interface testing device and the storage medium based on the Python language solve the problems that in the prior art, the convenience of scene testing of the interface testing method is low, and the code compiling difficulty is high.
In order to solve the technical problems, the invention adopts the technical scheme that:
the first aspect of the embodiments of the present invention provides an interface testing method based on Python language, including:
acquiring Json files, wherein the Json files are test case files, and each Json file corresponds to a certain interface or a test scene;
compiling an execution file based on a Python language and the Json file, wherein the format of data in the execution file is a Json format;
and executing the Json file according to the execution file to obtain a test report.
In some embodiments, the obtaining the Json file includes:
newly building a test project, wherein the test project at least comprises a Json file;
and acquiring the Json file.
In some embodiments, the test items further include a configuration file, and the obtaining a Json file further includes: initializing the configuration file.
In some embodiments, the obtaining the Json file further includes: and if the number of the databases is more than 1, initializing the configuration file according to each database, wherein the database is a data source needing to be linked in the interface test process.
In some embodiments, initializing the configuration file according to each of the databases includes: and in the configuration file, performing individual maintenance based on data information included in each database.
In some embodiments, said executing said Json file from said execution file further comprises: and collecting results among the interface dependent parameters.
In some embodiments, initializing the configuration file according to each of the databases further includes: and recycling useless parameters returned by each interface.
A second aspect of the embodiments of the present invention provides an interface testing apparatus based on Python language, including:
the system comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring Json files, the Json files are test case files, and each Json file corresponds to a certain interface or a test scene;
the compiling module is used for compiling an execution file based on a Python language and the Json file, and the format of data in the execution file is the Json format;
and the execution module is used for executing the Json file according to the execution file to obtain a test report.
A third aspect of the embodiments of the present invention provides an interface testing device based on Python language, including: a storage device for storing one or more programs and one or more processors, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method according to the first aspect of an embodiment of the present invention.
A fourth aspect of embodiments of the present invention provides a computer-readable storage medium having stored thereon executable instructions that, when executed, perform a method according to the first aspect of embodiments of the present invention.
From the above description, compared with the prior art, the invention has the following beneficial effects:
the test case file based on the Json format is obtained, and the execution file written based on the Python language and the Json format is utilized to execute the test case file so as to generate a test report. The execution file is compiled based on Python language and Json format, the compiling difficulty is low, and the execution file is extremely friendly to common testers and can be quickly mastered only by simple training. And by "type" in the test case file (i.e., Json file): the scene field can easily distinguish whether the current Json file corresponds to a single-interface test or a certain scene test, and if the current Json file corresponds to the certain scene test, a tester can conveniently organize the scene test according to the scene corresponding to the current Json file.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below. It is to be understood that the drawings in the following description are of some, but not all, embodiments of the invention. For a person skilled in the art, other figures can also be obtained from the provided figures without inventive effort.
Fig. 1 is a schematic flowchart of an interface testing method based on Python language according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of step S1 in fig. 1 according to an embodiment of the present invention;
fig. 3 is a schematic flowchart of step S3 in fig. 1 according to an embodiment of the present invention;
FIG. 4 is a block diagram of an interface testing apparatus based on Python language according to an embodiment of the present invention;
fig. 5 is a block diagram of an interface test apparatus based on Python language according to an embodiment of the present invention;
fig. 6 is a block diagram of a computer-readable storage medium according to an embodiment of the present invention.
Detailed Description
For purposes of promoting a clear understanding of the objects, aspects and advantages of the invention, reference will now be made in detail to the present embodiments of the invention, examples of which are illustrated in the accompanying drawings, wherein like reference numerals refer to the same or similar elements throughout. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. In addition, the technical features involved in the embodiments of the present invention described below may be combined with each other as long as they do not conflict with each other.
Referring to fig. 1, fig. 1 is a schematic flowchart illustrating a Python language-based interface testing method according to an embodiment of the present invention.
As shown in fig. 1, an embodiment of the present invention provides a Python language-based interface testing method, which includes the following steps S1 to S3.
And S1, acquiring a Json file.
The Json files are test case files in essence, and in interface test, each Json file corresponds to a certain interface or test scenario. It should be understood that the number of Json files may include one or more, which is determined according to the number of interfaces or scenarios to be tested, and is not limited in this embodiment of the present invention.
S2, writing an execution file based on a Python language and a Json file, wherein the format of data in the execution file is the Json format.
When the execution file is written, in order to realize formatted writing and reduce writing difficulty, the embodiment of the invention needs to write the execution file based on the Python language and the Json data format.
And S3, executing the Json file according to the execution file to obtain a test report.
Executing a Json file is essentially executing a test case. As an example, in the whole execution process, the following execution parts may be included:
the device comprises a presetting part, a data processing part and a data processing part, wherein the presetting part is mainly used for presetting values of an Api interface, such as setting request failure reconnection and the like;
the second is that the request part is mainly used for daily interface request;
the inspection part is mainly used for inspecting parameters returned by the interface;
fourthly, a collecting part is mainly used for collecting results among the interface dependent parameters;
and fifthly, the recovery part is mainly used for recovering useless interface parameters and releasing the memory in time.
It should be noted that the recovery part is mainly used for recovering the useless data (such as useless interface parameters) existing in the whole process of the collection part and executing the Json file, and if a large amount of such data exists, the situation of memory overflow is likely to occur for a common small-memory computer.
It is understood that, in other examples, the execution Json file may include not only the above five parts, but also other parts besides the above five parts, which is not limited by the embodiment of the present invention.
According to the interface testing method based on the Python language, provided by the embodiment of the invention, the test case file based on the Json format is obtained, and the execution file written based on the Python language and the Json format is utilized to execute the test case file so as to generate the test report. The execution file is compiled based on Python language and Json format, the compiling difficulty is low, and the execution file is extremely friendly to common testers and can be mastered quickly only by simple training. And by "type" in the test case file (i.e., Json file): the scene field can easily distinguish whether the current Json file corresponds to a single-interface test or a certain scene test, and if the current Json file corresponds to the certain scene test, a tester can conveniently organize the scene test according to the scene corresponding to the current Json file.
In addition, the interface testing method based on the Python language provided by the embodiment of the invention has the following advantages:
firstly, reconnection of failed Api interface requests is supported, the problem of temporary interface errors caused by possible network instability is reduced, and misjudgment of output of test reports is avoided;
secondly, static parameterization and dynamic method parameterization in the test case script are supported, so that the execution of the test case is more consistent with randomness, and when a set of test case script is executed for multiple times, the result output is dynamically changed;
thirdly, supporting the related use of interface dependent parameters in synchronous execution before a plurality of interfaces;
fourthly, compared with the output content of the traditional test report, the test report obtained in the step S3 only displays the most common report content, and the result is clearer.
Corresponding to the second advantage, in the conventional interface testing method, testers manually set default values, so that the testers are difficult to perform in a long time when encountering the problem of interface uniqueness judgment, and the testers have to maintain and modify the test case file again before executing the test case file each time, thereby resulting in low testing efficiency. The embodiment of the invention utilizes static assignment and dynamic assignment, generates new records when executing the test case file each time, completely avoids the problem of uniqueness of an interface, and simultaneously ensures that a test result is more practical due to the adoption of an unfixed record generation mode.
Referring to fig. 2, fig. 2 is a schematic flowchart illustrating the step S1 in fig. 1 according to an embodiment of the present invention.
As shown in fig. 2, as a possible implementation, the step S1 may include the following steps S11 to S13.
S11, creating a new test project, wherein the test project at least comprises a configuration file and the Json file;
s12, initializing a configuration file;
s13, if the number of the databases is more than 1, initializing configuration files according to the databases;
in fact, the database here is a data source, such as mysql, that needs to be linked during the interface test.
And S14, acquiring a Json file.
As an example, if the number of databases is greater than 1, in the configuration file, individual maintenance is performed based on data information included in each database. In other words, step S13 is substantially to read and initialize the configuration file, and if there are multiple databases, each database can be maintained by the data information included in each database.
Referring to fig. 3, fig. 3 is a schematic flowchart illustrating the step S3 in fig. 1 according to an embodiment of the present invention.
As shown in fig. 3, as another possible embodiment, the step S3 may include the following steps S31 to S32.
S31, loading a Json file;
and S32, executing the loaded Json file according to the execution file.
As an example, when loading a Json file, the Json file may be loaded to a specified global variable. It should be noted that the global variable is substantially a temporary data store, and after the Json is loaded to the global variable, the interface use case and/or scenario use case parsed by the parser are both stored in the global variable.
Referring to fig. 4, fig. 4 is a block diagram of a Python language-based interface testing apparatus according to an embodiment of the present invention.
As shown in fig. 4, an embodiment of the present invention further provides a Python language-based interface testing apparatus 100, including:
the acquiring module 110 is configured to acquire Json files, where a Json file is a test case file, and each Json file corresponds to a certain interface or a test scene;
the compiling module 120 is configured to compile an execution file based on a Python language and a Json file, where a format of data in the execution file is a Json format;
the execution module 130 is configured to execute the Json file according to the execution file to obtain a test report.
Referring to fig. 5, fig. 5 is a block diagram of an interface testing apparatus based on Python language according to an embodiment of the present invention.
As shown in fig. 5, an embodiment of the present invention further provides a Python language based interface testing apparatus 200, which includes a storage device 201 and one or more processors 202, where the storage device 201 is configured to store one or more programs, and when the one or more programs are executed by the one or more processors 202, the one or more processors 202 are enabled to execute the Python language based interface testing method.
As a possible implementation, the Python language based interface test apparatus 200 may further include a bus 203 for communication connection between the storage device 201 and the one or more processors 202.
Referring to fig. 6, fig. 6 is a block diagram of a computer-readable storage medium according to an embodiment of the present invention.
As shown in fig. 6, an embodiment of the present invention further provides a computer-readable storage medium 300, where executable instructions 301 are stored on the computer-readable storage medium 300, and when executed, the executable instructions 301 execute the Python language-based interface testing method.
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.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (e.g., coaxial cable, fiber optic, digital subscriber line) or wirelessly (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk), among others.
It should be noted that, in the summary of the present invention, each embodiment is described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the method class embodiment, since it is similar to the product class embodiment, the description is simple, and the relevant points can be referred to the partial description of the product class embodiment.
It is further noted that, in the present disclosure, 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 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 previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined in this disclosure may be applied to other embodiments without departing from the spirit or scope of the disclosure. Thus, the present disclosure is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. An interface test method based on Python language is characterized by comprising the following steps:
acquiring Json files, wherein the Json files are test case files, and each Json file corresponds to a certain interface or a test scene;
compiling an execution file based on a Python language and the Json file, wherein the format of data in the execution file is a Json format;
and executing the Json file according to the execution file to obtain a test report.
2. The Python language-based interface testing method of claim 1, wherein the obtaining the Json file comprises:
newly building a test project, wherein the test project at least comprises a Json file;
and acquiring the Json file.
3. The Python language-based interface testing method of claim 2, wherein the test items further include a configuration file, and the obtaining a Json file further includes: initializing the configuration file.
4. The Python language based interface testing method of claim 3, wherein the obtaining the Json file further comprises: and if the number of the databases is more than 1, initializing the configuration file according to each database, wherein the database is a data source needing to be linked in the interface test process.
5. The Python language based interface testing method of claim 4, wherein the initializing the configuration file according to each database comprises: and in the configuration file, performing individual maintenance based on data information included in each database.
6. The Python language based interface testing method of claim 1, wherein the executing the Json file according to the execution file further comprises: and collecting results among the interface dependent parameters.
7. The Python language based interface testing method of claim 6, wherein initializing the configuration file according to each of the databases further comprises: and recycling useless parameters returned by each interface.
8. An interface testing device based on Python language is characterized by comprising:
the system comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring Json files, the Json files are test case files, and each Json file corresponds to a certain interface or a test scene;
the compiling module is used for compiling an execution file based on a Python language and the Json file, and the format of data in the execution file is the Json format;
and the execution module is used for executing the Json file according to the execution file to obtain a test report.
9. An interface test device based on Python language, comprising: a storage device to store one or more programs, and one or more processors to cause the one or more processors to perform the method of any one of claims 1-7 when the one or more programs are executed by the one or more processors.
10. A computer-readable storage medium having stored thereon executable instructions that, when executed, perform the method of any one of claims 1-7.
CN202011424580.9A 2020-12-09 2020-12-09 Python language-based interface test method and device and storage medium Pending CN112416802A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011424580.9A CN112416802A (en) 2020-12-09 2020-12-09 Python language-based interface test method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011424580.9A CN112416802A (en) 2020-12-09 2020-12-09 Python language-based interface test method and device and storage medium

Publications (1)

Publication Number Publication Date
CN112416802A true CN112416802A (en) 2021-02-26

Family

ID=74776738

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011424580.9A Pending CN112416802A (en) 2020-12-09 2020-12-09 Python language-based interface test method and device and storage medium

Country Status (1)

Country Link
CN (1) CN112416802A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107577599A (en) * 2017-08-21 2018-01-12 同程网络科技股份有限公司 A kind of automatic interface testing method and platform based on custom script
CN109189684A (en) * 2018-08-28 2019-01-11 四川长虹电器股份有限公司 Automatic interface testing method based on Python
US20190278700A1 (en) * 2018-03-07 2019-09-12 Jpmorgan Chase Bank, N.A. System and method for automated service layer testing and regression
CN111198809A (en) * 2018-11-16 2020-05-26 北京奇虎科技有限公司 Interface automation test method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107577599A (en) * 2017-08-21 2018-01-12 同程网络科技股份有限公司 A kind of automatic interface testing method and platform based on custom script
US20190278700A1 (en) * 2018-03-07 2019-09-12 Jpmorgan Chase Bank, N.A. System and method for automated service layer testing and regression
CN109189684A (en) * 2018-08-28 2019-01-11 四川长虹电器股份有限公司 Automatic interface testing method based on Python
CN111198809A (en) * 2018-11-16 2020-05-26 北京奇虎科技有限公司 Interface automation test method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
林连进 等: "《软件测试技术》", 北京理工大学出版社, pages: 107 - 108 *

Similar Documents

Publication Publication Date Title
CN107665171B (en) Automatic regression testing method and device
US9158514B2 (en) Method and apparatus for providing change-related information
US9026998B2 (en) Selecting relevant tests to quickly assess code stability
US7712087B2 (en) Methods and systems for identifying intermittent errors in a distributed code development environment
US8978009B2 (en) Discovering whether new code is covered by tests
CN107391333B (en) OSD disk fault testing method and system
US9940215B2 (en) Automatic correlation accelerator
JP2019053729A (en) Test method and test apparatus of smart contract
CN111767226A (en) Method, system and equipment for testing cloud computing platform resources
CN116107892A (en) Automatic test method, device, equipment and storage medium
CN110147313B (en) Log output method and device
CN112416802A (en) Python language-based interface test method and device and storage medium
CN116775488A (en) Abnormal data determination method, device, equipment, medium and product
CN113760754A (en) Method, system and storage medium for generating test case based on graph search
CN112000586B (en) Test case execution method and device, execution equipment and readable storage medium
CN116069464B (en) Optimization method and device based on distributed storage call data execution
CN110990267B (en) Data processing method and device
CN117112291A (en) Data backup method and backup device
CN112099838A (en) Method, device and storage medium for determining version difference
CN111857802A (en) Method, system and equipment for merging request group integration
CN116107889A (en) Regression testing method and device for application program, computer equipment and storage medium
CN116860257A (en) Method for generating Azkaban Flow file by analyzing dependency relationship among multiple scripts
CN115202843A (en) Data loading method and device
CN116108035A (en) Data recovery method and device, processor and electronic equipment
CN114694786A (en) Medical data query method, device, equipment and computer storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination