【自動化測試框架】pytest和unitttest你知道多少?區別在哪?該用哪個?
- 2022 年 2 月 21 日
- 筆記
- C-01【自動化測試】, C-02→ 介面自動化實戰, C-03→ Web自動化測試, C-04→ App自動化測試, 自動化測試
一、大家熟知的自動化測試框架
Java
JUnit、TestNG等等。
python
PyUnit(unittest)、Pytest、Robot Framework等等
二、Pytest介紹
- pytest 是非常成熟全功能的Python測試框架。
- 它可以勝任unittest能做到的各種各樣場景,比如:單元測試、web測試、app測試、介面測試等等。
- pytest是個插件化的平台,它比unittest更強大也在於此。目前已經有大量第三方插件擴展和增強它的功能
- 你可以根據自己需求,訂製化開發出自己的插件
- 可以很好的和CI工具進行結合
三、Pytest優點
- 簡單靈活,容易上手
- 支援參數化
- 能夠支援簡單的單元測試和以及一些複雜的功能測試,也可以用來做web、app、介面(Selenium/Appnium/Requests)等自動化測試
- pytest有很多第三方插件,並且可以進行自定義擴展,比較好用的如pytest-selenium(集成selenium)、pytest-rerunfailures(失敗case重複執行)、pytest-html(完美html測試報告生成)、pytest-xdist(多CPU分發)等
- 測試用例的skip和xfail處理
- 可以很好的和Jenkins集成
- report框架—-allure 也支援了pytest
- 斷言方式簡單便捷
四、pytest與unittest區別
五、Pytest功能介紹
1.Fixture:
2.mark:
3.assert斷言:
assert xx—判斷xx為真
assert not xx —判斷xx不為真
assert a in b—判斷b包含a
assert a == b—判斷a等於b
assert a !=b —判斷a不等於b
等等
4.其他功能:
pytest.xfail()
pytest.exit()
pytest.skip()
pytest.skipif()
六、Pytest架構運行流程
七、應用場景
介面自動化
web自動化
UI自動化
等等
八、Pytest使用
1.自動化用例編寫
2.執行腳本:
1. 命令行中執行用例:
2.IDE中執行用例:
更多功能使用請查看pytest官網:
//docs.pytest.org/en/latest/contents.html
自動化測試框架實戰
介面自動化測試框架:
python+request+pytest+allure://www.cnblogs.com/upstudy/p/15921045.html