Python Interface Automation Test (iii)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.