CN114741283A - Automatic interface testing method and device based on python design - Google Patents

Automatic interface testing method and device based on python design Download PDF

Info

Publication number
CN114741283A
CN114741283A CN202210323116.3A CN202210323116A CN114741283A CN 114741283 A CN114741283 A CN 114741283A CN 202210323116 A CN202210323116 A CN 202210323116A CN 114741283 A CN114741283 A CN 114741283A
Authority
CN
China
Prior art keywords
data
test
interface
calling
excel
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
CN202210323116.3A
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.)
XCMG Hanyun Technologies Co Ltd
Original Assignee
XCMG Hanyun Technologies 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 XCMG Hanyun Technologies Co Ltd filed Critical XCMG Hanyun Technologies Co Ltd
Priority to CN202210323116.3A priority Critical patent/CN114741283A/en
Publication of CN114741283A publication Critical patent/CN114741283A/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/3684Test management for test design, e.g. generating new test cases
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Test And Diagnosis Of Digital Computers (AREA)

Abstract

The invention discloses an automatic interface testing method and device based on python design, reading excel by a python method to obtain test case data, generating interface test requests in batch, writing back test results to a test case file, outputting a test case report, compared with the existing testing tool using an open source or customized development interface, the method does not need frequent tool parameter configuration and modification, does not need a testing script of a maintenance tool and a secondary development testing tool, and in the method of the invention, the business test case is separated from the interface test code, parameterization is carried out on the business test case, and the business test case is extracted as the input parameter of the interface test code, so that the problem of uncontrollable test data is solved, the maintenance of the test data is convenient, and corresponding adjustment and optimization of test cases can be made according to the test results, so that the test efficiency and accuracy are improved, and a large amount of labor time is saved.

Description

Automatic interface testing method and device based on python design
Technical Field
The invention relates to an interface automatic testing method and device based on python design, and belongs to the technical field of automatic testing.
Background
Interface testing is an important testing link for testing interfaces between components of a system. The key point of the interface test is to check the exchange of data, transfer and control management processes, mutual logic dependency relationship between systems and the like. The interface test principle is a process of simulating a client to send a request to a server, processing a response request after the server receives the request, returning a corresponding result to the client and receiving the result by the client.
Due to the continuous increase of the complexity of the system, the cost of the traditional testing method is increased sharply, and the testing efficiency is reduced greatly, so the interface testing is particularly important in the development period of software. Meanwhile, the interface test is relatively easy to realize automatic continuous integration, and is relatively stable relative to UI automation, so that the investment of test labor cost and time cost can be reduced, the test period is shortened, the requirement of quick version sending at the rear end is supported, and the continuous integration of the interface test is the root of low cost and high yield. At present, the front-end and back-end architectures of many systems are separated, and from the security level, the front-end is only relied on for limitation, the security requirements of the systems cannot be met at all, the back-end is required to control the systems, and in this case, the verification needs to be carried out from the interface level.
Currently, the calling of the front end and the back end of a mainstream project in the market is mainly an interface based on an http protocol, so that the sending and receiving of an http request are mainly simulated through a tool or a code during the testing of the interface. There are many tools such as: postman, meter, robotframe + httplibrary, etc.
The postman has low threshold, quick hands-on and cross-platform, but cannot operate the operation related to the file, cannot read and write the database, but cannot encapsulate the public function, and does not support the skip, retry and the like among the use cases; the jmeter is used as a professional performance testing tool for interface testing, convenience for managing and maintaining the testing script is lacked, the change of the interface or the testing component can influence the execution results of other testing components, the accuracy of the testing result can be influenced by frequent change of the testing script, and the maintenance cost is very high; robotframe + httpliibry has certain requirements on the code capability of testers, the interface reaction speed is low, the interface is often stuck, and the import of a test library is sometimes abnormal.
Although there are many interface testing tools and schemes that can be selected in the market, there is no scheme that is completely suitable for the existing project, the configuration and operation of the tools need to be familiar, and even a certain customized development is needed to meet the project requirements, so a more flexible interface testing framework needs to be developed by the user to meet the test requirements of the project.
Disclosure of Invention
The invention aims to overcome the defects in the prior art and provides an interface automatic testing method and device based on python design, which can read test cases without frequent script parameter modification and only need to maintain the test scenes and test parameters of the system interface to be tested in the test cases, execute the automatic test of the interface in batches and generate a report mail to be sent, present the test results of the automatic test execution success rate, the passing failure number and the like of the interface in a chart form, have clear and simple report results and can meet the requirement of the current project test.
In order to achieve the purpose, the invention is realized by adopting the following technical scheme:
in a first aspect, the invention provides an automatic interface testing method based on python design, which comprises the following steps:
reading configuration information of a config.ini configuration file, connecting a system database according to the configuration information, calling a DB function method to initialize the system database, and creating basic test data;
calling a pre-packaged method to read excel service test case information, and returning a result in a json data format;
requesting a tested system interface, calling different interface requests according to the read service test case data and obtaining a result;
assembling results obtained by calling different interface requests into data in a JSON format, simultaneously obtaining expected result data in an excel table, carrying out regular judgment and comparison on the expected result data and the excel table, and writing judgment results into an excel result data table;
and calling the use cases in batches, executing and generating a test report, and sending the test report to a specified mailbox in an html form.
Further, the reading configuration information of the config.ini configuration file, connecting the system database according to the configuration information, calling a DB function method to initialize the system database, and creating basic test data includes:
the system comprises an import package, a database, a configuration file reading method, an os module and an SYS module;
defining a class method by using python, customizing a database operation method, including methods of deleting, inserting and initializing table data;
and executing a database operation method, initializing interface test data, and confirming that the data initialization is successful.
Further, the configuration file information includes IP, port information, user, password, and db _ name of the test database.
Further, the calling the pre-packaged method to read the excel service test case information and return the result in a json data format includes:
defining a reading function class for reading excel file data;
defining a reading method for reading the data content and the list format of the first line;
defining a for loop method for reading the data content and list format of each line;
converting the read data content into a dictionary format according to a key-value key value pair, then defining an array format, adding dictionary data into an array, returning to a json format, judging whether the format content is empty, and returning to None if the format content is empty.
Further, the reading method can judge the read data format and respond to the data processing mode to return a correct message.
Further, the requesting a tested system interface calls different interface requests according to the read service test case data and obtains a result, including:
establishing a class method, defining Requests function, and realizing the interface request of the tested system;
acquiring a transmission parameter and a request url from a read service test case data table, calling a blind interface request function according to different parameters in a request mode;
and returning the interface request result in a text format.
Furthermore, the interface request function changes the interface request mode according to different parameter types and request methods, and returns corresponding results.
Further, the assembling the results obtained by calling different interface requests into data in a JSON format, obtaining expected result data in an excel table at the same time, performing regular judgment and comparison on the two data, and writing the judgment result into the excel result data table includes:
defining a service test case class and defining an initialization request method;
calling a Read _ Excel method in Excel _ operation to Read test data and decorating the test data to generate a service test case by using data drive;
defining a tested system interface test method, analyzing a request result, obtaining useful data, and comparing and judging the useful data with expected result data obtained by an excel table;
and calling an excel _ write method in the excel _ operation to write the judgment result into an excel result data table for storage.
Further, the batch call of the use cases, the execution and the generation of the test report, and the sending to the specified mailbox in the form of html, include:
defining a method for loading service test cases so as to load all or specified paths and names of the service test cases;
defining a method for executing a service test case, calling a Beautifurport module to generate a latest report, calling a mail sending module, and sending the report to a specified mailbox.
In a second aspect, the present invention provides an automated interface testing apparatus based on python design, including:
reading the configuration information of the config.ini configuration file, connecting the system database according to the configuration information, calling a DB function method to initialize the system database, and creating a module of basic test data;
calling a pre-packaged method to read excel service test case information and returning a result in a json data format;
requesting the interface of the tested system, calling different interface requests according to the read business test case data and obtaining a result;
assembling results obtained by calling different interface requests into data in a JSON format, simultaneously obtaining expected result data in an excel table, carrying out regular judgment and comparison on the results, and writing the judgment results into a module in the excel result data table;
and calling the use cases in batches, executing and generating a test report, and sending the test report to a module of a specified mailbox in an html form.
Compared with the prior art, the invention has the following beneficial effects:
the invention provides an interface automatic test method based on python design, which reads excel to obtain test case data through the python method, generates interface test requests in batch, writes back a test result and an interface response message to a test case file, and outputs a test report, compared with the existing open-source or customized development interface test tool, frequent tool parameter configuration and modification are not needed, and a test script and a secondary development test tool of a maintenance tool are not needed; the service test case uses excel to maintain data, has neat and efficient format, and can cover various test scenes, input and output boundary analysis, parameter combination test and the like; the tester can execute the automatic interface test only by maintaining the scene data and the parameter data of the tested system in the excel test case, and can make corresponding adjustment and optimization test cases according to the test result, thereby improving the test efficiency and accuracy and saving a large amount of labor time.
Drawings
Fig. 1 is a schematic flowchart of an interface automated testing method based on python design according to an embodiment of the present invention.
Detailed Description
The invention is further described below with reference to the accompanying drawings. The following examples are only for illustrating the technical solutions of the present invention more clearly, and the protection scope of the present invention is not limited thereby.
Example 1
This embodiment introduces an automated interface testing method based on python design, including:
reading configuration information of a config.ini configuration file, connecting a system database according to the configuration information, calling a DB function method to initialize the system database, and creating basic test data;
calling a pre-packaged method to read excel service test case information, and returning a result in a json data format;
requesting a tested system interface, calling different interface requests according to the read service test case data and obtaining a result;
assembling results obtained by calling different interface requests into data in a JSON format, simultaneously obtaining expected result data in an excel table, carrying out regular judgment and comparison on the expected result data and the excel table, and writing judgment results into an excel result data table;
and calling the use cases in batches, executing and generating a test report, and sending the test report to a specified mailbox in an html form.
The application process of the automatic interface testing method based on python design provided by the embodiment specifically involves the following steps:
1. creating a config directory for storing file configurations, such as:
newly adding a config.ini configuration file for configuring mysql information, wherein the mysql information comprises ip, port, user, password, database name and the like;
the mail related information comprises sending mailbox server information, sender mailbox, receiver mailbox, sending mailbox user name/password, mail subject and the like
2. And a newly added data directory is used for storing the business test case file:
the service test case is maintained by using excel, and the information comprises a test module, a number, an interface request url, a request type, a request parameter, heads, body, type, status _ code, msg, result and the like 3. the newly added common directory comprises a common operation method py script file, for example:
newly adding a config _ read.py script for reading and writing a config.ini configuration file;
newly adding a db _ reset. py script, encapsulating a user-defined database operation method for initializing the database;
adding an excel _ operation. py script, and encapsulating the operation for reading and writing excel file data;
py script is added for being requested by the interface of the tested system, and the analyzed data is returned for being called by the interface testing logic code and compared with the expected result assertion.
And adding an email script, packaging the function of sending the mail, reading the mail information in the configuration file, and sending an interface automation test report in an HTML format.
4. A testcase directory is added for storing relevant code files for the automatic test of the interface,
and adding testcase _ xxproject.py, including interface test logic codes of the test frame, defining a test method of the system interface to be tested, analyzing a request result, obtaining an interface request result, and comparing and judging the interface request result with expected result data obtained by the excel table. The code provides a function of generating a case according to the test data, the test data is used as a parameter to be transmitted to the test case, one test case is correspondingly generated by one piece of data, and if a plurality of pieces of data exist in the data, a plurality of test cases are correspondingly generated. If data of sequence type such as tuple, list, etc. is put in the data, the data will regard them as a whole, i.e. a test data. The use cases are isolated from each other, and other test use cases cannot be influenced under the condition of failure. The interface test logic code provides a function of writing a test result into the excel, and the test result is written into the service test case excel.
5. Newly added report directory for storing test report files
Py script is added, a method for loading test cases is defined, the test cases are called in batch, a Beautifurport module is executed and called to generate the latest report, the report is stored to a local designated path, if the latest report does not exist, the latest report is created, a method for sending a mail function is called at the same time, and the report is sent to a designated mailbox in an html mode.
The interface automation test report contains information such as report summarization and detailed data, the test result is presented in a chart form, the result is clear and understandable, and the report summarizes the name of the use case, the total number of the use cases, the passing number of the use cases, the failure number, the skipping number, the starting and ending time and the like.
The invention has the beneficial effects that:
the invention relates to an automatic interface test method based on python design. Compared with the existing testing tool using an open source or a customized development interface, the testing tool does not need frequent tool parameter configuration and modification, and does not need a testing script of a maintenance tool and a secondary development testing tool. In the method, the service test case is separated from the interface test code, the service test case is parameterized and extracted as the input parameter of the interface test code, so that the problem of uncontrollable test data is solved, and the test data is convenient to maintain. The service test case uses excel to maintain data, has neat and efficient format, and can cover various test scenes, input and output boundary analysis, parameter combination test and the like. The tester can execute the automatic interface test only by maintaining the scene data and the parameter data of the tested system in the excel test case, and can make corresponding adjustment and optimization test cases according to the test result, thereby improving the test efficiency and accuracy and saving a large amount of labor time.
Example 2
The embodiment provides an automatic interface testing device based on python design, which comprises:
reading the configuration information of the config.ini configuration file, connecting the system database according to the configuration information, calling a DB function method to initialize the system database, and creating a module of basic test data;
calling a pre-packaged method to read excel service test case information and returning a result in a json data format;
requesting the tested system interface, calling different interface requests according to the read service test case data and obtaining a result;
assembling results obtained by calling different interface requests into JSON format data, acquiring expected result data in an excel table, performing regular judgment and comparison on the two data, and writing a judgment result into a module in the excel result data table;
and calling the use cases in batches, executing and generating a test report, and sending the test report to a module of a specified mailbox in an html form.
The above description is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, several modifications and variations can be made without departing from the technical principle of the present invention, and these modifications and variations should also be regarded as the protection scope of the present invention.

Claims (10)

1. An automatic interface testing method based on python design is characterized by comprising the following steps:
reading configuration information of a config.ini configuration file, connecting a system database according to the configuration information, calling a DB function method to initialize the system database, and creating basic test data;
calling a pre-packaged method to read excel service test case information, and returning a result in a json data format;
requesting a tested system interface, calling different interface requests according to the read service test case data and obtaining a result;
assembling results obtained by calling different interface requests into JSON format data, acquiring expected result data in an excel table, performing regular judgment and comparison on the two data, and writing a judgment result into an excel result data table;
and calling the use cases in batches, executing and generating a test report, and sending the test report to a specified mailbox in an html form.
2. The automated python design-based interface testing method of claim 1, wherein: reading configuration information of the config.ini configuration file, connecting a system database according to the configuration information, calling a DB function method to initialize the system database, and creating basic test data, wherein the method comprises the following steps:
the system comprises an import package, a database, a configuration file reading method, an os module and an SYS module;
defining a class method by using python, and customizing a database operation method, wherein the class method comprises methods of deleting, inserting and initializing table data;
and executing a database operation method, initializing interface test data, and confirming that the data initialization is successful.
3. The automated python design-based interface testing method of claim 1, wherein: the configuration file information comprises IP, port information, user, password and db _ name of the test database.
4. The automated python design-based interface testing method of claim 1, wherein: the calling of the pre-packaged method for reading excel service test case information and returning a result in a json data format comprises the following steps:
defining a reading function class for reading the excel file data;
defining a reading method for reading the data content and the list format of the first line;
defining a for loop method for reading the data content and list format of each line;
converting the read data content into a dictionary format according to a key-value key value pair, then defining an array format, adding dictionary data into an array, returning to a json format, judging whether the format content is empty, and returning to None if the format content is empty.
5. The automated python design-based interface testing method of claim 1, wherein: the reading method can judge the read data format and respond to the data processing mode to return a correct message.
6. The automated interface testing method based on python design according to claim 1, characterized in that: the requesting tested system interface calls different interface requests and obtains results according to the read service test case data, and the method comprises the following steps:
establishing a class method, defining Requests function, and realizing the interface request of the tested system;
acquiring a transmission parameter and a request url from a read service test case data table, calling a blind interface request function according to different parameters in a request mode;
and returning the interface request result in a text format.
7. The automated python design-based interface testing method of claim 1, wherein: the interface request function changes the interface request mode according to different parameter types and request methods and returns corresponding results.
8. The automated python design-based interface testing method of claim 1, wherein: assembling results obtained by calling different interface requests into data in a JSON format, simultaneously obtaining expected result data in an excel table, carrying out regular judgment and comparison on the results and the expected result data, and writing judgment results into the excel result data table, wherein the method comprises the following steps:
defining a service test case class and defining an initialization request method;
calling a Read _ Excel method in Excel _ operation to Read test data and decorating the test data to generate a service test case by using data drive;
defining a tested system interface test method, analyzing a request result, obtaining useful data, and comparing and judging the useful data with expected result data obtained by an excel table;
and calling an excel _ write method in the excel _ operation to write the judgment result into an excel result data table for storage.
9. The automated python design-based interface testing method of claim 1, wherein: the batch call use case is executed and generated, and the test report is sent to a specified mailbox in an html form, and the method comprises the following steps:
defining a method for loading service test cases so as to load all or specified paths and names of the service test cases;
defining a method for executing a service test case, calling a Beautifurport module to generate a latest report, calling a mail sending module, and sending the report to a specified mailbox.
10. An automatic interface testing device based on python design is characterized by comprising:
reading the configuration information of the config.ini configuration file, connecting the system database according to the configuration information, calling a DB function method to initialize the system database, and creating a module of basic test data;
calling a pre-packaged method to read excel service test case information and returning a result in a json data format;
requesting the tested system interface, calling different interface requests according to the read service test case data and obtaining a result;
assembling results obtained by calling different interface requests into data in a JSON format, simultaneously obtaining expected result data in an excel table, carrying out regular judgment and comparison on the results, and writing the judgment results into a module in the excel result data table;
and calling the use cases in batches, executing and generating a test report, and sending the test report to a module of a specified mailbox in an html form.
CN202210323116.3A 2022-03-30 2022-03-30 Automatic interface testing method and device based on python design Pending CN114741283A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210323116.3A CN114741283A (en) 2022-03-30 2022-03-30 Automatic interface testing method and device based on python design

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210323116.3A CN114741283A (en) 2022-03-30 2022-03-30 Automatic interface testing method and device based on python design

Publications (1)

Publication Number Publication Date
CN114741283A true CN114741283A (en) 2022-07-12

Family

ID=82276599

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210323116.3A Pending CN114741283A (en) 2022-03-30 2022-03-30 Automatic interface testing method and device based on python design

Country Status (1)

Country Link
CN (1) CN114741283A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115297039A (en) * 2022-10-08 2022-11-04 天津华来科技股份有限公司 HTTP (hyper text transport protocol) parameterized test architecture method, electronic equipment and storage medium
CN115543806A (en) * 2022-10-08 2022-12-30 武汉赫尔墨斯智能科技有限公司 Method for supporting automatic calling and automatic matching automatic execution case test
CN115811476A (en) * 2022-12-01 2023-03-17 四川天邑康和通信股份有限公司 Method for counting octoscope test results, electronic device and readable storage medium
CN117033249A (en) * 2023-10-08 2023-11-10 卓望数码技术(深圳)有限公司 Test case generation method and device, computer equipment and storage medium
CN117370217A (en) * 2023-12-08 2024-01-09 天津华来科技股份有限公司 Automatic interface test result generation method based on python

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115297039A (en) * 2022-10-08 2022-11-04 天津华来科技股份有限公司 HTTP (hyper text transport protocol) parameterized test architecture method, electronic equipment and storage medium
CN115543806A (en) * 2022-10-08 2022-12-30 武汉赫尔墨斯智能科技有限公司 Method for supporting automatic calling and automatic matching automatic execution case test
CN115297039B (en) * 2022-10-08 2023-01-10 天津华来科技股份有限公司 HTTP (hyper text transport protocol) parameterized test architecture method, electronic equipment and storage medium
CN115543806B (en) * 2022-10-08 2024-06-07 武汉赫尔墨斯智能科技有限公司 Method for supporting automatic calling, automatic matching and automatic executing case test
CN115811476A (en) * 2022-12-01 2023-03-17 四川天邑康和通信股份有限公司 Method for counting octoscope test results, electronic device and readable storage medium
CN117033249A (en) * 2023-10-08 2023-11-10 卓望数码技术(深圳)有限公司 Test case generation method and device, computer equipment and storage medium
CN117370217A (en) * 2023-12-08 2024-01-09 天津华来科技股份有限公司 Automatic interface test result generation method based on python
CN117370217B (en) * 2023-12-08 2024-06-14 天津华来科技股份有限公司 Automatic interface test result generation method based on python

Similar Documents

Publication Publication Date Title
CN109189684B (en) Python-based automatic interface testing method
CN114741283A (en) Automatic interface testing method and device based on python design
CN110297774B (en) Automatic interface testing method based on python
CN111930635B (en) Swagger-based rapid automatic testing method and system
CN108319547B (en) Test case generation method, device and system
CN110716870B (en) Automatic service testing method and device
CN112286806B (en) Automatic test method and device, storage medium and electronic equipment
WO2008061340A1 (en) Automated testing and control of networked devices
WO2020186680A1 (en) Interface testing method based on modeling platform
CN114880240B (en) Automatic test system and method for equipment of Internet of things, storage medium and equipment
CN112035363A (en) Automatic interface testing method and device
WO2017017691A1 (en) Testing computing devices
CN115080398A (en) Automatic interface test system and method
CN112181854A (en) Method, device, equipment and storage medium for generating flow automation script
CN112181852A (en) Interface automatic testing method and device, computer equipment and storage medium
CN115437954A (en) Interface automation test data separation method
CN111679982A (en) Automatic testing method for REST API (representational State transfer) interface software
CN111782546A (en) Automatic interface testing method and device based on machine learning
CN110928796B (en) Automatic test platform
CN114281680A (en) Web automatic testing method and system
CN113836014A (en) Interface testing method and device, electronic equipment and storage medium
CN117370217B (en) Automatic interface test result generation method based on python
CN113448826A (en) Software automation test system and method
CN111459809A (en) Software testing method based on rapid demand version iteration
CN111078529B (en) Client writing module testing method and device and electronic equipment

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