pytest接口自动化测试框架学习总结

入职已经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

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值