1. 程式人生 > 其它 >3、unitteest容器執行用例、用例跳過

3、unitteest容器執行用例、用例跳過

1、unittest容器執行用例

Unittest.main()是執行所有的case

當我不想所有的case都去執行,只想執行其中某條/或某些case的情況下,怎麼辦呢?

知識點:

1、unittest.TestSuite() 新增unittest測試容器,或者叫測試套件

2、addTest(類名(“用例名”)) 新增想要執行的用例(case的執行順序,安裝新增的順序執行

3、TextTestRunner方法執行

2、用例跳過

在執行測試用例時,有時候有些用例是不需要執行的,那怎麼辦呢?需要用到跳過用例的方法

unittest提供了4跳過指定用例的方法

1、@unittest.skip(reason):強制跳轉。

reason是跳轉原因

2、@unittest.skipIf(condition, reason)conditionTrue的時候跳轉

3、@unittest.skipUnless(condition, reason)conditionFalse的時候跳轉

4、@unittest.expectedFailure:如果test失敗了跳轉

第一種跳過:@unittest.skip(“原因備註”)

第二種跳過:@unittest.skipIf(條件True, “原因”)條件True的時候跳轉

第三種跳過:@unittest.skipUnless(條件False, “原因

”)條件False的時候跳轉

第四種跳過:@unittest.expectedFailure如果此條case失敗了,就跳轉