python+pytest interface automation: interface testing

Interface definition

Generally speaking, the interface we call is API, so what is API? Baidu defines it as follows:

API (Application Programming Interface) is some predefined interfaces (such as functions, HTTP interface), or refers to the agreement for connecting different components of the software system. A set of routines used to provide applications and developers access to a piece of software or hardware without having to access the source code or understand the details of the inner workings.

It’s a bit convoluted, but let’s take a look at these keywords in the definition: predefined interfaces (such as functions, HTTP interfaces), access based on software or hardware, no need to access the source code, no need to understand the internal working mechanism, and we will probably understand.

for example:

  1. Computers or mobile phones provide various physical hardware interfaces, such as USB interfaces, charging interfaces, headphone interfaces, microphone interfaces, etc. These different interfaces have different functions. For example, by inserting a U disk through the USB interface, you can copy data, and by inserting the headphone interface, you can listen to music. We do not need to care about the working principles of these interfaces, we only need to use these interfaces to meet our usage needs.

  2. Check the weather of a certain city online on the China Weather Network and enter the city name to get the weather for the corresponding city. The essence behind the query is to call the website backend interface to obtain data. The interface here is the Web service software interface. Users do not need to pay attention to how the data is queried in the background of the website, they only need to get the returned results.

Interface classification

There are many dimensions of software interface classification, and the types are difficult to define and may often be confused.

The different protocols used by the interface can be classified as follows:

  • HTTP interface, using HTTP protocol

  • Web Service interface, using soap

  • WebSocket interface, using TCP, UDP protocols

  • Dubbo interface, using Dubbo protocol

Of course, classification based on different protocols is not rigorous. For example, the soap protocol is also based on the HTTP protocol encapsulation, and the Dubbo protocol is based on the TCP protocol, so this classification is for reference only.

Different interface design styles can be classified as follows:

  • RPC type interface, RPC is oriented to procedure call (Remote Procedure Call Protocol), mainly based on TCP/IP protocol

  • REST type interface, REST is oriented to resource calling (Representational State Transfer), mainly based on HTTP protocol

As for the specific content of these two styles, I will not explain too much here. Interested students can search for information by themselves.

   Recommended tutorials related to automated testing:

The latest automated testing self-study tutorial in 2023 is the most detailed tutorial for newbies to get started in 26 days. Currently, more than 300 people have joined major companies by studying this tutorial! ! _bilibili_bilibili

2023 latest collection of Python automated test development framework [full stack/practical/tutorial] collection essence, annual salary after learning 40W+_bilibili_bilibili

Recommended tutorials related to test development

The best in the entire network in 2023, the Byte test and development boss will give you on-site teaching and teach you to become a test and development engineer with an annual salary of one million from scratch_bilibili_bilibili

postman/jmeter/fiddler test tool tutorial recommendation

The most detailed collection of practical tutorials on JMeter interface testing/interface automated testing projects. A set of tutorials for learning jmeter interface testing is enough! ! _bilibili_bilibili

To teach yourself how to capture packets with fiddler in 2023, please be sure to watch the most detailed video tutorial on the Internet [How to Learn to Capture Packets with Fiddler in 1 Day]! ! _bilibili_bilibili

In 2023, the whole network will be honored. The most detailed practical teaching of Postman interface testing at Station B can be learned by novices_bilibili_bilibili

Common interfaces

Interface testing is a verification test of the interface. The interfaces commonly encountered during the testing process are HTTP and Dubbo. The comparison between the two is as follows (please comment and correct me if you understand it wrong):

At present, most companies' interface tests are for HTTP interfaces.

Taking logging in to the TesterHome website as an example, we enter the user name and password on the web page, and click the [Login] button. The web page will request the login interface (the interface is the HTTP interface) to initiate a login request to the server.

If you enter an incorrect username or error, the login interface (sign_in) will return an error, as follows:

Enter the correct user name and password, the login interface verification passes, the login is successful and jumps to the homepage, as follows:

Through examples, we have a general impression of how the client and server interact with data through interfaces.

Test layering

Software testing is usually divided into a three-layer pyramid model, from top to bottom: UI testing, interface testing, and unit testing.

In terms of project quality, each layer of the pyramid cannot be replaced. Our usual testing may focus more on UI testing, but this is often not possible to meet the quality of the system under test. In addition, The interface also needs to be tested (unit testing is generally completed by development).

The necessity and advantages of interface testing are as follows:

  • It is closer to the bottom layer than UI testing. The earlier the underlying problems are discovered, the lower the cost of solving them.

  • Compared with UI testing, interface testing is easier to find hidden bugs in the backend.

  • In the design mode where the front-end and back-end are separated, it is easy to bypass the front-end tampering or forging data to make interface requests, so the exception handling capabilities and security of the interface need to be tested.

  • In the case of concurrency, the stability of the interface needs to be tested for performance, otherwise it may easily cause system problems.

  • Compared with unit testing, interface testing is closer to user usage scenarios and has lower investment costs.

  • Compared with UI testing, interface testing can perform automated testing with lower maintenance costs and higher efficiency.

Test left and right shifts

In recent years, the testing industry has increasingly mentioned shift left and shift right of testing, and they are defined as follows.

Test left shift

Shift testing to the left, that is, letting testing intervene in some testing work before development and testing. For example, during the architecture design phase or development phase, testers step in to consider the testability of the product and manage development self-testing, etc. In addition, testing can be further extended to the requirements review stage, allowing testers to not only understand the requirements, but also evaluate the quality of the requirements.

Test shift right

The test is moved to the right, which means that the test is involved in part of the work after the application is launched. For example, testers can conduct online inspections during and after product launch. In addition, after the product is launched, testers still need to pay attention to the online situation and follow up promptly if problems are found to minimize the impact.

The purpose of moving testing left or right is to better control the quality of the project. Regardless of whether it is moved left or right, in the process of practice, the focus on the quality of the interface is still the focus.

Summarize

In terms of the current market demand and trends in software testing recruitment, interface testing is a skill that testers must master, and interface automated testing is a tool for increasing salary.

In the work process, more is done on interface testing of HTTP protocol interfaces, and subsequent blogs will also focus on HTTP type interfaces.

  Summarize:

 Optical theory is useless. You must learn to follow along and practice it in order to apply what you have learned to practice. At this time, you can learn from some practical cases.

If it is helpful to you, please like and save it to give the author an encouragement. It also makes it easier for you to search quickly next time.

If you don’t understand, please consult the small card below. The blogger also hopes to learn and improve with like-minded testers.

At the appropriate age, choose the appropriate position and try to give full play to your own advantages.

My path to automated test development is inseparable from plans at each stage, because I like planning and summarizing.

Test development video tutorials and study notes collection portal! !

Guess you like

Origin blog.csdn.net/m0_59868866/article/details/134598777