第二章 使用unittest模块扩展功能测试
生活随笔
收集整理的這篇文章主要介紹了
第二章 使用unittest模块扩展功能测试
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2.1使用功能測試驅(qū)動開放一個最簡單的應(yīng)用
# functional_tests.py # -*- coding: utf-8 -*- from selenium import webdriverbrowser = webdriver.Chrome() browser.get('localhost:8000')assert 'To-Do' in browser.titlebrowser.quit()python3 manage.py runserver 啟動服務(wù)器,
python3 functional_tests.py 進(jìn)行測試 將出現(xiàn)assert錯誤
2.2Python標(biāo)準(zhǔn)庫中的unittest模塊
# functional_tests.py # -*- coding: utf-8 -*- from selenium import webdriver import unittestclass NewVisitorTest(unittest.TestCase):#setup 和tearDowm是特殊的方法,分別在測試的前后運(yùn)行,這兩個方法與try/except相似def setUp(self):self.browser = webdriver.Chrome()self.browser.implicitly_wait(3) #隱式等待 3秒def tearDown(self):self.browser.quit()def test_can_start_a_list_and_retrieve_it_later(self): #名字以test開頭的函數(shù)都是測試方法self.browser.get('http://localhost:8000')self.assertIn('To-Do',self.browser.title)self.fail('Finish the test!')if __name__ == '__main__':unittest.main(warnings='ignore') #warnings='ignore'為禁止拋出resourceWarning異常python3 functional_test.py ,測試失敗
轉(zhuǎn)載于:https://www.cnblogs.com/fg2312/p/7607772.html
總結(jié)
以上是生活随笔為你收集整理的第二章 使用unittest模块扩展功能测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 树莓派学习——文件传输
- 下一篇: 循环队列_数组实现