3、unitteest容器執行用例、用例跳過
阿新 • • 發佈:2021-08-24
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):condition為True的時候跳轉
3、@unittest.skipUnless(condition, reason):condition為False的時候跳轉
4、@unittest.expectedFailure:如果test失敗了跳轉
第一種跳過:@unittest.skip(“原因備註”)
第二種跳過:@unittest.skipIf(條件為True, “原因”):條件為True的時候跳轉
第三種跳過:@unittest.skipUnless(條件為False, “原因 ”):條件為False的時候跳轉
第四種跳過:@unittest.expectedFailure,如果此條case失敗了,就跳轉