Python Interface Automation test (vi) Using UNITTEST batch use case management

Source: Internet
Author: User

There must be more than one interface test case in our daily projects, and how do we manage these batch cases as the case grows? How to ensure that cases are not duplicated? How do you ensure the efficiency of case execution when there are a lot of cases (hundreds, even more)? How to do (batch) test data management? How do you separate data from scripts?

These are some of the issues that we need to focus on in our automated testing, and a single use case is not really difficult.

Take a look at how to manage batch cases in the UnitTest framework:

First, manually load the batch use case:

#-*-Coding:utf-8-*-# Batch use case execution-manually loading import unittestclass testone (unittest. TestCase):    def setUp (self):        print ' \ncases before '        pass    def test_add (self):        ' Test Add method ' '        print ' Add ... '        a = 3 + 4        B = 7        self.assertequal (A, b)    def test_sub (self):        ' Test sub method ' '        print ' sub ... '        a = 10-5        b = 5        self.assertequal (A, b)    def tearDown (self):        print ' Case AF Ter '        passif __name__ = = ' __main__ ':    # 1, construct use case set    suite = UnitTest. TestSuite ()    # 2, the order of execution is the load order: Execute test_sub First, then execute Test_add    suite.addtest (Testone ("Test_sub"))    Suite.addtest (Testone ("Test_add"))    # 3, Instantiate runner class    runner = UnitTest. Texttestrunner ()
# 4, execute Test Runner.run (Suite)

Second, automatic loading of batch use cases:

#-*-Coding:utf-8-*-# Batch use case execution-auto load import unittestimport osclass testone (unittest. TestCase):    def setUp (self):        print ' \ncases before '        pass    def test_add (self):        ' Test Add method ' '        print ' Add ... '        a = 3 + 4        B = 7        self.assertequal (A, b)    def test_sub (self):        ' Test sub method ' '        print ' sub ... '        a = 10-5        b = 5        self.assertequal (A, b)    def tearDown (self):        print ' Case AF Ter '        passif __name__ = = ' __main__ ':    # 1, set the directory for the case to be executed    Test_dir = Os.path.join (OS.GETCWD ())    # 2, Automatically searches CAs in the specified directory, constructs the test set, executes the order of names: Executes the Test_add first, then executes test_sub    discover = Unittest.defaultTestLoader.discover (test_ Dir, pattern= ' test_*.py ')    # instantiates Texttestrunner class    runner = UnitTest. Texttestrunner ()    # Run the test suite with the Run () method (that is, run all the use cases in the test suite)    Runner.run (Discover)

The above only solves the problem of how to manage the batch case, other questions how to do (batch) test data management? How do you separate data from scripts? Follow-up in the introduction.

Python interface Automation test (vi) Using UNITTEST batch use case management

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.