您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“python單元測試中的函數(shù)有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“python單元測試中的函數(shù)有哪些”吧!
1、setUp準(zhǔn)備環(huán)境。
執(zhí)行每個(gè)測試用例的前提條件。
2、tearDown恢復(fù)環(huán)境。
執(zhí)行每個(gè)測試用例的后置條件。
3、setUpClass所有case執(zhí)行的前置條件,只運(yùn)行一次。
必須使用@classmethod裝飾器,
4、tearDownClass所有case運(yùn)行后只運(yùn)行一次。
必須使用@classmethod裝飾器,
實(shí)例
import unittest #要繼承unittest.TestCase class CalcTestcase(unittest.TestCase): def setUp(self) -> None: print("我是setUp") def test01(self): print("我是的測試方法test01") def test02(self): print("我是的測試方法test02") def test03(self): print("我是的測試方法test03") def tearDown(self) -> None: print("我是tearDown") @classmethod def setUpClass(cls) -> None: print("我是setUpClass") @classmethod def tearDownClass(cls) -> None: print("我是tearDownClass") if __name__ == '__main__': unittest.main() #設(shè)置套件 # suite = unittest.TestSuite() # #把測試方法添加到集合中,然后循環(huán)取值,在添加到套件里面輸出 # list = ["test01","test02","test03"] # for i in list: # suite.addTest(CalcTestcase(i))
到此,相信大家對“python單元測試中的函數(shù)有哪些”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。