I think a lot of people haven't come back yet, just after the holiday.
This time introduce a Python-brought test framework Unitest
1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 ImportRequests5 ImportUnitTest6 7 classTestswcw_back (unittest. TestCase):8 defsetUp (self):9 Print "interface Test started"Ten One defTearDown (self): A Print "end of interface test" - - defTestlogin (self):#Login Test Cases theURL ='http://localhost:8081/swcw/back/sysLogin.action' -Postparams = {'username':'Admin','Password':'123456'} -Results =requests.post (url,postparams) - Print "Request Address:", the URL + Print "Request return Address:", Results.url - Print "The interface Returns a status code:", Results.status_code + A defTestaddproducttype (self): atURL ='http://localhost:8081/swcw/back/producttypeForm.action' -Login_data = {'username':'Admin','Password':'123456'}#Login Parameters -Postparams = { - "ID":"", - "Oldpid":"", - "PID":" -", in "TypeName":"104", - "Code":"101", to "Showinnav":"1", + "Remark":"102", - "":"Save", the}#Add Item Category parameters *s =requests. Session () $ Panax NotoginsengLogin = S.post ('http://localhost:8081/swcw/back/sysLogin.action', Data=login_data) - #call the session method to send a POST request login theResults = S.post (url,data=postparams) + #to investigate the session method post request as the same user keeps the login status A Print "Request Address:", the URL the Print "Request return Address:", Results.url + Print "The interface Returns a status code:", Results.status_code - $ if __name__=="__main__": $Unittest.main ()
The code is simple, without declaring a generic class, and starting the write interface test directly
The results of the operation are as follows:
SetUp, teardown two functions each execution case will run again
The blogger can only use it here.
Python Interface Automation Test (iii)