我們現在需要測試v2ex**的檢視論壇節點資訊的api。具體如下:
節點資訊該介面是獲取資料的介面,一般來說,這種接**們的測試重點是驗證資料的準確性。method: get authentication: none 接受引數:
name: 節點名(v2ex 的節點名全是半形英文或者數字) 例如:
?name=python
介面返回
根據3a原則,我們可以設計如下的用例
斷言: 返回的結果裡,id必須是90,name必須等於python,大家想一想為什麼?
新建名為v2ex_api_test.py的檔案,鍵入如下內容
import requests
class testv2exapi(object):
domain = ''
def test_node(self):
path = 'api/nodes/show.json?name=python'
url = self.domain + path
res = requests.get(url).json()
assert res['id'] == 90
assert res['name'] == 'python'
需要注意的點
$ pytest v2ex_api_test.py用例執行成功,我們實現了最簡單的介面測試場景。***************=== test session starts ******************************
platform darwin – python 2.7.12, pytest-3.2.3, py-1.4.34,
pluggy-0.4.0 rootdir: /users/easonhan/code/testclass.net/src/pytest,
inifile: collected 1 item
v2ex_api_test.py .
***************== 1 passed in 1.39 seconds ********************=
pytest學習教程 assert 3
assert就是斷言,每個測試用例都需要斷言。與unittest不同,pytest使用的是python自帶的assert關鍵字來進行斷言,大大降低了學習成本。assert關鍵字後面可以接乙個表示式,只要表示式的最終結果為true,那麼斷言通過,用例執行成功,否則用例執行失敗。pytest的用例失敗描...
pytest學習教程 執行多個檔案 2
在現實的測試活動中,我們經常會定義多個用例檔案,用來實現業務邏輯或其他邏輯上用例的物理分隔,比如 login test.py 登入相關功能的測試用例 cart test.py 購物車相關功能的測試用例 checkout test.py 結算相關功能的用例 order test.py 訂單相關功能的用...
Pytest簡單的例項介紹
引用 針對以上文章的webui自動化,編寫了對應的login api介面自動化 介面的呼叫方法 利用pytest.mark.parametrize裝飾器可以實現測試用例引數化 生成html報告 python m pytest html report add demo.html 生成報告 利用allu...