Most of the time we need to test our interfaces manually using third-party tools. In some cases, it is laborious and time-consuming. We can actually write our own programs to test our interfaces automatically
Here, we use Python to implement periodic automatic test on the interface. Here, I use PyCharm development tool to write the program, and the source code is as follows:
# import the necessary libraries Introduced after can be in your code using the corresponding class, and a member function import requests the import time # new target interface url_hello = 'http://116.85.59.109/hello' # url variables For n in range(0, 10): # Call the Requests class get method, the HTTP get request, to the address url_hello points to. Response_hello = requests. Get (url_hello) response_hello. Encoding = 'utF-8' # Print ('response: '+ response_hello.text) # response.sleep (3)Copy the code
Run the test program below, and you can see that the program will request the interface 10 times every 3 seconds