自动化测试,需要加断言,方法如下
    assert r.status_code == 200 # 这是对状态码断言
    assert r.json()[‘success’] == True # 对json值断言
    image.png

    断言要结合测试框架来使用,在python常使用的框架有pytest
    可以在bing中搜索pytest
    image.png

    安装pytest方法
    点Terminal,输入 pip install pytest
    image.png

    安装好 pytest,输入 pytest testcases,可以直接执行test cases目录,因为执行test cases目录的时候,它会自动的去找test_ 的文件
    image.png

    也可以指定文件,例如test_topics.py,执行命令如下
    pytest testcases\test_topics.py (如果是mac,则输入 pytest testcases/test_topics.py)
    image.png
    image.png

    注意:
    assert r.status_code == 200
    assert r.json()[‘success’] == True
    这两段代码需要与上面的 } 和 r = … 对齐
    image.png

    所写代码如下
    assert r.status_code == 200
    assert r.json()[‘success’] == True

    所执行语句如下,点Terminal,先安装 pip install pytest
    然后输入 pytest testcases
    或者输入 pytest testcases\test_topics.py
    (如果是mac,则输入 pytest testcases/test_topics.py)