当前位置:网站首页>Talking about interface test (I)
Talking about interface test (I)
2022-06-26 01:40:00 【NitefullSand】
Excerpt from :https://blog.csdn.net/qq_41370110/article/details/82825224
http://www.51testing.com/html/46/n-3722746.html
What is an interface (API)
API Full name Application Programming Interface, We don't have to pay attention to it AP, It only needs I Just go up . One API It's just one. Interface. We use it all the time interfaces. The button inside our elevator is a interface. We drive a car, we step on the gas, it's also a interface. We have computers operating system There are also many interfaces .( This is a better explanation that I have found at present )
An interface is one that sits on top of a complex system and simplifies your tasks , It's like a middleman, so you don't need to know all the details in detail . So what we're going to talk about today Web API That's the kind of thing . image Google Search system , It provides a search interface , Simplify your search task . Like the user login page , We just need to call our login interface , We can achieve the purpose of logging into the system .
There are many styles on the market now Web API, One of the most popular and accessible styles at the moment is REST Or call it RESTful Style API. from now on , All of the things I mentioned below API All refer to RESTful Style API.
What is interface testing ? Why do interface tests ?
Interface test is a test to test the interface between system components . The interface test is mainly used to detect the interaction points between the external system and the system as well as between the internal subsystems . The focus of the test is to check the exchange of data , Transfer and control the management process , And the mutual logical dependence between systems .
Nowadays, many front and back architectures of systems are separated , In terms of security , Only relying on the front end to restrict can not meet the security requirements of the system ( It's too easy to get around the front end ), The back end is also needed to control , In this case, it needs to be verified from the interface level .
Now the system is more and more complex , The traditional front-end testing has greatly reduced the efficiency , And now we're all pushing the test forward , I hope the test can intervene earlier , So interface testing is a way to get involved early . For example, traditional testing , Do you have to wait for the front end and the back end to complete the test , In order to write automatic code . And if it's interface testing , Just define the interface at the front and back , Then automation can get involved in writing interfaces automated testing Code , Manual testing only needs the completion of back-end code to intervene in testing back-end logic without waiting for the completion of front-end work .
The strategy of interface testing
Interface testing also belongs to A functional test , So it's not very different from our previous functional testing process , The test process is still :1. Test interface documentation ( The requirements document ) 2. Write according to the interface documentation The test case ( The use case can be written according to the previous rules , For example, equivalence class division , Boundary value and other design methods ) 3. Perform the test , View different parameter requests , Whether the data returned by the interface meets the expectation .
Interface test points :

Here's an example
Suppose we now have the following interface document ( Douban books open source API:https://developers.douban.com/wiki/?title=book_v2)
image.png
From the documentation, we can generally know some information about this interface , For example, the interface is GET request , The request protocol is https, The requested interface server address is api.douban.com, The path to the interface is /v2/book/search, An interface can take four parameters q( Search keywords ),tag( Of the query tag),start( Result based offset),count( Take the number of results ), If the interface request returns the status normally 200, Return the following results in general :
{ "start": 0, "count": 10, "total": 30, "books" : [Book, ] } |
Suppose this document is perfect ( Personally, I think that the parameter type can be written in the development document ) At this time, according to this document , We designed the following test case :
use q= automated testing ,start=0,count=1 Request the search book interface as a parameter , Then the status code of the interface request should be 200,reponse Should return to count=1,start=0 wait .
Finally, we execute the test case , Suppose I don't have another interface test case tool right now , We'll pass browser To test this GET Requested interface , Then I can enter in the low quality bar of the browser :https://api.douban.com/v2/book/search?q= automated testing &start=0&count=1, And judge whether the returned information is wrong .
image.png
JSONView introduce
We found that directly from Chrome Open our book query interface to request , Back to The data is JSON Format , But the browser display layout is hard to read , At this time, we can consider installing some plug-ins for us to read , for example JSONView plug-in unit :
https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc . After the plug-in is installed, we request to search the book interface again , We see the formatted layout :
image.png
Of course, similar formatting JSON There are many plug-in tools , You can find a convenient one by yourself .
Fiddler
Chrome Developer tools depend on Chrome browser , Can only grab Chrome Browser initiated request , If we want to get requests from all programs , We can go through Fiddler To grab .
brief introduction
Fiddler( Chinese name : The violin ) It's a HTTP Debugging agent for , In the form of a proxy server , Monitoring system Http Network data flow ,Fiddler You can or you can check everything HTTP Communications , To set breakpoints , as well as Fiddle be-all “ In and out ” The data of ( I usually use it to grab bags ),Fiddler It also contains a simple but powerful software based on JScript .NET Event script subsystem , It can support many HTTP Debugging tasks .
working principle
Fiddler Acting as agent WEB Working as a server , Browser and server through the establishment of TCP Connect with HTTP Protocol to communicate , The browser sends it by default HTTP Request to server , It uses a proxy address :127.0.0.1, port :8888. When Fiddler The proxy will be set automatically when it is turned on , It automatically logs off the agent when it exits , So it doesn't affect other programs . But if Fiddler Abnormal exit , This time because Fiddler No automatic logout , It will make the web page inaccessible . The solution is to restart Fiddler.
working principle .png
Simple demonstration
Grab http request
1. start-up Fiddler.
2. Click on Fiddler The monitor program in the lower right corner of the main interface , choice ie Browser is initiated by all browsers on the system http Requests will be captured .
image.png
3. open chrome browser , Open the home page of the official website , Enter user name and password to log in .
4. see Fiddler Main panel , You can see that Login request .
5. see Login Requested information
You can see the following Chrome The plug-in sees similar information .
request\response
Postman introduce
We just tested one of our web browsers GET A test case for the requested interface , But usually our interface request methods are except GET also POST,PUT,DELETE wait , After all, browsers are not professional interface testing software , And it can't test POST This type of interface , Then we need to find a professional interface testing software :Postman.
Postman Installation
Former Postman except mac All versions need to be in Chrome The plug-in installation , But now it also introduces Win and liunx Of PC edition , So we just need to go to the official website :https://www.getpostman.com/ Download the corresponding version according to your own operating system .
image.png
For the first time to use
I suggest you register an account , Log in to use , It can facilitate data synchronization on different computers .
GET request
image.png
POST request
POST Request example , adopt Postman Configure the request method , Address , Parameter to initiate a request , Finally, as follows :
Post Demo
Maybe you have questions too , If the development does not have a complete interface document , How do I know about him API Information about ?
At this time, we have to grab these through some bag grabbing tools API Information .
Common bag grabbing tools
HTTP Caught tools :Fiddler、Charles、Firebug、 Developer tools, etc ...
Chrome Simple demo of developer tools
1. open Chrome browser , Press down F12 Quick open Chrome Developer tools
2. Click on Network label
3. Check Preserve log Options , Make sure that the page refresh does not empty the caught requests
image.png
4. Open the homepage of the website , Enter login and password , Click login
5. Check out developer tools , You can find the following figure Login The request interface of
image.png
6. see Login Details of the request
Request method :POST
Requested URL:http://test.logwing.com/Home/Login
Request parameter format :Content-Type: application/x-www-form-urlencoded
Request parameters :UserName=XXX&Password=XXXX&CheckCode=&Remember=false&LoginCheckCode=7119
Request result type :Content-Type: application/json; charset=utf-8
Request the results :
response
More about Chrome Developer tools help Chinese help documents can refer to :https://github.com/CN-Chrome-DevTools/CN-Chrome-DevTools
边栏推荐
猜你喜欢
随机推荐
Region of Halcon: generation of multiple regions (4)
JSON introduction
Installing MySQL databases in FreeBSD
Is it safe to log in the stock account on the flush? How to open a stock account in the flush
Camera - 02 image sensor
Oracle database complete uninstallation steps (no screenshot)
Longitude and latitude multipoint acquisition center point has been solved
Laravel basic course routing and MVC - routing
Oracle常用的基础命令
Log4j2 vulnerability
Model integration and cascading
2021-1-15 摸魚做的筆記Ctrl+c /v來的
Loss function of depth model
Etcd database source code analysis cluster communication initialization
Embedded c learning notes
"Hot post" Statistics
24. histogram calculation
胰蛋白酶的化学性质及应用
毕业季你考虑好去留了吗
From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown























