Python之Unittest和Requests库详解
1.按类来执行 import unittest class f1(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_001(self): pass def test_002(self): pass ''' 按类来执行 ''' if __name__ == ' __main__ ' : suite = unittest.TestSuite(unittest.makeSuite(f1)) unittest.TextTestRunner(verbosity = 2 ).run(suite) 2.加载测试模块来执行 import unittest from selenium import webdriver class BaiduLink(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.maximize_window() self.driver.implicitly_wait( 30 ) self.driver. get (url= " htttp://www.baidu.com " ) def tearDown(self): self.driver.quit() def