Python unittest frame Decorator

Source: Internet
Author: User

To say what kind of a relationship between unit testing and UI Automation, say my personal experience, I do not have much experience in this area, because the work itself is less, there is a functional test point for me this lazy person, more complex than unit testing ... Considering the correspondence between the processing logic and the UI of the unit test, according to the test idea of layered automation, the Ui>> interface >> the bottom is the unit, for the unit level Automation test, is the white box test category, with a piece of code to test a piece of code, And we need to write our automated test scripts using some of the organizational drivers of the unit test framework, and UnitTest is the unit test framework that comes with python, and we don't have to delve into it, we just use a part of the rule method encapsulated by UnitTest to populate your script

#Coding:utf-8" "@author: Hx@desc: Focus on learning unittest usage Note setup/setupclass, Teardown/teardownclass difference 1.setUp: Run 2.tearDown before each test function runs: After each test function executes 3.setUpClass: The @classmethod adorner must be used, all tests run once before 4.tearDownClass: The @classmethod adorner must be used, All test runs once run once UnitTest also has some less commonly used adorners: @unittest. Skip (reason): Skip test unconditionally, reason describe why you skipped the test @unittest.skipif (Condititon, Reason): Condititon is true when skipping test @unittest.skipunless (condition, reason): condition Skip Test @unittest.expectedfailure When not true: if test fails, this test does not count toward the number of failed case" "ImportUnitTestImport Time fromSeleniumImportWebdriverclasssearchtest (unittest. TestCase): @classmethoddefSetupClass (CLS): Cls.driver=Webdriver. Chrome () cls.driver.implicitly_wait (30) Cls.driver.maximize_window () Cls.base_url=''cls.driver.get (cls.base_url) Cls.search_text= cls.driver.find_element_by_id ('kw') cls.search_btn= cls.driver.find_element_by_id ('su')    deftest_search_btn_displayed (self): Self.asserttrue (self.search_btn.is_displayed ()) Self.asserttrue (Self.s Earch_btn.is_enabled ())deftest_search_text_maxlength (self): Max_length= Self.search_text.get_attribute ('maxlength') self.assertequal ('255', Max_length)defTest_search (self): Self.search_text.clear () Self.search_text.send_keys ('Blog Park') () Time.sleep (4) Title=Self.driver.title self.assertequal (title, U'Blog Park _ Baidu Search') @classmethoddefTeardownclass (CLS): Cls.driver.quit ()if __name__=='__main__': Unittest.main (verbosity= 3)

Python unittest frame Decorator

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: 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.