Python Interface Automation Test (vi)-unittest-single use case management

Source: Internet
Author: User

The first five sections mainly introduce the environment construction and the use of the requests library, which can be used to send the interface request. But how to manage the interface case? Returns how the results are automatically verified? This is not possible with the above five sections, so from this section we have introduced the Python Unit Test framework unittest, which handles batch use case management, verifying return results, initialization work, and environmental resiliency after testing.

One, a single use case management is relatively simple, for example, a single use case is generally more useful when debugging:

Second, the code is as follows:

#-*-coding:utf-8-*-#single use case execution#1. Import ModuleImportUnitTest#2, inherit from UnitTest. TestCase classclassTestone (unittest. TestCase):#3, configure the environment: Before testing the initialization of the work    defsetUp (self):Print '\ncases before'        Pass    #4. Define test case with name beginning with "Test"    defTest_add (self):" "Test Add Method" "        Print 'Add ...'a= 3 + 4b= 7#5, define the Assert assertion, judge the test resultsSelf.assertequal (A, b)deftest_sub (self):" "Test Sub Method" "        Print 'Sub ...'a= 10-5b= 4Self.assertequal (A, b)#6. Clean up the environment    defTearDown (self):Print ' Case After'        Pass#7. This method searches all test case methods that start with test in the module and executes them automaticallyif __name__=='__main__': Unittest.main ()

Output:

inch 0.001sOKcases beforeadd...case aftercases beforesub...case afterprocess finished with exit code 0

Python Interface Automation Test (vi)-unittest-single use case management

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.