入职已经1个月多了,前段时间一个紧急的项目,用紧急的手段做成接口自动化,框架用的是jmeter+ant+Jenkins,这个框架的优点就是上手快,写用例快,总之就是越快越好!明天开始新的项目,估计又是996,抽空把今天学习的pytest框架一些知识做下总结:
1,Assert就是断言,每个测试用例都需要断言。
2,fixture方法的运用:
import requests
import pytest
class TestV2exApiWithParams(object):
domain = 'https://www.v2ex.com/'
@pytest.fixture(params=['python','java','go'])
def lang(self, request):
return request.param
def test_node(self, lang):
path = 'api/nodes/show.json?name=%s' %(lang)
url = self.domain + path
res = requests.get(url).json()
assert res['name'] == lang
# assert 0
3,parametrize fixture方法的运用
import requests
import pytest
class TestV2exApiWithExceptation(object):
domain = 'https://www.v2ex.com/'
@pytest.mark.parametrize('name,node_id', [('python', 90), ('java', 63), ('go', 375), ('nodejs', 436)])
def test_node(self,name,node_id):
path = 'api/nodes/show.json?name=%s'%(name)
url = self.domain + path
res = requests.get(url).json()
assert res['name'] == name
assert res['id'] == node_id
assert 0
4,生成接口测试报告
pytest test_quick_start.py --junit-xml=report.xml